Search in sources :

Example 61 with Application

use of com.netflix.discovery.shared.Application in project spring-cloud-netflix by spring-cloud.

the class InstanceRegistry method renew.

@Override
public boolean renew(final String appName, final String serverId, boolean isReplication) {
    log("renew " + appName + " serverId " + serverId + ", isReplication {}" + isReplication);
    List<Application> applications = getSortedApplications();
    for (Application input : applications) {
        if (input.getName().equals(appName)) {
            InstanceInfo instance = null;
            for (InstanceInfo info : input.getInstances()) {
                if (info.getId().equals(serverId)) {
                    instance = info;
                    break;
                }
            }
            publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instance, isReplication));
            break;
        }
    }
    return super.renew(appName, serverId, isReplication);
}
Also used : EurekaInstanceRenewedEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 62 with Application

use of com.netflix.discovery.shared.Application in project spring-cloud-netflix by spring-cloud.

the class EurekaHealthIndicator method getApplications.

private Map<String, Object> getApplications() {
    Applications applications = this.eurekaClient.getApplications();
    if (applications == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> result = new HashMap<>();
    for (Application application : applications.getRegisteredApplications()) {
        result.put(application.getName(), application.getInstances().size());
    }
    return result;
}
Also used : Applications(com.netflix.discovery.shared.Applications) HashMap(java.util.HashMap) Application(com.netflix.discovery.shared.Application)

Example 63 with Application

use of com.netflix.discovery.shared.Application in project spring-cloud-netflix by spring-cloud.

the class EurekaInstanceDiscovery method getInstancesForApp.

/**
 * Private helper that fetches the Instances for each application.
 * @param serviceId
 * @return List<Instance>
 * @throws Exception
 */
@Override
protected List<Instance> getInstancesForApp(String serviceId) throws Exception {
    List<Instance> instances = new ArrayList<>();
    log.info("Fetching instances for app: " + serviceId);
    Application app = eurekaClient.getApplication(serviceId);
    if (app == null) {
        log.warn("Eureka returned null for app: " + serviceId);
        return instances;
    }
    try {
        List<InstanceInfo> instancesForApp = app.getInstances();
        if (instancesForApp != null) {
            log.info("Received instance list for app: " + serviceId + ", size=" + instancesForApp.size());
            for (InstanceInfo iInfo : instancesForApp) {
                Instance instance = marshall(iInfo);
                if (instance != null) {
                    instances.add(instance);
                }
            }
        }
    } catch (Exception e) {
        log.warn("Failed to retrieve instances from Eureka", e);
    }
    return instances;
}
Also used : Instance(com.netflix.turbine.discovery.Instance) ArrayList(java.util.ArrayList) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 64 with Application

use of com.netflix.discovery.shared.Application in project spring-cloud-netflix by spring-cloud.

the class EurekaBasedTurbineClustersProviderTest method application.

private Application application(String name) {
    Application application = mock(Application.class);
    when(application.getName()).thenReturn(name);
    return application;
}
Also used : Application(com.netflix.discovery.shared.Application)

Example 65 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class BackUpRegistryTest method setupBackupMock.

private void setupBackupMock() {
    Application localApp = createLocalApps();
    Applications localApps = new Applications();
    localApps.addApplication(localApp);
    backupRegistry.setLocalRegionApps(localApps);
    Application remoteApp = createRemoteApps();
    Applications remoteApps = new Applications();
    remoteApps.addApplication(remoteApp);
    backupRegistry.getRemoteRegionVsApps().put(REMOTE_REGION, remoteApps);
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application)

Aggregations

Application (com.netflix.discovery.shared.Application)104 InstanceInfo (com.netflix.appinfo.InstanceInfo)51 Test (org.junit.Test)43 Applications (com.netflix.discovery.shared.Applications)41 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Map (java.util.Map)6 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)4 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)2 Pair (com.netflix.discovery.shared.Pair)2