Search in sources :

Example 16 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class ApplicationsResolver method getClusterEndpoints.

@Override
public List<AwsEndpoint> getClusterEndpoints() {
    List<AwsEndpoint> result = new ArrayList<>();
    Applications applications = applicationsSource.getApplications(transportConfig.getApplicationsResolverDataStalenessThresholdSeconds(), TimeUnit.SECONDS);
    if (applications != null && vipAddress != null) {
        List<InstanceInfo> validInstanceInfos = applications.getInstancesByVirtualHostName(vipAddress);
        for (InstanceInfo instanceInfo : validInstanceInfos) {
            if (instanceInfo.getStatus() == InstanceInfo.InstanceStatus.UP) {
                AwsEndpoint endpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceInfo);
                if (endpoint != null) {
                    result.add(endpoint);
                }
            }
        }
    }
    logger.debug("Retrieved endpoint list {}", result);
    return result;
}
Also used : Applications(com.netflix.discovery.shared.Applications) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 17 with Applications

use of com.netflix.discovery.shared.Applications 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 18 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class CodecLoadTester method createJacksonNgAction.

Func0 createJacksonNgAction(final MediaType mediaType, final boolean compact) {
    return new Func0<Object>() {

        @Override
        public int call(Object object) {
            AbstractEurekaJacksonCodec codec;
            if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
                codec = compact ? jsonCodecNgCompact : jsonCodecNG;
            } else {
                codec = compact ? xmlCodecNgCompact : xmlCodecNG;
            }
            ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
            try {
                codec.writeTo(object, captureStream);
                byte[] bytes = captureStream.toByteArray();
                InputStream source = new ByteArrayInputStream(bytes);
                Applications readValue = codec.getObjectMapper(object.getClass()).readValue(source, Applications.class);
                secondHolder.value = readValue;
                return bytes.length;
            } catch (IOException e) {
                throw new RuntimeException("unexpected", e);
            }
        }
    };
}
Also used : AbstractEurekaJacksonCodec(com.netflix.discovery.converters.jackson.AbstractEurekaJacksonCodec) Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 19 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class CodecLoadTester method loadWithCodec.

private Applications loadWithCodec(String fileName, MediaType mediaType) throws IOException {
    FileInputStream fis = new FileInputStream(fileName);
    BufferedInputStream bis = new BufferedInputStream(fis);
    return (Applications) xstreamCodec.read(bis, Applications.class, mediaType);
}
Also used : Applications(com.netflix.discovery.shared.Applications) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream)

Example 20 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class BackUpRegistryTest method testLocalOnly.

@Test
public void testLocalOnly() throws Exception {
    setUp(false);
    Applications applications = client.getApplications();
    List<Application> registeredApplications = applications.getRegisteredApplications();
    System.out.println("***" + registeredApplications);
    Assert.assertNotNull("Local region apps not found.", registeredApplications);
    Assert.assertEquals("Local apps size not as expected.", 1, registeredApplications.size());
    Assert.assertEquals("Local region apps not present.", LOCAL_REGION_APP_NAME, registeredApplications.get(0).getName());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Aggregations

Applications (com.netflix.discovery.shared.Applications)85 Test (org.junit.Test)43 Application (com.netflix.discovery.shared.Application)25 InstanceInfo (com.netflix.appinfo.InstanceInfo)22 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)11 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)10 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)8 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Response (javax.ws.rs.core.Response)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3