protected List<ReplaceableAttribute> createAttributesToRegister(PriamInstance instance) { instance.setUpdatetime(new Date().getTime()); List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>(); attrs.add(new ReplaceableAttribute(Attributes.INSTANCE_ID, instance.getInstanceId(), false)); attrs.add(new ReplaceableAttribute(Attributes.TOKEN, instance.getToken(), true)); attrs.add(new ReplaceableAttribute(Attributes.APP_ID, instance.getApp(), true)); attrs.add(new ReplaceableAttribute(Attributes.ID, Integer.toString(instance.getId()), true)); attrs.add(new ReplaceableAttribute(Attributes.AVAILABILITY_ZONE, instance.getRac(), true)); attrs.add(new ReplaceableAttribute(Attributes.ELASTIC_IP, instance.getHostIP(), true)); attrs.add(new ReplaceableAttribute(Attributes.HOSTNAME, instance.getHostName(), true)); attrs.add(new ReplaceableAttribute(Attributes.LOCATION, instance.getDC(), true)); attrs.add( new ReplaceableAttribute( Attributes.UPDATE_TS, Long.toString(instance.getUpdatetime()), true)); return attrs; }
/** * Convert a simpledb item to PriamInstance * * @param item * @return */ public PriamInstance transform(Item item) { PriamInstance ins = new PriamInstance(); Iterator<Attribute> attrs = item.getAttributes().iterator(); while (attrs.hasNext()) { Attribute att = attrs.next(); if (att.getName().equals(Attributes.INSTANCE_ID)) ins.setInstanceId(att.getValue()); else if (att.getName().equals(Attributes.TOKEN)) ins.setToken(att.getValue()); else if (att.getName().equals(Attributes.APP_ID)) ins.setApp(att.getValue()); else if (att.getName().equals(Attributes.ID)) ins.setId(Integer.parseInt(att.getValue())); else if (att.getName().equals(Attributes.AVAILABILITY_ZONE)) ins.setRac(att.getValue()); else if (att.getName().equals(Attributes.ELASTIC_IP)) ins.setHostIP(att.getValue()); else if (att.getName().equals(Attributes.HOSTNAME)) ins.setHost(att.getValue()); else if (att.getName().equals(Attributes.LOCATION)) ins.setDC(att.getValue()); else if (att.getName().equals(Attributes.UPDATE_TS)) ins.setUpdatetime(Long.parseLong(att.getValue())); } return ins; }
private String getKey(PriamInstance instance) { return instance.getApp() + instance.getId(); }