/** * Gets the hash code for this <em>applications</em> instance. Used for * comparison of instances between eureka server and eureka client. * * @return the internal hash code representation indicating the information * about the instances. */ @JsonIgnore public String getReconcileHashCode() { TreeMap<String, AtomicInteger> instanceCountMap = new TreeMap<String, AtomicInteger>(); populateInstanceCountMap(instanceCountMap); return getReconcileHashCode(instanceCountMap); }
public static Applications updateMeta(Applications applications) { applications.setVersion(1L); applications.setAppsHashCode(applications.getReconcileHashCode()); return applications; }
private String getReconcileHashCode(Applications applications) { TreeMap<String, AtomicInteger> instanceCountMap = new TreeMap<String, AtomicInteger>(); if (isFetchingRemoteRegionRegistries()) { for (Applications remoteApp : remoteRegionVsApps.values()) { remoteApp.populateInstanceCountMap(instanceCountMap); } } applications.populateInstanceCountMap(instanceCountMap); return Applications.getReconcileHashCode(instanceCountMap); }
public static Applications updateMeta(Applications applications) { applications.setVersion(1L); applications.setAppsHashCode(applications.getReconcileHashCode()); return applications; }
/** * Reconciles the delta information fetched to see if the hashcodes match. * * @param delta - the delta information fetched previously for reconciliation. * @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()); long currentGeneration = fetchRegistryGeneration.get(); Applications apps = this.fetchRemoteRegistry(false); if (apps == null) { logger.error("The application is null for some reason. Not storing this information"); return false; } if (fetchRegistryGeneration.compareAndSet(currentGeneration, currentGeneration + 1)) { applications.set(apps); applicationsDelta.set(apps); logger.warn("The Reconcile hashcodes after complete sync up, client : {}, server : {}.", getApplications().getReconcileHashCode(), delta.getAppsHashCode()); return true; }else { logger.warn("Not setting the applications map as another thread has advanced the update generation"); return true; // still return true } }
try { updateDelta(delta); reconcileHashCode = getApplications().getReconcileHashCode(); } finally { fetchRegistryUpdateLock.unlock();
applications.setAppsHashCode(applications.getReconcileHashCode()); localRegionApps.set(applications); logTotalInstances();
public Applications toApplications() { Map<String, Application> appsByName = new HashMap<>(); Iterator<InstanceInfo> it = serviceIterator(); while (it.hasNext()) { InstanceInfo instanceInfo = it.next(); Application instanceApp = appsByName.get(instanceInfo.getAppName()); if (instanceApp == null) { instanceApp = new Application(instanceInfo.getAppName()); appsByName.put(instanceInfo.getAppName(), instanceApp); } instanceApp.addInstance(instanceInfo); } // Do not pass application list to the constructor, as it does not initialize properly Applications // data structure. Applications applications = new Applications(); for (Application app : appsByName.values()) { applications.addApplication(app); } applications.shuffleInstances(false); applications.setAppsHashCode(applications.getReconcileHashCode()); applications.setVersion(1L); return applications; }
logger.debug( "The Reconcile hashcodes after complete sync up, client : {}, server : {}.", getApplications().getReconcileHashCode(), delta.getAppsHashCode()); } else {
protected String getDeltaAppsHashCode(boolean includeRemote) { Applications allApps = new Applications(); for (Application application : applicationMap.values()) { allApps.addApplication(application); } if (includeRemote) { for (Application application : remoteRegionApps.values()) { allApps.addApplication(application); } } addDeltaApps(includeRemote, allApps); return allApps.getReconcileHashCode(); }
getAndUpdateDelta(applications); applications.setAppsHashCode(applications.getReconcileHashCode()); logTotalInstances(); } catch (Throwable e) {
apps.setAppsHashCode(apps.getReconcileHashCode()); return apps;
apps.setAppsHashCode(allApps.getReconcileHashCode()); return apps; } finally {
toReturn.setAppsHashCode(toReturn.getReconcileHashCode()); logger.debug( "Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), toReturn.getReconcileHashCode()); return toReturn;
apps.setAppsHashCode(apps.getReconcileHashCode()); return apps;
public CodecLoadTester(int instanceCount, int appCount) { Iterator<InstanceInfo> instanceIt = InstanceInfoGenerator.newBuilder(instanceCount, appCount) .withMetaData(true).build().serviceIterator(); applications = new Applications(); int appIdx = 0; while (instanceIt.hasNext()) { InstanceInfo next = instanceIt.next(); instanceInfoList.add(next); if (applicationList.size() <= appIdx) { applicationList.add(new Application(next.getAppName())); } applicationList.get(appIdx).addInstance(next); appIdx = (appIdx + 1) % appCount; } for (Application app : applicationList) { applications.addApplication(app); } applications.setAppsHashCode(applications.getReconcileHashCode()); firstHolder.value = applications; }
apps.addApplication(application); apps.setAppsHashCode(apps.getReconcileHashCode()); sendOkResponseWithContent((Request) request, response, toJson(apps)); handled = true; apps.addApplication(application); apps.setAppsHashCode(apps.getReconcileHashCode()); sendOkResponseWithContent((Request) request, response, toJson(apps)); handled = true;
apps.setAppsHashCode(allApps.getReconcileHashCode()); return apps; } finally {
System.out.println("Eureka port: " + port + ". " + System.currentTimeMillis() + ". Not including delta apps in /apps response, as delta has not been sent."); apps.setAppsHashCode(apps.getReconcileHashCode()); sendOkResponseWithContent((Request) request, response, apps); sentRegistry.set(true); apps.setAppsHashCode(apps.getReconcileHashCode()); sendOkResponseWithContent((Request) request, response, apps); handled = true;
@Test public void testReconcileHashcode() { DataCenterInfo myDCI = new DataCenterInfo() { public DataCenterInfo.Name getName() { return DataCenterInfo.Name.MyOwn; } }; InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder() .setAppName("test") .setVIPAddress("test.testname:1") .setSecureVIPAddress("securetest.testname:7102") .setDataCenterInfo(myDCI) .setHostName("test.hostname") .setStatus(InstanceStatus.UP) .build(); Application application = new Application("TestApp"); application.addInstance(instanceInfo); Applications applications = new Applications(); String hashCode = applications.getReconcileHashCode(); assertTrue(hashCode.isEmpty()); applications.addApplication(application); hashCode = applications.getReconcileHashCode(); assertFalse(hashCode.isEmpty()); assertEquals("UP_1_", hashCode); }