Search in sources :

Example 16 with InstanceInfo

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

the class DiscoveryClientRegistryTest method testGetByVipInLocalRegion.

@Test
public void testGetByVipInLocalRegion() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(4, "app1", "app2").build().toApplications();
    InstanceInfo instance = applications.getRegisteredApplications("app1").getInstances().get(0);
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, applications).type(MediaType.APPLICATION_JSON_TYPE).build());
    List<InstanceInfo> result = discoveryClientResource.getClient().getInstancesByVipAddress(instance.getVIPAddress(), false);
    assertThat(result.size(), is(equalTo(2)));
    assertThat(result.get(0).getVIPAddress(), is(equalTo(instance.getVIPAddress())));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 17 with InstanceInfo

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

the class Applications method addInstancesToVIPMaps.

/**
     * Adds the instances to the internal vip address map.
     * @param app - the applications for which the instances need to be added.
     */
private void addInstancesToVIPMaps(Application app) {
    // mappings
    for (InstanceInfo info : app.getInstances()) {
        String vipAddresses = info.getVIPAddress();
        String secureVipAddresses = info.getSecureVipAddress();
        if ((vipAddresses == null) && (secureVipAddresses == null)) {
            continue;
        }
        addInstanceToMap(info, vipAddresses, virtualHostNameAppMap);
        addInstanceToMap(info, secureVipAddresses, secureVirtualHostNameAppMap);
    }
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 18 with InstanceInfo

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

the class Applications method populateInstanceCountMap.

/**
     * Populates the provided instance count map.  The instance count map is used as part of the general
     * app list synchronization mechanism.
     * @param instanceCountMap the map to populate
     */
public void populateInstanceCountMap(TreeMap<String, AtomicInteger> instanceCountMap) {
    for (Application app : this.getRegisteredApplications()) {
        for (InstanceInfo info : app.getInstancesAsIsFromEureka()) {
            AtomicInteger instanceCount = instanceCountMap.get(info.getStatus().name());
            if (instanceCount == null) {
                instanceCount = new AtomicInteger(0);
                instanceCountMap.put(info.getStatus().name(), instanceCount);
            }
            instanceCount.incrementAndGet();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 19 with InstanceInfo

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

the class InstanceInfoJsonBeanSerializer method serializeFields.

@Override
protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvider provider) throws IOException {
    super.serializeFields(bean, jgen0, provider);
    InstanceInfo instanceInfo = (InstanceInfo) bean;
    jgen0.writeFieldName("port");
    jgen0.writeStartObject();
    jgen0.writeNumberField("$", instanceInfo.getPort());
    jgen0.writeStringField("@enabled", Boolean.toString(instanceInfo.isPortEnabled(PortType.UNSECURE)));
    jgen0.writeEndObject();
    jgen0.writeFieldName("securePort");
    jgen0.writeStartObject();
    jgen0.writeNumberField("$", instanceInfo.getSecurePort());
    jgen0.writeStringField("@enabled", Boolean.toString(instanceInfo.isPortEnabled(PortType.SECURE)));
    jgen0.writeEndObject();
    // Save @class field for backward compatibility. Remove once all clients are migrated to the new codec
    if (!compactMode) {
        jgen0.writeFieldName("metadata");
        if (instanceInfo.getMetadata() == null || instanceInfo.getMetadata().isEmpty()) {
            stringMapObjectMapper.writeValue(jgen0, EMPTY_MAP);
        } else {
            stringMapObjectMapper.writeValue(jgen0, instanceInfo.getMetadata());
        }
    }
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 20 with InstanceInfo

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

the class EurekaCodecCompatibilityTest method testInstanceInfoFullEncodeMiniDecodeJackson.

/**
     * During deserialization process in compact mode not all fields might be filtered out. If JVM memory
     * is an issue, compact version of the encoder should be used on the server side.
     */
@Test
public void testInstanceInfoFullEncodeMiniDecodeJackson() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.JacksonJson(), new CodecWrappers.JacksonJsonMini());
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

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