Repository: brooklyn-server Updated Branches: refs/heads/master 1c994df7d -> 3c5981b57
REST endpoint for an activity children has `includeBackground` option Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/99f0adc0 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/99f0adc0 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/99f0adc0 Branch: refs/heads/master Commit: 99f0adc0b07023542e494f3aac86daa2788991ad Parents: 1c994df Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Wed Feb 15 11:53:45 2017 +0000 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Wed Feb 15 11:56:17 2017 +0000 ---------------------------------------------------------------------- .../apache/brooklyn/rest/api/ActivityApi.java | 4 +- .../rest/resources/ActivityResource.java | 41 +++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/99f0adc0/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ActivityApi.java ---------------------------------------------------------------------- diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ActivityApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ActivityApi.java index 73beaf3..45cd25c 100644 --- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ActivityApi.java +++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ActivityApi.java @@ -54,7 +54,9 @@ public interface ActivityApi { @ApiResponse(code = 404, message = "Could not find task") }) public List<TaskSummary> children( - @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId); + @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId, + @ApiParam(value = "Whether to include non-subtask backgrounded tasks submitted by this task", required = false) + @QueryParam("includeBackground") @DefaultValue("false") Boolean includeBackground); @GET @Path("/{task}/children/recurse") http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/99f0adc0/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java index 3b4bdbe..81439d5 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ActivityResource.java @@ -18,9 +18,14 @@ */ package org.apache.brooklyn.rest.resources; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.mgmt.HasTaskChildren; import org.apache.brooklyn.api.mgmt.Task; @@ -31,8 +36,12 @@ import org.apache.brooklyn.rest.api.ActivityApi; import org.apache.brooklyn.rest.domain.TaskSummary; import org.apache.brooklyn.rest.transform.TaskTransformer; import org.apache.brooklyn.rest.util.WebResourceUtils; +import org.apache.brooklyn.util.collections.MutableList; +import org.apache.brooklyn.util.collections.MutableSet; -import java.util.*; +import com.google.common.collect.Collections2; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; public class ActivityResource extends AbstractBrooklynRestResource implements ActivityApi { @@ -71,13 +80,35 @@ public class ActivityResource extends AbstractBrooklynRestResource implements Ac @Override - public List<TaskSummary> children(String taskId) { + public List<TaskSummary> children(String taskId, Boolean includeBackground) { Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t == null) { throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); } checkEntityEntitled(t); + Set<TaskSummary> result = MutableSet.copyOf(getSubTaskChildren(t)); + if (Boolean.TRUE.equals(includeBackground)) { + result.addAll(getBackgroundedChildren(t)); + } + return MutableList.copyOf(result); + } + + 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; + } + + private List<TaskSummary> getSubTaskChildren(Task<?> t) { if (!(t instanceof HasTaskChildren)) { return Collections.emptyList(); }