use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class AbstractInstanceRegistry method getApplications.
/**
* Get the registry information about all {@link Applications}.
*
* @param includeRemoteRegion true, if we need to include applications from remote regions
* as indicated by the region {@link URL} by this property
* {@link EurekaServerConfig#getRemoteRegionUrls()}, false otherwise
* @return applications
*
* @deprecated Use {@link #getApplicationsFromMultipleRegions(String[])} instead. This method has a flawed behavior
* of transparently falling back to a remote region if no instances for an app is available locally. The new
* behavior is to explicitly specify if you need a remote region.
*/
@Deprecated
public Applications getApplications(boolean includeRemoteRegion) {
GET_ALL_CACHE_MISS.increment();
Applications apps = new Applications();
apps.setVersion(1L);
for (Entry<String, Map<String, Lease<InstanceInfo>>> entry : registry.entrySet()) {
Application app = null;
if (entry.getValue() != null) {
for (Entry<String, Lease<InstanceInfo>> stringLeaseEntry : entry.getValue().entrySet()) {
Lease<InstanceInfo> lease = stringLeaseEntry.getValue();
if (app == null) {
app = new Application(lease.getHolder().getAppName());
}
app.addInstance(decorateInstanceInfo(lease));
}
}
if (app != null) {
apps.addApplication(app);
}
}
if (includeRemoteRegion) {
for (RemoteRegionRegistry remoteRegistry : this.regionNameVSRemoteRegistry.values()) {
Applications applications = remoteRegistry.getApplications();
for (Application application : applications.getRegisteredApplications()) {
Application appInLocalRegistry = apps.getRegisteredApplications(application.getName());
if (appInLocalRegistry == null) {
apps.addApplication(application);
}
}
}
}
apps.setAppsHashCode(apps.getReconcileHashCode());
return apps;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class AbstractInstanceRegistry method getApplicationDeltas.
/**
* Get the registry information about the delta changes. The deltas are
* cached for a window specified by
* {@link EurekaServerConfig#getRetentionTimeInMSInDeltaQueue()}. Subsequent
* requests for delta information may return the same information and client
* must make sure this does not adversely affect them.
*
* @return all application deltas.
* @deprecated use {@link #getApplicationDeltasFromMultipleRegions(String[])} instead. This method has a
* flawed behavior of transparently falling back to a remote region if no instances for an app is available locally.
* The new behavior is to explicitly specify if you need a remote region.
*/
@Deprecated
public Applications getApplicationDeltas() {
GET_ALL_CACHE_MISS_DELTA.increment();
Applications apps = new Applications();
apps.setVersion(responseCache.getVersionDelta().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));
}
boolean disableTransparentFallback = serverConfig.disableTransparentFallbackToOtherRegion();
if (!disableTransparentFallback) {
Applications allAppsInLocalRegion = getApplications(false);
for (RemoteRegionRegistry remoteRegistry : this.regionNameVSRemoteRegistry.values()) {
Applications applications = remoteRegistry.getApplicationDeltas();
for (Application application : applications.getRegisteredApplications()) {
Application appInLocalRegistry = allAppsInLocalRegion.getRegisteredApplications(application.getName());
if (appInLocalRegistry == null) {
apps.addApplication(application);
}
}
}
}
Applications allApps = getApplications(!disableTransparentFallback);
apps.setAppsHashCode(allApps.getReconcileHashCode());
return apps;
} finally {
write.unlock();
}
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class AbstractInstanceRegistry method getApplication.
/**
* Get application information.
*
* @param appName The name of the application
* @param includeRemoteRegion true, if we need to include applications from remote regions
* as indicated by the region {@link URL} by this property
* {@link EurekaServerConfig#getRemoteRegionUrls()}, false otherwise
* @return the application
*/
@Override
public Application getApplication(String appName, boolean includeRemoteRegion) {
Application app = null;
Map<String, Lease<InstanceInfo>> leaseMap = registry.get(appName);
if (leaseMap != null && leaseMap.size() > 0) {
for (Entry<String, Lease<InstanceInfo>> entry : leaseMap.entrySet()) {
if (app == null) {
app = new Application(appName);
}
app.addInstance(decorateInstanceInfo(entry.getValue()));
}
} else if (includeRemoteRegion) {
for (RemoteRegionRegistry remoteRegistry : this.regionNameVSRemoteRegistry.values()) {
Application application = remoteRegistry.getApplication(appName);
if (application != null) {
return application;
}
}
}
return app;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class AbstractInstanceRegistry method getInstancesById.
/**
* @deprecated Try {@link #getInstanceByAppAndId(String, String, boolean)} instead.
*
* Get the list of instances by its unique id.
*
* @param id the unique id of the instance
* @param includeRemoteRegions true, if we need to include applications from remote regions
* as indicated by the region {@link URL} by this property
* {@link EurekaServerConfig#getRemoteRegionUrls()}, false otherwise
* @return list of InstanceInfo objects.
*/
@Deprecated
public List<InstanceInfo> getInstancesById(String id, boolean includeRemoteRegions) {
List<InstanceInfo> list = new ArrayList<InstanceInfo>();
for (Iterator<Entry<String, Map<String, Lease<InstanceInfo>>>> iter = registry.entrySet().iterator(); iter.hasNext(); ) {
Map<String, Lease<InstanceInfo>> leaseMap = iter.next().getValue();
if (leaseMap != null) {
Lease<InstanceInfo> lease = leaseMap.get(id);
if (lease == null || (isLeaseExpirationEnabled() && lease.isExpired())) {
continue;
}
if (list == Collections.EMPTY_LIST) {
list = new ArrayList<InstanceInfo>();
}
list.add(decorateInstanceInfo(lease));
}
}
if (list.isEmpty() && includeRemoteRegions) {
for (RemoteRegionRegistry remoteRegistry : this.regionNameVSRemoteRegistry.values()) {
for (Application application : remoteRegistry.getApplications().getRegisteredApplications()) {
InstanceInfo instanceInfo = application.getByInstanceId(id);
if (instanceInfo != null) {
list.add(instanceInfo);
return list;
}
}
}
}
return list;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method primeAwsReplicas.
/**
* Prime connections for Aws replicas.
* <p>
* Sometimes when the eureka servers comes up, AWS firewall may not allow
* the network connections immediately. This will cause the outbound
* connections to fail, but the inbound connections continue to work. What
* this means is the clients would have switched to this node (after EIP
* binding) and so the other eureka nodes will expire all instances that
* have been switched because of the lack of outgoing heartbeats from this
* instance.
* </p>
* <p>
* The best protection in this scenario is to block and wait until we are
* able to ping all eureka nodes successfully atleast once. Until then we
* won't open up the traffic.
* </p>
*/
private void primeAwsReplicas(ApplicationInfoManager applicationInfoManager) {
boolean areAllPeerNodesPrimed = false;
while (!areAllPeerNodesPrimed) {
String peerHostName = null;
try {
Application eurekaApps = this.getApplication(applicationInfoManager.getInfo().getAppName(), false);
if (eurekaApps == null) {
areAllPeerNodesPrimed = true;
logger.info("No peers needed to prime.");
return;
}
for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
for (InstanceInfo peerInstanceInfo : eurekaApps.getInstances()) {
LeaseInfo leaseInfo = peerInstanceInfo.getLeaseInfo();
// If the lease is expired - do not worry about priming
if (System.currentTimeMillis() > (leaseInfo.getRenewalTimestamp() + (leaseInfo.getDurationInSecs() * 1000)) + (2 * 60 * 1000)) {
continue;
}
peerHostName = peerInstanceInfo.getHostName();
logger.info("Trying to send heartbeat for the eureka server at {} to make sure the " + "network channels are open", peerHostName);
// the other instances may be legitimately down
if (peerHostName.equalsIgnoreCase(new URI(node.getServiceUrl()).getHost())) {
node.heartbeat(peerInstanceInfo.getAppName(), peerInstanceInfo.getId(), peerInstanceInfo, null, true);
}
}
}
areAllPeerNodesPrimed = true;
} catch (Throwable e) {
logger.error("Could not contact " + peerHostName, e);
try {
Thread.sleep(PRIME_PEER_NODES_RETRY_MS);
} catch (InterruptedException e1) {
logger.warn("Interrupted while priming : ", e1);
areAllPeerNodesPrimed = true;
}
}
}
}
Aggregations