Collection<Task<?>> tasks = executionManager.allTasksLive(); List<Task<?>> tasksToConsiderDeleting = MutableList.of(); try {
protected int expireSubTasksWhoseSubmitterIsExpired() { // ideally we wouldn't have this; see comments on CHECK_SUBTASK_SUBMITTERS if (!brooklynProperties.getConfig(CHECK_SUBTASK_SUBMITTERS)) return 0; Collection<Task<?>> allTasks = executionManager.allTasksLive(); Collection<Task<?>> tasksToDelete = MutableList.of(); try { for (Task<?> task: allTasks) { if (!task.isDone()) continue; Task<?> submitter = task.getSubmittedByTask(); // if we've leaked, ie a subtask which is not a child task, // and the submitter is GC'd, then delete this also if (submitter!=null && submitter.isDone() && executionManager.getTask(submitter.getId())==null) { tasksToDelete.add(task); } } } catch (ConcurrentModificationException e) { // delete what we've found so far LOG.debug("Got CME inspecting aged tasks, with "+tasksToDelete.size()+" found for deletion: "+e); } for (Task<?> task: tasksToDelete) { executionManager.deleteTask(task); } return tasksToDelete.size(); }
protected int expireIfOverCapacityGlobally() { Collection<Task<?>> tasksLive = executionManager.allTasksLive(); if (tasksLive.size() <= brooklynProperties.getConfig(MAX_TASKS_GLOBAL)) return 0; LOG.debug("brooklyn-gc deleted "+numDeleted+" tasks as was over global limit, now have "+executionManager.allTasksLive().size()); return numDeleted;
protected void expireAgedTasks() { Duration maxTaskAge = brooklynProperties.getConfig(MAX_TASK_AGE); Collection<Task<?>> allTasks = executionManager.allTasksLive(); Collection<Task<?>> tasksToDelete = MutableList.of(); try { for (Task<?> task: allTasks) { if (!task.isDone()) continue; if (BrooklynTaskTags.isSubTask(task)) continue; if (maxTaskAge.isShorterThan(Duration.sinceUtc(task.getEndTimeUtc()))) tasksToDelete.add(task); } } catch (ConcurrentModificationException e) { // delete what we've found so far LOG.debug("Got CME inspecting aged tasks, with "+tasksToDelete.size()+" found for deletion: "+e); } for (Task<?> task: tasksToDelete) { executionManager.deleteTask(task); } }