public static Applications updateMeta(Applications applications) { applications.setVersion(1L); applications.setAppsHashCode(applications.getReconcileHashCode()); return applications; }
public static Applications updateMeta(Applications applications) { applications.setVersion(1L); applications.setAppsHashCode(applications.getReconcileHashCode()); return applications; }
public Applications takeDeltaForDelete(boolean useInstanceId, int instanceCount) { List<InstanceInfo> instanceInfoList = new ArrayList<>(); for (int i = 0; i < instanceCount; i ++) { instanceInfoList.add(this.generateInstanceInfo(i, i, useInstanceId, ActionType.DELETED)); } Applications delete = EurekaEntityFunctions.toApplications(toApplicationMap(instanceInfoList)); allApplications = mergeApplications(allApplications, delete); delete.setAppsHashCode(allApplications.getAppsHashCode()); return delete; }
apps.setVersion(jp.getValueAsLong()); } else if (appHashCodeKey.equals(fieldName)){ apps.setAppsHashCode(jp.getValueAsString());
applications.setAppsHashCode(applications.getReconcileHashCode()); localRegionApps.set(applications); logTotalInstances();
public Applications takeDelta(int count) { if (currentIt == null) { currentIt = serviceIterator(); allApplications = new Applications(); } List<InstanceInfo> instanceBatch = new ArrayList<InstanceInfo>(); for (int i = 0; i < count; i++) { InstanceInfo next = currentIt.next(); next.setActionType(ActionType.ADDED); instanceBatch.add(next); } Applications nextBatch = EurekaEntityFunctions.toApplications(toApplicationMap(instanceBatch)); allApplications = mergeApplications(allApplications, nextBatch); nextBatch.setAppsHashCode(allApplications.getAppsHashCode()); return nextBatch; }
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; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Applications apps = new Applications(); while (reader.hasMoreChildren()) { reader.moveDown(); String nodeName = reader.getNodeName(); if (NODE_APP.equals(nodeName)) { apps.addApplication((Application) context.convertAnother( apps, Application.class)); } else if (VERSIONS_DELTA.equals(nodeName)) { apps.setVersion(Long.valueOf(reader.getValue())); } else if (APPS_HASHCODE.equals(nodeName)) { apps.setAppsHashCode(reader.getValue()); } reader.moveUp(); } return apps; } }
getAndUpdateDelta(applications); applications.setAppsHashCode(applications.getReconcileHashCode()); logTotalInstances(); } catch (Throwable e) {
apps.setAppsHashCode(apps.getReconcileHashCode()); return apps;
apps.setAppsHashCode(allApps.getReconcileHashCode()); return apps; } finally {
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 {
toReturn.setAppsHashCode(toReturn.getReconcileHashCode()); logger.debug( "Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}",
@Test public void testAppsHashCodeAfterRefresh() throws Exception { InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build(); // Full fetch with one item InstanceInfo first = instanceGen.first(); Applications initial = toApplications(first); when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build() ); EurekaClient client = discoveryClientResource.getClient(); assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_"))); // Delta with one add InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setStatus(InstanceStatus.DOWN).build(); Applications delta = toApplications(second); delta.setAppsHashCode("DOWN_1_UP_1_"); when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build() ); assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true)); assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_1_"))); }
/** * There is a bug, because of which remote registry data structures are not initialized during full registry fetch, only during delta. */ private void prepareRemoteRegionRegistry() throws Exception { Applications localApplications = InstanceInfoGenerator.newBuilder(4, "app1", "app2").build().toApplications(); Applications remoteApplications = InstanceInfoGenerator.newBuilder(4, "remote1", "remote2").withZone(TEST_REMOTE_ZONE).build().toApplications(); Applications allApplications = mergeApplications(localApplications, remoteApplications); // Load remote data in delta, to go around exiting bug in DiscoveryClient Applications delta = copyApplications(remoteApplications); delta.setAppsHashCode(allApplications.getAppsHashCode()); when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, localApplications).type(MediaType.APPLICATION_JSON_TYPE).build() ); when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build() ); assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true)); } }
@Test public void testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull() throws Exception { InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build(); // Full fetch with one item InstanceInfo first = instanceGen.first(); Applications initial = toApplications(first); when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build() ); EurekaClient client = discoveryClientResource.getClient(); assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_"))); // Delta with one add InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo1").setStatus(InstanceStatus.DOWN).setDataCenterInfo(null).build(); InstanceInfo third = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo2").setStatus(InstanceStatus.UP).setDataCenterInfo(new DataCenterInfo() { @Override public Name getName() { return null; } }).build(); Applications delta = toApplications(second, third); delta.setAppsHashCode("DOWN_1_UP_2_"); when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn( anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build() ); assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true)); assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_2_"))); }
@Test public void testVersionAndAppHash() { Applications apps = new Applications(); assertEquals(-1L, (long)apps.getVersion()); assertNull(apps.getAppsHashCode()); apps.setVersion(101L); apps.setAppsHashCode("UP_5_DOWN_6_"); assertEquals(101L, (long)apps.getVersion()); assertEquals("UP_5_DOWN_6_", apps.getAppsHashCode()); }