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