Search in sources :

Example 56 with InstanceInfo

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

the class PeerEurekaNodes method isThisMe.

/**
     * @deprecated 2016-06-27 use instance version of {@link #isThisMyUrl(String)}
     *
     * Checks if the given service url contains the current host which is trying
     * to replicate. Only after the EIP binding is done the host has a chance to
     * identify itself in the list of replica nodes and needs to take itself out
     * of replication traffic.
     *
     * @param url the service url of the replica node that the check is made.
     * @return true, if the url represents the current node which is trying to
     *         replicate, false otherwise.
     */
public static boolean isThisMe(String url) {
    InstanceInfo myInfo = ApplicationInfoManager.getInstance().getInfo();
    String hostName = hostFromUrl(url);
    return hostName != null && hostName.equals(myInfo.getHostName());
}
Also used : InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 57 with InstanceInfo

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

the class EurekaJacksonCodecTest method testInstanceInfoJacksonEncodeDecodeWithoutMetaData.

@Test
public void testInstanceInfoJacksonEncodeDecodeWithoutMetaData() throws Exception {
    InstanceInfo noMetaDataInfo = InstanceInfoGenerator.newBuilder(1, 1).withMetaData(false).build().serviceIterator().next();
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(noMetaDataInfo, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    InstanceInfo decoded = codec.readValue(InstanceInfo.class, source);
    assertTrue(EurekaEntityComparators.equal(decoded, noMetaDataInfo));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 58 with InstanceInfo

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

the class EurekaJacksonCodecTest method testJacksonWrite.

@Test
public void testJacksonWrite() throws Exception {
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(INSTANCE_INFO_1_A1, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode value
    InputStream source = new ByteArrayInputStream(encoded);
    InstanceInfo decoded = codec.readValue(InstanceInfo.class, source);
    assertTrue(EurekaEntityComparators.equal(decoded, INSTANCE_INFO_1_A1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 59 with InstanceInfo

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

the class EurekaJsonAndXmlJacksonCodecTest method doInstanceInfoIgnoredFieldsAreFilteredOutDuringDeserializationProcess.

public void doInstanceInfoIgnoredFieldsAreFilteredOutDuringDeserializationProcess(AbstractEurekaJacksonCodec fullCodec, AbstractEurekaJacksonCodec compactCodec) throws Exception {
    InstanceInfo instanceInfo = infoIterator.next();
    // We use regular codec here to have all fields serialized
    String encodedString = fullCodec.getObjectMapper(InstanceInfo.class).writeValueAsString(instanceInfo);
    InstanceInfo decodedValue = compactCodec.getObjectMapper(InstanceInfo.class).readValue(encodedString, InstanceInfo.class);
    assertThat(decodedValue.getId(), is(equalTo(instanceInfo.getId())));
    assertThat(decodedValue.getAppName(), is(equalTo(instanceInfo.getAppName())));
    assertThat(decodedValue.getIPAddr(), is(equalTo(instanceInfo.getIPAddr())));
    assertThat(decodedValue.getVIPAddress(), is(equalTo(instanceInfo.getVIPAddress())));
    assertThat(decodedValue.getSecureVipAddress(), is(equalTo(instanceInfo.getSecureVipAddress())));
    assertThat(decodedValue.getHostName(), is(equalTo(instanceInfo.getHostName())));
    assertThat(decodedValue.getStatus(), is(equalTo(instanceInfo.getStatus())));
    assertThat(decodedValue.getActionType(), is(equalTo(instanceInfo.getActionType())));
    assertThat(decodedValue.getASGName(), is(equalTo(instanceInfo.getASGName())));
    assertThat(decodedValue.getLastUpdatedTimestamp(), is(equalTo(instanceInfo.getLastUpdatedTimestamp())));
    AmazonInfo sourceAmazonInfo = (AmazonInfo) instanceInfo.getDataCenterInfo();
    AmazonInfo decodedAmazonInfo = (AmazonInfo) decodedValue.getDataCenterInfo();
    assertThat(decodedAmazonInfo.get(MetaDataKey.accountId), is(equalTo(sourceAmazonInfo.get(MetaDataKey.accountId))));
}
Also used : AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 60 with InstanceInfo

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

the class EurekaJsonAndXmlJacksonCodecTest method doInstanceInfoCompactEncodeDecode.

private void doInstanceInfoCompactEncodeDecode(AbstractEurekaJacksonCodec codec, boolean isJson) throws Exception {
    InstanceInfo instanceInfo = infoIterator.next();
    String encodedString = codec.getObjectMapper(InstanceInfo.class).writeValueAsString(instanceInfo);
    if (isJson) {
        JsonNode metadataNode = new ObjectMapper().readTree(encodedString).get("instance").get("metadata");
        assertThat(metadataNode, is(nullValue()));
    }
    InstanceInfo decodedValue = codec.getObjectMapper(InstanceInfo.class).readValue(encodedString, InstanceInfo.class);
    assertThat(decodedValue.getId(), is(equalTo(instanceInfo.getId())));
    assertThat(decodedValue.getMetadata().isEmpty(), is(true));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) InstanceInfo(com.netflix.appinfo.InstanceInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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