Search in sources :

Example 16 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class InstanceRegionCheckerTest method testDefaultOverride.

@Test
public void testDefaultOverride() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.us-east-1.availabilityZones", "abc,def");
    PropertyBasedAzToRegionMapper azToRegionMapper = new PropertyBasedAzToRegionMapper(new DefaultEurekaClientConfig());
    InstanceRegionChecker checker = new InstanceRegionChecker(azToRegionMapper, "us-east-1");
    azToRegionMapper.setRegionsToFetch(new String[] { "us-east-1" });
    AmazonInfo dcInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "def").build();
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("app").setDataCenterInfo(dcInfo).build();
    String instanceRegion = checker.getInstanceRegion(instanceInfo);
    Assert.assertEquals("Invalid instance region.", "us-east-1", instanceRegion);
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 17 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class InstanceRegionCheckerTest method testNotMappedAZNotFollowingFormat.

@Test
public void testNotMappedAZNotFollowingFormat() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.us-east-1.availabilityZones", "abc,def");
    PropertyBasedAzToRegionMapper azToRegionMapper = new PropertyBasedAzToRegionMapper(new DefaultEurekaClientConfig());
    InstanceRegionChecker checker = new InstanceRegionChecker(azToRegionMapper, "us-east-1");
    azToRegionMapper.setRegionsToFetch(new String[] { "us-east-1" });
    AmazonInfo dcInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "us-east-x").build();
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("abc").setDataCenterInfo(dcInfo).build();
    String instanceRegion = checker.getInstanceRegion(instanceInfo);
    Assert.assertNull("Invalid instance region.", instanceRegion);
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 18 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class InstanceRegionCheckerTest method testNotMappedAZ.

@Test
public void testNotMappedAZ() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.us-east-1.availabilityZones", "abc,def");
    PropertyBasedAzToRegionMapper azToRegionMapper = new PropertyBasedAzToRegionMapper(new DefaultEurekaClientConfig());
    InstanceRegionChecker checker = new InstanceRegionChecker(azToRegionMapper, "us-east-1");
    azToRegionMapper.setRegionsToFetch(new String[] { "us-east-1" });
    AmazonInfo dcInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "us-east-1x").build();
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("abc").setDataCenterInfo(dcInfo).build();
    String instanceRegion = checker.getInstanceRegion(instanceInfo);
    Assert.assertEquals("Invalid instance region.", "us-east-1", instanceRegion);
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 19 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class InstanceRegionCheckerTest method testInstanceWithNoAZ.

@Test
public void testInstanceWithNoAZ() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.us-east-1.availabilityZones", "abc,def");
    PropertyBasedAzToRegionMapper azToRegionMapper = new PropertyBasedAzToRegionMapper(new DefaultEurekaClientConfig());
    InstanceRegionChecker checker = new InstanceRegionChecker(azToRegionMapper, "us-east-1");
    azToRegionMapper.setRegionsToFetch(new String[] { "us-east-1" });
    AmazonInfo dcInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "").build();
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("app").setDataCenterInfo(dcInfo).build();
    String instanceRegion = checker.getInstanceRegion(instanceInfo);
    Assert.assertNull("Invalid instance region.", instanceRegion);
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 20 with AmazonInfo

use of com.netflix.appinfo.AmazonInfo in project eureka by Netflix.

the class BackUpRegistryTest method createLocalInstance.

private InstanceInfo createLocalInstance(String instanceHostName) {
    InstanceInfo.Builder instanceBuilder = InstanceInfo.Builder.newBuilder();
    instanceBuilder.setAppName(LOCAL_REGION_APP_NAME);
    instanceBuilder.setVIPAddress(ALL_REGIONS_VIP_ADDR);
    instanceBuilder.setHostName(instanceHostName);
    instanceBuilder.setIPAddr("10.10.101.1");
    AmazonInfo amazonInfo = getAmazonInfo(null, instanceHostName);
    instanceBuilder.setDataCenterInfo(amazonInfo);
    instanceBuilder.setMetadata(amazonInfo.getMetadata());
    return instanceBuilder.build();
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

AmazonInfo (com.netflix.appinfo.AmazonInfo)30 InstanceInfo (com.netflix.appinfo.InstanceInfo)21 Test (org.junit.Test)7 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)4 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)2 Builder (com.netflix.appinfo.InstanceInfo.Builder)2 DiscoveryClient (com.netflix.discovery.DiscoveryClient)2 Address (com.amazonaws.services.ec2.model.Address)1 AssociateAddressRequest (com.amazonaws.services.ec2.model.AssociateAddressRequest)1 DescribeAddressesRequest (com.amazonaws.services.ec2.model.DescribeAddressesRequest)1 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)1 LeaseInfo (com.netflix.appinfo.LeaseInfo)1 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)1 UniqueIdentifier (com.netflix.appinfo.UniqueIdentifier)1 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)1 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)1 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)1