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());
}
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));
}
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));
}
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))));
}
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));
}
Aggregations