use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.
the class BackUpRegistryTest method createRemoteInstance.
private InstanceInfo createRemoteInstance(String instanceHostName) {
InstanceInfo.Builder instanceBuilder = InstanceInfo.Builder.newBuilder();
instanceBuilder.setAppName(REMOTE_REGION_APP_NAME);
instanceBuilder.setVIPAddress(ALL_REGIONS_VIP_ADDR);
instanceBuilder.setHostName(instanceHostName);
instanceBuilder.setIPAddr("10.10.101.1");
AmazonInfo amazonInfo = getAmazonInfo(REMOTE_ZONE, instanceHostName);
instanceBuilder.setDataCenterInfo(amazonInfo);
instanceBuilder.setMetadata(amazonInfo.getMetadata());
return instanceBuilder.build();
}
use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.
the class EurekaJsonAndXmlJacksonCodecTest method doAmazonInfoEncodeDecodeTest.
private void doAmazonInfoEncodeDecodeTest(AbstractEurekaJacksonCodec codec) throws Exception {
AmazonInfo amazonInfo = (AmazonInfo) infoIterator.next().getDataCenterInfo();
String encodedString = codec.getObjectMapper(DataCenterInfo.class).writeValueAsString(amazonInfo);
DataCenterInfo decodedValue = codec.getObjectMapper(DataCenterInfo.class).readValue(encodedString, DataCenterInfo.class);
assertThat(EurekaEntityComparators.equal(amazonInfo, decodedValue), is(true));
}
use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method isRegisterable.
/**
* Checks if an instance is registerable in this region. Instances from other regions are rejected.
*
* @param instanceInfo th instance info information of the instance
* @return true, if it can be registered in this server, false otherwise.
*/
public boolean isRegisterable(InstanceInfo instanceInfo) {
DataCenterInfo datacenterInfo = instanceInfo.getDataCenterInfo();
String serverRegion = clientConfig.getRegion();
if (AmazonInfo.class.isInstance(datacenterInfo)) {
AmazonInfo info = AmazonInfo.class.cast(instanceInfo.getDataCenterInfo());
String availabilityZone = info.get(MetaDataKey.availabilityZone);
// Can be null for dev environments in non-AWS data center
if (availabilityZone == null && US_EAST_1.equalsIgnoreCase(serverRegion)) {
return true;
} else if ((availabilityZone != null) && (availabilityZone.contains(serverRegion))) {
// If in the same region as server, then consider it registerable
return true;
}
}
// Everything non-amazon is registrable.
return true;
}
use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.
the class AwsAsgUtil method getAccountId.
private String getAccountId(InstanceInfo instanceInfo, String fallbackId) {
String localAccountId = null;
DataCenterInfo dataCenterInfo = instanceInfo.getDataCenterInfo();
if (dataCenterInfo instanceof AmazonInfo) {
localAccountId = ((AmazonInfo) dataCenterInfo).get(MetaDataKey.accountId);
}
return localAccountId == null ? fallbackId : localAccountId;
}
use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.
the class EIPManager method isEIPBound.
/**
* Checks if an EIP is already bound to the instance.
* @return true if an EIP is bound, false otherwise
*/
public boolean isEIPBound() {
InstanceInfo myInfo = applicationInfoManager.getInfo();
String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.instanceId);
String myZone = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.availabilityZone);
String myPublicIP = ((AmazonInfo) myInfo.getDataCenterInfo()).get(MetaDataKey.publicIpv4);
Collection<String> candidateEIPs = getCandidateEIPs(myInstanceId, myZone);
for (String eipEntry : candidateEIPs) {
if (eipEntry.equals(myPublicIP)) {
logger.info("My instance {} seems to be already associated with the public ip {}", myInstanceId, myPublicIP);
return true;
}
}
return false;
}
Aggregations