Source:
private void cleanUpOrphanTasks(Map<Guid, Set<Guid>> runningTasksInClusterMap) { if (runningTasksInClusterMap.isEmpty()) { log.debug("Clean up of tasks has been skipped"); return; } List<Guid> taskListInDB = getProvider().getMonitoredTaskIDsInDB(); if (taskListInDB == null || taskListInDB.isEmpty()) { return; } Set<Guid> allRunningTasksInCluster = new HashSet<>(); for (Set<Guid> taskSet: runningTasksInClusterMap.values()) { if (taskSet != null) { allRunningTasksInCluster.addAll(taskSet); } } final Set<Guid> tasksNotRunning = new HashSet<Guid>(taskListInDB); tasksNotRunning.removeAll(allRunningTasksInCluster); log.debugFormat("tasks to be cleaned up in db {0}", tasksNotRunning); for (Guid taskId: tasksNotRunning) { GlusterVolumeEntity vol= getVolumeDao().getVolumeByGlusterTask(taskId); if (vol != null && vol.getStatus() != GlusterStatus.UP && !runningTasksInClusterMap.keySet().contains((vol.getClusterId()))) { continue; } List<Step> steps = getStepDao().getStepsByExternalId(taskId); for (Step step: steps) { step.markStepEnded(JobExecutionStatus.UNKNOWN); step.setStatus(JobExecutionStatus.UNKNOWN); Map<String, String> values = new HashMap<String, String>(); values.put(GlusterConstants.CLUSTER, vol == null ? "" :vol.getVdsGroupName()); values.put(GlusterConstants.VOLUME, vol == null ? "" : vol.getName()); values.put(GlusterConstants.JOB_STATUS, JobExecutionStatus.UNKNOWN.toString()); values.put(GlusterConstants.JOB_INFO, " "); step.setDescription(ExecutionMessageDirector.resolveStepMessage(step.getStepType(), values)); getGlusterTaskUtils().endStepJob(step); if (vol != null) { logTaskStoppedFromCLI(step, vol); } } getGlusterTaskUtils().releaseVolumeLock(taskId); } }

Target:
private void cleanUpOrphanTasks(Map<Guid, Set<Guid>> runningTasksInClusterMap) { if (runningTasksInClusterMap.isEmpty()) { log.debug("Clean up of tasks has been skipped"); return; } List<Guid> taskListInDB = getProvider().getMonitoredTaskIDsInDB(); if (taskListInDB == null || taskListInDB.isEmpty()) { return; } Set<Guid> allRunningTasksInCluster = new HashSet<>(); for (Set<Guid> taskSet: runningTasksInClusterMap.values()) { if (taskSet != null) { allRunningTasksInCluster.addAll(taskSet); } } final Set<Guid> tasksNotRunning = new HashSet<Guid>(taskListInDB); tasksNotRunning.removeAll(allRunningTasksInCluster); log.debugFormat("tasks to be cleaned up in db {0}", tasksNotRunning); for (Guid taskId: tasksNotRunning) { GlusterVolumeEntity vol= getVolumeDao().getVolumeByGlusterTask(taskId); if (vol != null && vol.getStatus() != GlusterStatus.UP && !runningTasksInClusterMap.keySet().contains((vol.getClusterId()))) { continue; } List<Step> steps = getStepDao().getStepsByExternalId(taskId); Map<String, String> values = new HashMap<String, String>(); values.put(GlusterConstants.CLUSTER, vol == null ? "" :vol.getVdsGroupName()); values.put(GlusterConstants.VOLUME, vol == null ? "" : vol.getName()); values.put(GlusterConstants.JOB_STATUS, JobExecutionStatus.UNKNOWN.toString()); values.put(GlusterConstants.JOB_INFO, " "); for (Step step: steps) { step.markStepEnded(JobExecutionStatus.UNKNOWN); step.setStatus(JobExecutionStatus.UNKNOWN); step.setDescription(ExecutionMessageDirector.resolveStepMessage(step.getStepType(), values)); getGlusterTaskUtils().endStepJob(step); if (vol != null) { logTaskStoppedFromCLI(step, vol); } } getGlusterTaskUtils().releaseVolumeLock(taskId); } }