Search in sources :

Example 11 with DataCenterInfo

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)));
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo)

Example 12 with DataCenterInfo

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));
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 13 with DataCenterInfo

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;
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 14 with DataCenterInfo

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;
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) AmazonInfo(com.netflix.appinfo.AmazonInfo)

Example 15 with DataCenterInfo

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));
}
Also used : DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Aggregations

DataCenterInfo (com.netflix.appinfo.DataCenterInfo)16 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 AmazonInfo (com.netflix.appinfo.AmazonInfo)5 Test (org.junit.Test)5 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)2 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)2 UniqueIdentifier (com.netflix.appinfo.UniqueIdentifier)2 Before (org.junit.Before)2 HealthCheckHandler (com.netflix.appinfo.HealthCheckHandler)1 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 RefreshableInstanceConfig (com.netflix.appinfo.RefreshableInstanceConfig)1 Applications (com.netflix.discovery.shared.Applications)1 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)1 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)1 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)1 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)1 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)1 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1