private boolean hasTaskAsAncestor(Task<?> t, Task<?> potentialAncestor) { if (t==null || potentialAncestor==null) return false; if (t.equals(potentialAncestor)) return true; return hasTaskAsAncestor(t.getSubmittedByTask(), potentialAncestor); }
/** finds the first {@link EffectorCallTag} tag on this tag, or optionally on submitters, or null */ public static EffectorCallTag getEffectorCallTag(Task<?> task, boolean recurse) { Task<?> t = task; while (t!=null) { for (Object tag: t.getTags()) { if (tag instanceof EffectorCallTag) return (EffectorCallTag)tag; } if (!recurse) return null; t = t.getSubmittedByTask(); } return null; }
public static boolean isTransient(Task<?> task) { if (hasTag(task, TRANSIENT_TASK_TAG)) return true; if (hasTag(task, NON_TRANSIENT_TASK_TAG)) return false; if (task.getSubmittedByTask()!=null) return isTransient(task.getSubmittedByTask()); return false; } public static boolean isSubTask(Task<?> task) { return hasTag(task, SUB_TASK_TAG); }
/** returns the first tag found on the given task which matches the given type, looking up the submission hierarachy if necessary */ @SuppressWarnings("unchecked") public static <T> T tag(@Nullable Task<?> task, Class<T> type, boolean recurseHierarchy) { // support null task to make it easier for callers to walk hierarchies if (task==null) return null; for (Object tag: task.getTags()) if (type.isInstance(tag)) return (T)tag; if (!recurseHierarchy) return null; return tag(task.getSubmittedByTask(), type, true); }
public static boolean isAncestorCancelled(Task<?> t) { if (t==null) return false; if (t.isCancelled()) return true; return isAncestorCancelled(t.getSubmittedByTask()); }
private Task<?> getTopEntityTask(Task<?> stopEffectorTask) { Entity context = BrooklynTaskTags.getContextEntity(stopEffectorTask); Task<?> topTask = stopEffectorTask; while (true) { Task<?> parentTask = topTask.getSubmittedByTask(); Entity parentContext = BrooklynTaskTags.getContextEntity(parentTask); if (parentTask == null || parentContext != context) { return topTask; } else { topTask = parentTask; } } }
/** * Finds the currently applicable {@link EntitlementContext} by examining the current thread * then by investigating the current task, its submitter, etc. */ // NOTE: entitlements are propagated to tasks whenever they are created, as tags // (see BrooklynTaskTags.tagForEntitlement and BasicExecutionContext.submitInternal). // It might be cheaper to only do this lookup, not to propagate as tags, and to ensure // all entitlement operations are wrapped in a task at source; but currently we do not // do that so we need at least to set entitlement on the outermost task. // Setting it on tasks submitted by a task is not strictly necessary (i.e. in BasicExecutionContext) // but seems cheap enough, and means checking entitlements is fast, if we choose to do that more often. public static EntitlementContext getEntitlementContext() { EntitlementContext context; context = PerThreadEntitlementContextHolder.perThreadEntitlementsContextHolder.get(); if (context!=null) return context; Task<?> task = Tasks.current(); while (task!=null) { context = BrooklynTaskTags.getEntitlement(task); if (context!=null) return context; task = task.getSubmittedByTask(); } // no entitlements set -- assume entitlements not used, or system internal return null; }
/** * finds the task up the {@code child} hierarchy handling the {@code effector} call, * returns null if one doesn't exist. */ @Beta public static Task<?> getClosestEffectorTask(Task<?> child, Effector<?> effector) { Task<?> t = child; while (t != null) { Set<Object> tags = t.getTags(); if (tags.contains(EFFECTOR_TAG)) { for (Object tag: tags) { if (tag instanceof EffectorCallTag) { EffectorCallTag et = (EffectorCallTag) tag; if (effector != null && !et.getEffectorName().equals(effector.getName())) continue; return t; } } } t = t.getSubmittedByTask(); } return null; }
/** * checks if the given task is part of the given effector call on the given entity; * @param task the task to check (false if null) * @param entity the entity where this effector task should be running, or any entity if null * @param effector the effector (matching name) where this task should be running, or any effector if null * @param allowNestedEffectorCalls whether to match ancestor effector calls, e.g. if eff1 calls eff2, * and we are checking eff2, whether to match eff1 * @return whether the given task is part of the given effector */ public static boolean isInEffectorTask(Task<?> task, @Nullable Entity entity, @Nullable Effector<?> effector, boolean allowNestedEffectorCalls) { Task<?> t = task; while (t!=null) { Set<Object> tags = t.getTags(); if (tags.contains(EFFECTOR_TAG)) { for (Object tag: tags) { if (tag instanceof EffectorCallTag) { EffectorCallTag et = (EffectorCallTag)tag; if (entity!=null && !et.getEntityId().equals(entity.getId())) continue; if (effector!=null && !et.getEffectorName().equals(effector.getName())) continue; return true; } } if (!allowNestedEffectorCalls) return false; } t = t.getSubmittedByTask(); } return false; }
private Collection<? extends TaskSummary> getBackgroundedChildren(Task<?> t) { Entity entity = BrooklynTaskTags.getContextEntity(t); List<TaskSummary> result = MutableList.of(); if (entity!=null) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), entity); for (Task<?> ti: tasks) { if (t.equals(ti.getSubmittedByTask())) { result.add(TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(ti)); } } } return result; }
return false; if (task.getSubmittedByTask()!=null) { Task<?> parent = task.getSubmittedByTask(); if (executionManager.getTask(parent.getId())==null) {
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(); }
if (task.equals(t.getSubmittedByTask())) { if (mode.isAllowedToInterruptAllSubmittedTasks() || BrooklynTaskTags.isTransient(t)) { if (log.isTraceEnabled()) {
Task<?> o1s = o1.getSubmittedByTask(); Task<?> o2s = o2.getSubmittedByTask(); if ("start".equals(o1.getDisplayName()) ||"start".equals(o2.getDisplayName())) { weight = 0;
task.getTags(), ifPositive(task.getSubmitTimeUtc()), ifPositive(task.getStartTimeUtc()), ifPositive(task.getEndTimeUtc()), task.getStatusSummary(), result, task.isError(), task.isCancelled(), children, asLink(task.getSubmittedByTask(), ub), task.isDone() ? null : task instanceof TaskInternal ? asLink(((TaskInternal<?>)task).getBlockingTask(), ub) : null, task.isDone() ? null : task instanceof TaskInternal ? ((TaskInternal<?>)task).getBlockingDetails() : null,