use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaEntityFunctionsTest method testCopyInstancesIfNotNullReturnCollectionOfInstanceInfo.
@Test
public void testCopyInstancesIfNotNullReturnCollectionOfInstanceInfo() {
Application application = createSingleInstanceApp("foo", "foo", InstanceInfo.ActionType.ADDED);
Assert.assertEquals(1, EurekaEntityFunctions.copyInstances(new ArrayList<>(Arrays.asList(application.getByInstanceId("foo"))), InstanceInfo.ActionType.ADDED).size());
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaEntityFunctionsTest method testCopyApplicationIfNotNullReturnApplication.
@Test
public void testCopyApplicationIfNotNullReturnApplication() {
Application application = createSingleInstanceApp("foo", "foo", InstanceInfo.ActionType.ADDED);
Assert.assertEquals(1, EurekaEntityFunctions.copyApplication(application).size());
}
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<>();
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) {
logger.debug("Deleted instance {} to the existing apps ", instance.getId());
existingApp.removeInstance(instance);
/*
* We find all instance list from application(The status of instance status is not only the status is UP but also other status)
* if instance list is empty, we remove the application.
*/
if (existingApp.getInstancesAsIsFromEureka().isEmpty()) {
applications.removeApplication(existingApp);
}
}
}
}
}
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