use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaHttpResolverTest method testNoValidDataFromRemoteServer.
@Test
public void testNoValidDataFromRemoteServer() {
Applications newApplications = new Applications();
for (Application application : applications.getRegisteredApplications()) {
if (!application.getInstances().get(0).getVIPAddress().equals(vipAddress)) {
newApplications.addApplication(application);
}
}
when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, newApplications).build());
List<AwsEndpoint> endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.isEmpty(), is(true));
verify(httpClient, times(1)).shutdown();
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method updateRenewalThreshold.
/**
* Updates the <em>renewal threshold</em> based on the current number of
* renewals. The threshold is a percentage as specified in
* {@link EurekaServerConfig#getRenewalPercentThreshold()} of renewals
* received per minute {@link #getNumOfRenewsInLastMin()}.
*/
private void updateRenewalThreshold() {
try {
Applications apps = eurekaClient.getApplications();
int count = 0;
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo instance : app.getInstances()) {
if (this.isRegisterable(instance)) {
++count;
}
}
}
synchronized (lock) {
// current expected threshold of if the self preservation is disabled.
if ((count * 2) > (serverConfig.getRenewalPercentThreshold() * numberOfRenewsPerMinThreshold) || (!this.isSelfPreservationModeEnabled())) {
this.expectedNumberOfRenewsPerMin = count * 2;
this.numberOfRenewsPerMinThreshold = (int) ((count * 2) * serverConfig.getRenewalPercentThreshold());
}
}
logger.info("Current renewal threshold is : {}", numberOfRenewsPerMinThreshold);
} catch (Throwable e) {
logger.error("Cannot update renewal threshold", e);
}
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class RemoteRegionRegistry method logTotalInstances.
/**
* Logs the total number of non-filtered instances stored locally.
*/
private void logTotalInstances() {
int totInstances = 0;
for (Application application : getApplications().getRegisteredApplications()) {
totInstances += application.getInstancesAsIsFromEureka().size();
}
logger.debug("The total number of all instances in the client now is {}", totInstances);
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class ResponseCacheImpl method getApplicationsForVip.
private static Applications getApplicationsForVip(Key key, AbstractInstanceRegistry registry) {
Object[] args = { key.getEntityType(), key.getName(), key.getVersion(), key.getType() };
logger.debug("Retrieving applications from registry for key : {} {} {} {}", args);
Applications toReturn = new Applications();
Applications applications = registry.getApplications();
for (Application application : applications.getRegisteredApplications()) {
Application appToAdd = null;
for (InstanceInfo instanceInfo : application.getInstances()) {
String vipAddress;
if (Key.EntityType.VIP.equals(key.getEntityType())) {
vipAddress = instanceInfo.getVIPAddress();
} else if (Key.EntityType.SVIP.equals(key.getEntityType())) {
vipAddress = instanceInfo.getSecureVipAddress();
} else {
// should not happen, but just in case.
continue;
}
if (null != vipAddress) {
String[] vipAddresses = vipAddress.split(",");
Arrays.sort(vipAddresses);
if (Arrays.binarySearch(vipAddresses, key.getName()) >= 0) {
if (null == appToAdd) {
appToAdd = new Application(application.getName());
toReturn.addApplication(appToAdd);
}
appToAdd.addInstance(instanceInfo);
}
}
}
}
toReturn.setAppsHashCode(toReturn.getReconcileHashCode());
args = new Object[] { key.getEntityType(), key.getName(), key.getVersion(), key.getType(), toReturn.getReconcileHashCode() };
logger.debug("Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}", args);
return toReturn;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class AbstractInstanceRegistry method getApplicationDeltasFromMultipleRegions.
/**
* Gets the application delta also including instances from the passed remote regions, with the instances from the
* local region. <br/>
*
* The remote regions from where the instances will be chosen can further be restricted if this application does not
* appear in the whitelist specified for the region as returned by
* {@link EurekaServerConfig#getRemoteRegionAppWhitelist(String)} for a region. In case, there is no whitelist
* defined for a region, this method will also look for a global whitelist by passing <code>null</code> to the
* method {@link EurekaServerConfig#getRemoteRegionAppWhitelist(String)} <br/>
*
* @param remoteRegions The remote regions for which the instances are to be queried. The instances may be limited
* by a whitelist as explained above. If <code>null</code> all remote regions are included.
* If empty list then no remote region is included.
*
* @return The delta with instances from the passed remote regions as well as local region. The instances
* from remote regions can be further be restricted as explained above. <code>null</code> if the application does
* not exist locally or in remote regions.
*/
public Applications getApplicationDeltasFromMultipleRegions(String[] remoteRegions) {
if (null == remoteRegions) {
// null means all remote regions.
remoteRegions = allKnownRemoteRegions;
}
boolean includeRemoteRegion = remoteRegions.length != 0;
if (includeRemoteRegion) {
GET_ALL_WITH_REMOTE_REGIONS_CACHE_MISS_DELTA.increment();
} else {
GET_ALL_CACHE_MISS_DELTA.increment();
}
Applications apps = new Applications();
apps.setVersion(responseCache.getVersionDeltaWithRegions().get());
Map<String, Application> applicationInstancesMap = new HashMap<String, Application>();
try {
write.lock();
Iterator<RecentlyChangedItem> iter = this.recentlyChangedQueue.iterator();
logger.debug("The number of elements in the delta queue is :" + this.recentlyChangedQueue.size());
while (iter.hasNext()) {
Lease<InstanceInfo> lease = iter.next().getLeaseInfo();
InstanceInfo instanceInfo = lease.getHolder();
Object[] args = { instanceInfo.getId(), instanceInfo.getStatus().name(), instanceInfo.getActionType().name() };
logger.debug("The instance id %s is found with status %s and actiontype %s", args);
Application app = applicationInstancesMap.get(instanceInfo.getAppName());
if (app == null) {
app = new Application(instanceInfo.getAppName());
applicationInstancesMap.put(instanceInfo.getAppName(), app);
apps.addApplication(app);
}
app.addInstance(decorateInstanceInfo(lease));
}
if (includeRemoteRegion) {
for (String remoteRegion : remoteRegions) {
RemoteRegionRegistry remoteRegistry = regionNameVSRemoteRegistry.get(remoteRegion);
if (null != remoteRegistry) {
Applications remoteAppsDelta = remoteRegistry.getApplicationDeltas();
if (null != remoteAppsDelta) {
for (Application application : remoteAppsDelta.getRegisteredApplications()) {
if (shouldFetchFromRemoteRegistry(application.getName(), remoteRegion)) {
Application appInstanceTillNow = apps.getRegisteredApplications(application.getName());
if (appInstanceTillNow == null) {
appInstanceTillNow = new Application(application.getName());
apps.addApplication(appInstanceTillNow);
}
for (InstanceInfo instanceInfo : application.getInstances()) {
appInstanceTillNow.addInstance(instanceInfo);
}
}
}
}
}
}
}
Applications allApps = getApplicationsFromMultipleRegions(remoteRegions);
apps.setAppsHashCode(allApps.getReconcileHashCode());
return apps;
} finally {
write.unlock();
}
}
Aggregations