Search in sources :

Example 96 with InstanceInfo

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

the class InstanceInfoXmlBeanSerializer method serializeFields.

@Override
protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvider provider) throws IOException {
    super.serializeFields(bean, jgen0, provider);
    InstanceInfo instanceInfo = (InstanceInfo) bean;
    ToXmlGenerator xgen = (ToXmlGenerator) jgen0;
    xgen.writeFieldName("port");
    xgen.writeStartObject();
    xgen.setNextIsAttribute(true);
    xgen.writeFieldName("enabled");
    xgen.writeBoolean(instanceInfo.isPortEnabled(PortType.UNSECURE));
    xgen.setNextIsAttribute(false);
    xgen.writeFieldName("port");
    xgen.setNextIsUnwrapped(true);
    xgen.writeString(Integer.toString(instanceInfo.getPort()));
    xgen.writeEndObject();
    xgen.writeFieldName("securePort");
    xgen.writeStartObject();
    xgen.setNextIsAttribute(true);
    xgen.writeStringField("enabled", Boolean.toString(instanceInfo.isPortEnabled(PortType.SECURE)));
    xgen.setNextIsAttribute(false);
    xgen.writeFieldName("securePort");
    xgen.setNextIsUnwrapped(true);
    xgen.writeString(Integer.toString(instanceInfo.getSecurePort()));
    xgen.writeEndObject();
}
Also used : ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 97 with InstanceInfo

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

the class DiscoveryManager method initComponent.

/**
     * Initializes the <tt>Discovery Client</tt> with the given configuration.
     *
     * @param config
     *            the instance info configuration that will be used for
     *            registration with Eureka.
     * @param eurekaConfig the eureka client configuration of the instance.
     */
public void initComponent(EurekaInstanceConfig config, EurekaClientConfig eurekaConfig, AbstractDiscoveryClientOptionalArgs args) {
    this.eurekaInstanceConfig = config;
    this.eurekaClientConfig = eurekaConfig;
    if (ApplicationInfoManager.getInstance().getInfo() == null) {
        // Initialize application info
        ApplicationInfoManager.getInstance().initComponent(config);
    }
    InstanceInfo info = ApplicationInfoManager.getInstance().getInfo();
    discoveryClient = new DiscoveryClient(info, eurekaConfig, args);
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 98 with InstanceInfo

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

the class AbstractJersey2EurekaHttpClient method getInstanceInternal.

private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
    Response response = null;
    try {
        Builder requestBuilder = jerseyClient.target(serviceUrl).path(urlPath).request();
        addExtraProperties(requestBuilder);
        addExtraHeaders(requestBuilder);
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
        InstanceInfo infoFromPeer = null;
        if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
            infoFromPeer = response.readEntity(InstanceInfo.class);
        }
        return anEurekaHttpResponse(response.getStatus(), infoFromPeer).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) Response(javax.ws.rs.core.Response) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(javax.ws.rs.client.Invocation.Builder) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 99 with InstanceInfo

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

the class Jersey2EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // has a binding for jersey2
    Assert.assertNotNull(binding);
    TransportClientFactories transportClientFactories = injector.getInstance(TransportClientFactories.class);
    Assert.assertTrue(transportClientFactories instanceof Jersey2TransportClientFactories);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 100 with InstanceInfo

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

the class Application method _shuffleAndStoreInstances.

private void _shuffleAndStoreInstances(boolean filterUpInstances, boolean indexByRemoteRegions, @Nullable Map<String, Applications> remoteRegionsRegistry, @Nullable EurekaClientConfig clientConfig, @Nullable InstanceRegionChecker instanceRegionChecker) {
    List<InstanceInfo> instanceInfoList;
    synchronized (instances) {
        instanceInfoList = new ArrayList<InstanceInfo>(instances);
    }
    if (indexByRemoteRegions || filterUpInstances) {
        Iterator<InstanceInfo> it = instanceInfoList.iterator();
        while (it.hasNext()) {
            InstanceInfo instanceInfo = it.next();
            if (filterUpInstances && !InstanceStatus.UP.equals(instanceInfo.getStatus())) {
                it.remove();
            } else if (indexByRemoteRegions && null != instanceRegionChecker && null != clientConfig && null != remoteRegionsRegistry) {
                String instanceRegion = instanceRegionChecker.getInstanceRegion(instanceInfo);
                if (!instanceRegionChecker.isLocalRegion(instanceRegion)) {
                    Applications appsForRemoteRegion = remoteRegionsRegistry.get(instanceRegion);
                    if (null == appsForRemoteRegion) {
                        appsForRemoteRegion = new Applications();
                        remoteRegionsRegistry.put(instanceRegion, appsForRemoteRegion);
                    }
                    Application remoteApp = appsForRemoteRegion.getRegisteredApplications(instanceInfo.getAppName());
                    if (null == remoteApp) {
                        remoteApp = new Application(instanceInfo.getAppName());
                        appsForRemoteRegion.addApplication(remoteApp);
                    }
                    remoteApp.addInstance(instanceInfo);
                    this.removeInstance(instanceInfo, false);
                    it.remove();
                }
            }
        }
    }
    Collections.shuffle(instanceInfoList);
    this.shuffledInstances.set(instanceInfoList);
}
Also used : 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