/** return all children tasks of the given tasks, if it has children, else empty list */ public static Iterable<Task<?>> children(Task<?> task) { if (task instanceof HasTaskChildren) return ((HasTaskChildren)task).getChildren(); return Collections.emptyList(); }
private List<TaskSummary> getSubTaskChildren(Task<?> t) { if (!(t instanceof HasTaskChildren)) { return Collections.emptyList(); } return new LinkedList<TaskSummary>(Collections2.transform(Lists.newArrayList(((HasTaskChildren) t).getChildren()), TaskTransformer.fromTask(ui.getBaseUriBuilder()))); }
public static void dumpInfo(Task<?> t, Writer out, String currentIndentation, String tab) throws IOException { out.append(currentIndentation+t+": "+t.getStatusDetail(false)+"\n"); if (t instanceof HasTaskChildren) { for (Task<?> child: ((HasTaskChildren)t).getChildren()) { dumpInfo(child, out, currentIndentation+tab, tab); } } out.flush(); } }
public void deleteTask(Task<?> task) { boolean removed = deleteTaskNonRecursive(task); if (!removed) return; if (task instanceof HasTaskChildren) { List<Task<?>> children = ImmutableList.copyOf(((HasTaskChildren)task).getChildren()); for (Task<?> child : children) { deleteTask(child); } } }
private LinkedHashMap<String, TaskSummary> getAllDescendantTasks(final Task<?> parentTask, int limit, int maxDepth) { final LinkedHashMap<String, TaskSummary> result = Maps.newLinkedHashMap(); if (!(parentTask instanceof HasTaskChildren)) { return result; } Set<Task<?>> nextLayer = MutableSet.copyOf( ((HasTaskChildren) parentTask).getChildren() ); outer: while (limit!=0 && !nextLayer.isEmpty() && maxDepth-- != 0) { Set<Task<?>> thisLayer = nextLayer; nextLayer = MutableSet.of(); for (final Task<?> childTask : thisLayer) { TaskSummary wasThere = result.put(childTask.getId(), TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(childTask)); if (wasThere==null) { if (--limit == 0) { break outer; } if (childTask instanceof HasTaskChildren) { Iterables.addAll(nextLayer, ((HasTaskChildren)childTask).getChildren()); } } } } return result; }
protected Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>> tasks, Predicate<? super Task<?>> matcher, List<String> taskNames) { for (Task<?> task : tasks) { if (matcher.apply(task)) return Optional.<Task<?>>of(task); if (task instanceof HasTaskChildren) { Optional<Task<?>> subResult = findTaskOrSubTask(((HasTaskChildren) task).getChildren(), matcher); if (subResult.isPresent()) return subResult; } } return Optional.<Task<?>>absent(); }
public static Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>> tasks, Predicate<? super Task<?>> matcher, List<String> taskNames) { for (Task<?> task : tasks) { if (matcher.apply(task)) return Optional.<Task<?>>of(task); if (task instanceof HasTaskChildren) { Optional<Task<?>> subResult = findTaskOrSubTask(((HasTaskChildren) task).getChildren(), matcher); if (subResult.isPresent()) return subResult; } } return Optional.<Task<?>>absent(); }
protected Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>> tasks, Predicate<? super Task<?>> matcher) { for (Task<?> task : tasks) { if (matcher.apply(task)) return Optional.<Task<?>>of(task); if (!(task instanceof HasTaskChildren)) { return Optional.absent(); } else { Optional<Task<?>> subResult = findTaskOrSubTask(((HasTaskChildren) task).getChildren(), matcher); if (subResult.isPresent()) return subResult; } } return Optional.<Task<?>>absent(); } }
private void assertTaskHasFailedChild(Task<Void> task) { Assert.assertTrue(Tasks.failed( ((HasTaskChildren)task).getChildren() ).iterator().hasNext()); }
/** the composed effector should allow us to inspect its children */ @Test public void testComposedEffector() throws Exception { Entity txp1 = app.createAndManageChild(EntitySpec.create(Entity.class, Txp1Entity.class)); Task<Integer> e = txp1.invoke(TWO_X_PLUS_ONE, MutableMap.of("numberToStartWith", 3)); Assert.assertTrue(e instanceof DynamicSequentialTask); Assert.assertEquals(e.get(), (Integer)7); Assert.assertEquals( Iterables.size( ((HasTaskChildren)e).getChildren() ), 1); Task<?> child = ((HasTaskChildren)e).getChildren().iterator().next(); Assert.assertEquals( Iterables.size( ((HasTaskChildren)child).getChildren() ), 1); }
@Override public List<TaskSummary> listTasks(String applicationId, String entityId, int limit, Boolean recurse) { int sizeRemaining = limit; Entity entity = brooklyn().getEntity(applicationId, entityId); List<Task<?>> tasksToScan = MutableList.copyOf(BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), entity)); if (limit>0) { tasksToScan = MutableList.copyOf(Ordering.from(new InterestingTasksFirstComparator(entity)).leastOf(tasksToScan, limit)); } Map<String,Task<?>> tasksLoaded = MutableMap.of(); while (!tasksToScan.isEmpty()) { Task<?> t = tasksToScan.remove(0); if (tasksLoaded.put(t.getId(), t)==null) { if (--sizeRemaining==0) { break; } if (Boolean.TRUE.equals(recurse)) { if (t instanceof HasTaskChildren) { Iterables.addAll(tasksToScan, ((HasTaskChildren) t).getChildren() ); } } } } return new LinkedList<TaskSummary>(Collections2.transform(tasksLoaded.values(), TaskTransformer.fromTask(ui.getBaseUriBuilder()))); }
/** the composed effector should allow us to inspect its children */ @Test public void testComposedEffectorBasic() throws Exception { Entity txp1 = app.createAndManageChild(EntitySpec.create(Entity.class, Txp1Entity.class)); Task<Integer> e = txp1.invoke(TWO_X_PLUS_ONE_BASIC, MutableMap.of("numberToStartWith", 3)); Assert.assertTrue(e instanceof DynamicSequentialTask); Assert.assertEquals(e.get(), (Integer)7); Assert.assertEquals( Iterables.size( ((HasTaskChildren)e).getChildren() ), 2); }
if (parent instanceof HasTaskChildren && Iterables.contains(((HasTaskChildren)parent).getChildren(), task)) {
MutableList<Task<?>> childrenReversed = MutableList.copyOf( ((HasTaskChildren)task).getChildren() ); Collections.reverse(childrenReversed);
private void checkTags(Task<Integer> t, Entity entity, Effector<?> eff, boolean shouldHaveChild) { Assert.assertEquals(BrooklynTaskTags.getContextEntity(t), app); Assert.assertTrue(t.getTags().contains(BrooklynTaskTags.EFFECTOR_TAG), "missing effector tag; had: "+t.getTags()); Assert.assertTrue(t.getDescription().contains(eff.getName()), "description missing effector name: "+t.getDescription()); Assert.assertTrue(BrooklynTaskTags.isInEffectorTask(t, entity, eff, false)); Assert.assertTrue(BrooklynTaskTags.isInEffectorTask(t, null, null, false)); Assert.assertFalse(BrooklynTaskTags.isInEffectorTask(t, entity, Startable.START, false)); if (shouldHaveChild) { Task<?> subtask = ((HasTaskChildren)t).getChildren().iterator().next(); Assert.assertTrue(BrooklynTaskTags.isInEffectorTask(subtask, entity, eff, false)); Assert.assertTrue(BrooklynTaskTags.isInEffectorTask(subtask, null, null, false)); } }
Iterable<Task<?>> childrenTasks = ((HasTaskChildren)this).getChildren(); if (childrenTasks.iterator().hasNext()) { rv += "Children:\n";
log.info("testCancelled acquired semaphore; permits left is "+cancellations.availablePermits()); Iterator<Task<?>> ci = ((HasTaskChildren)t).getChildren().iterator();
final Task<T> t = (Task<T>)task; if (!Tasks.isQueuedOrSubmitted(t) && (!(Tasks.current() instanceof HasTaskChildren) || !Iterables.contains( ((HasTaskChildren)Tasks.current()).getChildren(), t ))) {
if (task instanceof HasTaskChildren) { children = new ArrayList<LinkWithMetadata>(); for (Task<?> t: ((HasTaskChildren)task).getChildren()) { children.add(asLink(t, ub));