use of com.netflix.discovery.shared.Applications 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;
}
use of com.netflix.discovery.shared.Applications 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;
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpClientsTest method testCanonicalClient.
@Test
public void testCanonicalClient() throws Exception {
Applications apps = instanceGen.toApplications();
when(writeRequestHandler.getApplications()).thenReturn(anEurekaHttpResponse(302, Applications.class).headers("Location", readServerURI + "/v2/apps").build());
when(readRequestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, apps).headers(HttpHeaders.CONTENT_TYPE, "application/json").build());
EurekaHttpClient eurekaHttpClient = clientFactory.newClient();
EurekaHttpResponse<Applications> result = eurekaHttpClient.getApplications();
assertThat(result.getStatusCode(), is(equalTo(200)));
assertThat(EurekaEntityComparators.equal(result.getEntity(), apps), is(true));
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpClientsTest method testCompositeBootstrapResolver.
@Test
public void testCompositeBootstrapResolver() throws Exception {
Applications applications = InstanceInfoGenerator.newBuilder(5, "eurekaWrite", "someOther").build().toApplications();
Applications applications2 = InstanceInfoGenerator.newBuilder(2, "eurekaWrite", "someOther").build().toApplications();
String vipAddress = applications.getRegisteredApplications("eurekaWrite").getInstances().get(0).getVIPAddress();
// setup client config to use fixed root ips for testing
when(clientConfig.shouldUseDnsForFetchingServiceUrls()).thenReturn(false);
// can use anything here
when(clientConfig.getEurekaServerServiceUrls(anyString())).thenReturn(Arrays.asList("http://foo:0"));
when(clientConfig.getRegion()).thenReturn("us-east-1");
when(transportConfig.getWriteClusterVip()).thenReturn(vipAddress);
when(transportConfig.getAsyncExecutorThreadPoolSize()).thenReturn(4);
when(transportConfig.getAsyncResolverRefreshIntervalMs()).thenReturn(400);
when(transportConfig.getAsyncResolverWarmUpTimeoutMs()).thenReturn(400);
ApplicationsResolver.ApplicationsSource applicationsSource = mock(ApplicationsResolver.ApplicationsSource.class);
when(applicationsSource.getApplications(anyInt(), eq(TimeUnit.SECONDS))).thenReturn(// first time
null).thenReturn(// second time
applications).thenReturn(// subsequent times
null);
EurekaHttpClient mockHttpClient = mock(EurekaHttpClient.class);
when(mockHttpClient.getVip(eq(vipAddress))).thenReturn(anEurekaHttpResponse(200, applications).build()).thenReturn(// contains diff number of servers
anEurekaHttpResponse(200, applications2).build());
TransportClientFactory transportClientFactory = mock(TransportClientFactory.class);
when(transportClientFactory.newClient(any(EurekaEndpoint.class))).thenReturn(mockHttpClient);
ClosableResolver<AwsEndpoint> resolver = null;
try {
resolver = EurekaHttpClients.compositeBootstrapResolver(clientConfig, transportConfig, transportClientFactory, applicationInfoManager.getInfo(), applicationsSource);
List endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
// wait for the second cycle that hits the app source
verify(applicationsSource, timeout(3000).times(2)).getApplications(anyInt(), eq(TimeUnit.SECONDS));
endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
// wait for the third cycle that triggers the mock http client (which is the third resolver cycle)
// for the third cycle we have mocked the application resolver to return null data so should fall back
// to calling the remote resolver again (which should return applications2)
verify(mockHttpClient, timeout(3000).times(3)).getVip(anyString());
endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications2.getInstancesByVirtualHostName(vipAddress).size()));
} finally {
if (resolver != null) {
resolver.shutdown();
}
}
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class RemoteRegionRegistry method reconcileAndLogDifference.
/**
* Reconciles the delta information fetched to see if the hashcodes match.
*
* @param delta - the delta information fetched previously for reconcililation.
* @param reconcileHashCode - the hashcode for comparison.
* @return - response
* @throws Throwable
*/
private boolean reconcileAndLogDifference(Applications delta, String reconcileHashCode) throws Throwable {
logger.warn("The Reconcile hashcodes do not match, client : {}, server : {}. Getting the full registry", reconcileHashCode, delta.getAppsHashCode());
Applications serverApps = this.fetchRemoteRegistry(false);
Map<String, List<String>> reconcileDiffMap = getApplications().getReconcileMapDiff(serverApps);
String reconcileString = "";
for (Map.Entry<String, List<String>> mapEntry : reconcileDiffMap.entrySet()) {
reconcileString = reconcileString + mapEntry.getKey() + ": ";
for (String displayString : mapEntry.getValue()) {
reconcileString = reconcileString + displayString;
}
reconcileString = reconcileString + "\n";
}
logger.warn("The reconcile string is {}", reconcileString);
applications.set(serverApps);
applicationsDelta.set(serverApps);
logger.warn("The Reconcile hashcodes after complete sync up, client : {}, server : {}.", getApplications().getReconcileHashCode(), delta.getAppsHashCode());
return true;
}
Aggregations