Search in sources :

Example 16 with Application

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();
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 17 with Application

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);
    }
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 18 with Application

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);
}
Also used : Application(com.netflix.discovery.shared.Application)

Example 19 with Application

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;
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 20 with Application

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();
    }
}
Also used : Applications(com.netflix.discovery.shared.Applications) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(com.netflix.discovery.shared.Application)

Aggregations

Application (com.netflix.discovery.shared.Application)60 InstanceInfo (com.netflix.appinfo.InstanceInfo)35 Applications (com.netflix.discovery.shared.Applications)25 Test (org.junit.Test)18 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 HashMap (java.util.HashMap)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)2 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1