/** * Refresh instance info - currently only used when in AWS cloud as a public ip can change * whenever an EIP is associated or dissociated. */ public synchronized void refreshAmazonInfo() { try { AmazonInfo newInfo = AmazonInfo.Builder.newBuilder().autoBuild(namespace); if (shouldUpdate(newInfo, info)) { // the datacenter info has changed, re-sync it logger.info("The AmazonInfo changed from : {} => {}", info, newInfo); this.info = newInfo; } } catch (Throwable t) { logger.error("Cannot refresh the Amazon Info ", t); } }
private AmazonInfo initDataCenterInfo() { AmazonInfo info; try { info = AmazonInfo.Builder.newBuilder().autoBuild(namespace); logger.info("Datacenter is: " + Name.Amazon); } catch (Throwable e) { logger.error("Cannot initialize amazon info :", e); throw new RuntimeException(e); } // Instance id being null means we could not get the amazon metadata if (info.get(MetaDataKey.instanceId) == null) { if (propValidateInstanceId.get()) { throw new RuntimeException( "Your datacenter is defined as cloud but we are not able to get the amazon metadata to " + "register. \nSet the property " + namespace + "validateInstanceId to false to " + "ignore the metadata call"); } else { // The property to not validate instance ids may be set for // development and in that scenario, populate instance id // and public hostname with the hostname of the machine Map<String, String> metadataMap = new HashMap<String, String>(); metadataMap.put(MetaDataKey.instanceId.getName(), super.getIpAddress()); metadataMap.put(MetaDataKey.publicHostname.getName(), super.getHostName(false)); info.setMetadata(metadataMap); } } else if ((info.get(MetaDataKey.publicHostname) == null) && (info.get(MetaDataKey.localIpv4) != null)) { // :( legacy code and logic // This might be a case of VPC where the instance id is not null, but // public hostname might be null info.getMetadata() .put(MetaDataKey.publicHostname.getName(), (info.get(MetaDataKey.localIpv4))); } return info; }