|
@@ -46,26 +46,37 @@ public class DefaultApplicationCleaner extends ApplicationCleaner {
|
|
|
LOG.info("Application cleaner run at time {}", now);
|
|
|
|
|
|
FederationStateStoreFacade facade = getGPGContext().getStateStoreFacade();
|
|
|
- Set<ApplicationId> candidates = new HashSet<ApplicationId>();
|
|
|
try {
|
|
|
+ // Get the candidate list from StateStore before calling router
|
|
|
+ Set<ApplicationId> allStateStoreApps = new HashSet<ApplicationId>();
|
|
|
List<ApplicationHomeSubCluster> response =
|
|
|
facade.getApplicationsHomeSubCluster();
|
|
|
for (ApplicationHomeSubCluster app : response) {
|
|
|
- candidates.add(app.getApplicationId());
|
|
|
+ allStateStoreApps.add(app.getApplicationId());
|
|
|
}
|
|
|
- LOG.info("{} app entries in FederationStateStore", candidates.size());
|
|
|
+ LOG.info("{} app entries in FederationStateStore",
|
|
|
+ allStateStoreApps.size());
|
|
|
|
|
|
+ // Get the candidate list from Registry before calling router
|
|
|
+ List<String> allRegistryApps = getRegistryClient().getAllApplications();
|
|
|
+ LOG.info("{} app entries in FederationRegistry",
|
|
|
+ allStateStoreApps.size());
|
|
|
+
|
|
|
+ // Get the list of known apps from Router
|
|
|
Set<ApplicationId> routerApps = getRouterKnownApplications();
|
|
|
LOG.info("{} known applications from Router", routerApps.size());
|
|
|
|
|
|
- candidates = Sets.difference(candidates, routerApps);
|
|
|
- LOG.info("Deleting {} applications from statestore", candidates.size());
|
|
|
+ // Clean up StateStore entries
|
|
|
+ Set<ApplicationId> toDelete =
|
|
|
+ Sets.difference(allStateStoreApps, routerApps);
|
|
|
+ LOG.info("Deleting {} applications from statestore", toDelete.size());
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
- LOG.debug("Apps to delete: ", candidates.stream().map(Object::toString)
|
|
|
+ LOG.debug("Apps to delete: ", toDelete.stream().map(Object::toString)
|
|
|
.collect(Collectors.joining(",")));
|
|
|
}
|
|
|
- for (ApplicationId appId : candidates) {
|
|
|
+ for (ApplicationId appId : toDelete) {
|
|
|
try {
|
|
|
+ LOG.debug("Deleting {} from statestore ", appId);
|
|
|
facade.deleteApplicationHomeSubCluster(appId);
|
|
|
} catch (Exception e) {
|
|
|
LOG.error(
|
|
@@ -74,8 +85,15 @@ public class DefaultApplicationCleaner extends ApplicationCleaner {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Clean up registry entries
|
|
|
- cleanupAppRecordInRegistry(routerApps);
|
|
|
+ // Clean up Registry entries
|
|
|
+ for (String app : allRegistryApps) {
|
|
|
+ ApplicationId appId = ApplicationId.fromString(app);
|
|
|
+ if (!routerApps.contains(appId)) {
|
|
|
+ LOG.debug("removing finished application entry for {}", app);
|
|
|
+ getRegistryClient().removeAppFromRegistry(appId, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Throwable e) {
|
|
|
LOG.error("Application cleaner started at time " + now + " fails: ", e);
|
|
|
}
|