use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class ApplicationResourceTest method testFullAppGet.
@Test
public void testFullAppGet() throws Exception {
Response response = applicationResource.getApplication(Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.full.name());
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Application decodedApp = decoder.decode(json, Application.class);
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(true));
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class ApplicationResourceTest method testMiniAppGet.
@Test
public void testMiniAppGet() throws Exception {
Response response = applicationResource.getApplication(Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.compact.name());
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Application decodedApp = decoder.decode(json, Application.class);
// assert false as one is mini, so should NOT equal
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false));
for (InstanceInfo instanceInfo : testApplication.getInstances()) {
InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
}
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class DiscoveryClient method getInstancesByVipAddressAndAppName.
/**
* Gets the list of instances matching the given VIP Address and the given
* application name if both of them are not null. If one of them is null,
* then that criterion is completely ignored for matching instances.
*
* @param vipAddress
* - The VIP address to match the instances for.
* @param appName
* - The applicationName to match the instances for.
* @param secure
* - true if it is a secure vip address, false otherwise.
* @return - The list of {@link InstanceInfo} objects matching the criteria.
*/
@Override
public List<InstanceInfo> getInstancesByVipAddressAndAppName(String vipAddress, String appName, boolean secure) {
List<InstanceInfo> result = new ArrayList<InstanceInfo>();
if (vipAddress == null && appName == null) {
throw new IllegalArgumentException("Supplied VIP Address and application name cannot both be null");
} else if (vipAddress != null && appName == null) {
return getInstancesByVipAddress(vipAddress, secure);
} else if (vipAddress == null && appName != null) {
Application application = getApplication(appName);
if (application != null) {
result = application.getInstances();
}
return result;
}
String instanceVipAddress;
for (Application app : getApplications().getRegisteredApplications()) {
for (InstanceInfo instance : app.getInstances()) {
if (secure) {
instanceVipAddress = instance.getSecureVipAddress();
} else {
instanceVipAddress = instance.getVIPAddress();
}
if (instanceVipAddress == null) {
continue;
}
String[] instanceVipAddresses = instanceVipAddress.split(COMMA_STRING);
// return the instance info for the same
for (String vipAddressFromList : instanceVipAddresses) {
if (vipAddress.equalsIgnoreCase(vipAddressFromList.trim()) && appName.equalsIgnoreCase(instance.getAppName())) {
result.add(instance);
break;
}
}
}
}
return result;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class DiscoveryClient method updateDelta.
/**
* Updates the delta information fetches from the eureka server into the
* local cache.
*
* @param delta
* the delta information received from eureka server in the last
* poll cycle.
*/
private void updateDelta(Applications delta) {
int deltaCount = 0;
for (Application app : delta.getRegisteredApplications()) {
for (InstanceInfo instance : app.getInstances()) {
Applications applications = getApplications();
String instanceRegion = instanceRegionChecker.getInstanceRegion(instance);
if (!instanceRegionChecker.isLocalRegion(instanceRegion)) {
Applications remoteApps = remoteRegionVsApps.get(instanceRegion);
if (null == remoteApps) {
remoteApps = new Applications();
remoteRegionVsApps.put(instanceRegion, remoteApps);
}
applications = remoteApps;
}
++deltaCount;
if (ActionType.ADDED.equals(instance.getActionType())) {
Application existingApp = applications.getRegisteredApplications(instance.getAppName());
if (existingApp == null) {
applications.addApplication(app);
}
logger.debug("Added instance {} to the existing apps in region {}", instance.getId(), instanceRegion);
applications.getRegisteredApplications(instance.getAppName()).addInstance(instance);
} else if (ActionType.MODIFIED.equals(instance.getActionType())) {
Application existingApp = applications.getRegisteredApplications(instance.getAppName());
if (existingApp == null) {
applications.addApplication(app);
}
logger.debug("Modified instance {} to the existing apps ", instance.getId());
applications.getRegisteredApplications(instance.getAppName()).addInstance(instance);
} else if (ActionType.DELETED.equals(instance.getActionType())) {
Application existingApp = applications.getRegisteredApplications(instance.getAppName());
if (existingApp == null) {
applications.addApplication(app);
}
logger.debug("Deleted instance {} to the existing apps ", instance.getId());
applications.getRegisteredApplications(instance.getAppName()).removeInstance(instance);
}
}
}
logger.debug("The total number of instances fetched by the delta processor : {}", deltaCount);
getApplications().setVersion(delta.getVersion());
getApplications().shuffleInstances(clientConfig.shouldFilterOnlyUpInstances());
for (Applications applications : remoteRegionVsApps.values()) {
applications.setVersion(delta.getVersion());
applications.shuffleInstances(clientConfig.shouldFilterOnlyUpInstances());
}
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class ApplicationXmlDeserializer method deserialize.
@Override
public Application deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String name = null;
List<InstanceInfo> instances = new ArrayList<>();
while (jp.nextToken() == JsonToken.FIELD_NAME) {
String fieldName = jp.getCurrentName();
// to point to value
jp.nextToken();
if ("name".equals(fieldName)) {
name = jp.getValueAsString();
} else if ("instance".equals(fieldName)) {
instances.add(jp.readValueAs(InstanceInfo.class));
} else {
throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation());
}
}
return new Application(name, instances);
}
Aggregations