use of com.netflix.appinfo.DataCenterInfo in project eureka by Netflix.
the class EurekaJsonAndXmlJacksonCodecTest method doMyDataCenterInfoEncodeDecodeTest.
private void doMyDataCenterInfoEncodeDecodeTest(AbstractEurekaJacksonCodec codec) throws Exception {
DataCenterInfo myDataCenterInfo = new DataCenterInfo() {
@Override
public Name getName() {
return Name.MyOwn;
}
};
String encodedString = codec.getObjectMapper(DataCenterInfo.class).writeValueAsString(myDataCenterInfo);
DataCenterInfo decodedValue = codec.getObjectMapper(DataCenterInfo.class).readValue(encodedString, DataCenterInfo.class);
assertThat(decodedValue.getName(), is(equalTo(Name.MyOwn)));
}
use of com.netflix.appinfo.DataCenterInfo 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.DataCenterInfo 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.DataCenterInfo 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.DataCenterInfo in project eureka by Netflix.
the class EurekaUtilsTest method testIsInEc2.
@Test
public void testIsInEc2() {
InstanceInfo instanceInfo1 = new InstanceInfo.Builder(InstanceInfoGenerator.takeOne()).setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return Name.MyOwn;
}
}).build();
Assert.assertFalse(EurekaUtils.isInEc2(instanceInfo1));
InstanceInfo instanceInfo2 = InstanceInfoGenerator.takeOne();
Assert.assertTrue(EurekaUtils.isInEc2(instanceInfo2));
}
Aggregations