Search in sources :

Example 46 with Application

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

the class PeerAwareInstanceRegistryImpl method syncUp.

/**
     * Populates the registry information from a peer eureka node. This
     * operation fails over to other nodes until the list is exhausted if the
     * communication fails.
     */
@Override
public int syncUp() {
    // Copy entire entry from neighboring DS node
    int count = 0;
    for (int i = 0; ((i < serverConfig.getRegistrySyncRetries()) && (count == 0)); i++) {
        if (i > 0) {
            try {
                Thread.sleep(serverConfig.getRegistrySyncRetryWaitMs());
            } catch (InterruptedException e) {
                logger.warn("Interrupted during registry transfer..");
                break;
            }
        }
        Applications apps = eurekaClient.getApplications();
        for (Application app : apps.getRegisteredApplications()) {
            for (InstanceInfo instance : app.getInstances()) {
                try {
                    if (isRegisterable(instance)) {
                        register(instance, instance.getLeaseInfo().getDurationInSecs(), true);
                        count++;
                    }
                } catch (Throwable t) {
                    logger.error("During DS init copy", t);
                }
            }
        }
    }
    return count;
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 47 with Application

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

the class AwsAsgUtil method getASGAccount.

/**
     * Get the AWS account id where an ASG is created.
     * Warning: This is expensive as it loops through all instances currently registered.
     *
     * @param asgName The name of the ASG
     * @return the account id
     */
private String getASGAccount(String asgName) {
    Applications apps = registry.getApplicationsFromLocalRegionOnly();
    for (Application app : apps.getRegisteredApplications()) {
        for (InstanceInfo instanceInfo : app.getInstances()) {
            String thisAsgName = instanceInfo.getASGName();
            if (thisAsgName != null && thisAsgName.equals(asgName)) {
                String localAccountId = getAccountId(instanceInfo, null);
                if (localAccountId != null) {
                    return localAccountId;
                }
            }
        }
    }
    logger.info("Couldn't get the ASG account for {}, using the default accountId instead", asgName);
    return accountId;
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 48 with Application

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

the class AwsAsgUtil method getCacheKeys.

/**
     * Get the cacheKeys of all the ASG to which query AWS for.
     *
     * <p>
     * The names are obtained from the {@link com.netflix.eureka.registry.InstanceRegistry} which is then
     * used for querying the AWS.
     * </p>
     *
     * @return the set of ASG cacheKeys (asgName + accountId).
     */
private Set<CacheKey> getCacheKeys() {
    Set<CacheKey> cacheKeys = new HashSet<CacheKey>();
    Applications apps = registry.getApplicationsFromLocalRegionOnly();
    for (Application app : apps.getRegisteredApplications()) {
        for (InstanceInfo instanceInfo : app.getInstances()) {
            String localAccountId = getAccountId(instanceInfo, accountId);
            String asgName = instanceInfo.getASGName();
            if (asgName != null) {
                CacheKey key = new CacheKey(localAccountId, asgName);
                cacheKeys.add(key);
            }
        }
    }
    return cacheKeys;
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) HashSet(java.util.HashSet)

Example 49 with Application

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

the class AbstractTester method populateRemoteRegistryAtStartup.

private void populateRemoteRegistryAtStartup() {
    Application myapp = createRemoteApps();
    Application myappDelta = createRemoteAppsDelta();
    remoteRegionApps.put(REMOTE_REGION_APP_NAME, myapp);
    remoteRegionAppsDelta.put(REMOTE_REGION_APP_NAME, myappDelta);
}
Also used : Application(com.netflix.discovery.shared.Application)

Example 50 with Application

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

the class AbstractTester method createRemoteAppsDelta.

private static Application createRemoteAppsDelta() {
    Application myapp = new Application(REMOTE_REGION_APP_NAME);
    InstanceInfo instanceInfo = createRemoteInstance(REMOTE_REGION_INSTANCE_1_HOSTNAME);
    myapp.addInstance(instanceInfo);
    return myapp;
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

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