Search in sources :

Example 31 with InstanceInfo

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

the class EurekaHttpResolver method getClusterEndpoints.

@Override
public List<AwsEndpoint> getClusterEndpoints() {
    List<AwsEndpoint> result = new ArrayList<>();
    EurekaHttpClient client = null;
    try {
        client = clientFactory.newClient();
        EurekaHttpResponse<Applications> response = client.getVip(vipAddress);
        if (validResponse(response)) {
            Applications applications = response.getEntity();
            if (applications != null) {
                // filter out non-UP instances
                applications.shuffleInstances(true);
                List<InstanceInfo> validInstanceInfos = applications.getInstancesByVirtualHostName(vipAddress);
                for (InstanceInfo instanceInfo : validInstanceInfos) {
                    AwsEndpoint endpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceInfo);
                    if (endpoint != null) {
                        result.add(endpoint);
                    }
                }
                logger.debug("Retrieved endpoint list {}", result);
                return result;
            }
        }
    } catch (Exception e) {
        logger.error("Error contacting server for endpoints with vipAddress:{}", vipAddress, e);
    } finally {
        if (client != null) {
            client.shutdown();
        }
    }
    logger.info("Returning empty endpoint list");
    return Collections.emptyList();
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaHttpClient(com.netflix.discovery.shared.transport.EurekaHttpClient) RetryableEurekaHttpClient(com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 32 with InstanceInfo

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

the class InstanceRegionCheckerTest method testDefaults.

@Test
public void testDefaults() throws Exception {
    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-1c").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 33 with InstanceInfo

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

the class BackUpRegistryTest method createLocalApps.

private Application createLocalApps() {
    Application myapp = new Application(LOCAL_REGION_APP_NAME);
    InstanceInfo instanceInfo = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
    myapp.addInstance(instanceInfo);
    return myapp;
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 34 with InstanceInfo

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

the class BackUpRegistryTest method createRemoteApps.

private Application createRemoteApps() {
    Application myapp = new Application(REMOTE_REGION_APP_NAME);
    InstanceInfo instanceInfo = createRemoteInstance(REMOTE_REGION_INSTANCE_1_HOSTNAME);
    myapp.addInstance(instanceInfo);
    return myapp;
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 35 with InstanceInfo

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

the class BaseDiscoveryClientTester method createInstance.

protected static InstanceInfo createInstance(String appName, String vipAddress, String instanceHostName, String zone) {
    InstanceInfo.Builder instanceBuilder = InstanceInfo.Builder.newBuilder();
    instanceBuilder.setAppName(appName);
    instanceBuilder.setVIPAddress(vipAddress);
    instanceBuilder.setHostName(instanceHostName);
    instanceBuilder.setIPAddr("10.10.101.1");
    AmazonInfo amazonInfo = getAmazonInfo(zone, instanceHostName);
    instanceBuilder.setDataCenterInfo(amazonInfo);
    instanceBuilder.setMetadata(amazonInfo.getMetadata());
    instanceBuilder.setLeaseInfo(LeaseInfo.Builder.newBuilder().build());
    return instanceBuilder.build();
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)192 Test (org.junit.Test)74 Application (com.netflix.discovery.shared.Application)35 Applications (com.netflix.discovery.shared.Applications)22 AmazonInfo (com.netflix.appinfo.AmazonInfo)21 ArrayList (java.util.ArrayList)19 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)11 Before (org.junit.Before)11 DiscoveryClient (com.netflix.discovery.DiscoveryClient)10 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)10 Lease (com.netflix.eureka.lease.Lease)9 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)7 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)6 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6