brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [08/31] git commit: have at-entity tasks show up as children (in dynamic queueing context, though still submitted externally which means they will not be run as part of queue), and allow them to have children: improves traceability in GUI when effector m
Date Tue, 29 Jul 2014 19:32:03 GMT
have at-entity tasks show up as children (in dynamic queueing context, though still submitted
externally which means they will not be run as part of queue), and allow them to have children:
improves traceability in GUI when effector methods call other effector methods, they show
up as children rather than background tasks (or worse, not even as background tasks); and
support setting flags in TaskBuilder


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8f81e7ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8f81e7ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8f81e7ef

Branch: refs/heads/master
Commit: 8f81e7ef3ead8344c0aec3ec9cd081ea5700e138
Parents: b1fa299
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Jul 21 20:33:51 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jul 29 10:41:11 2014 -0400

----------------------------------------------------------------------
 .../internal/LocalManagementContext.java        | 18 ++++++++--
 .../java/brooklyn/util/task/TaskBuilder.java    | 38 +++++++++++++-------
 2 files changed, 41 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f81e7ef/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
index 3ee97a7..2ab2be6 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalManagementContext.java
@@ -52,11 +52,14 @@ import brooklyn.management.ExecutionManager;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.SubscriptionManager;
 import brooklyn.management.Task;
+import brooklyn.management.TaskAdaptable;
 import brooklyn.management.ha.OsgiManager;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.guava.Maybe;
 import brooklyn.util.task.BasicExecutionContext;
 import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
 import brooklyn.util.text.Strings;
 
 import com.google.common.annotations.Beta;
@@ -322,12 +325,21 @@ public class LocalManagementContext extends AbstractManagementContext
{
         terminate();
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public <T> Task<T> runAtEntity(@SuppressWarnings("rawtypes") Map flags, Entity
entity, Callable<T> c) {
+    public <T> Task<T> runAtEntity(Map flags, Entity entity, Callable<T>
c) {
 		manageIfNecessary(entity, elvis(Arrays.asList(flags.get("displayName"), flags.get("description"),
flags, c)));
-        return getExecutionContext(entity).submit(flags, c);
+        return runAtEntity(entity, Tasks.<T>builder().dynamic(true).body(c).flags(flags).build());
     }
 
+    protected <T> Task<T> runAtEntity(Entity entity, TaskAdaptable<T> task)
{
+        getExecutionContext(entity).submit(task);
+        if (DynamicTasks.getTaskQueuingContext()!=null) {
+            // put it in the queueing context so it appears
+            DynamicTasks.getTaskQueuingContext().queue(task.asTask());
+        }
+        return task.asTask();
+    }
     
     @Override
     protected <T> Task<T> runAtEntity(final Entity entity, final Effector<T>
eff, @SuppressWarnings("rawtypes") final Map parameters) {
@@ -338,7 +350,7 @@ public class LocalManagementContext extends AbstractManagementContext
{
             log.debug("Top-level effector invocation: {} on {}", eff, entity);
             ec = getExecutionContext(entity);
         }
-        return ec.submit(Effectors.invocation(entity, eff, parameters));
+        return runAtEntity(entity, Effectors.invocation(entity, eff, parameters));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f81e7ef/core/src/main/java/brooklyn/util/task/TaskBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/TaskBuilder.java b/core/src/main/java/brooklyn/util/task/TaskBuilder.java
index 35dd8bc..8b0150d 100644
--- a/core/src/main/java/brooklyn/util/task/TaskBuilder.java
+++ b/core/src/main/java/brooklyn/util/task/TaskBuilder.java
@@ -18,10 +18,9 @@
  */
 package brooklyn.util.task;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
 
@@ -30,7 +29,9 @@ import brooklyn.management.TaskAdaptable;
 import brooklyn.management.TaskFactory;
 import brooklyn.management.TaskQueueingContext;
 import brooklyn.util.JavaGroovyEquivalents;
+import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
+import brooklyn.util.collections.MutableSet;
 
 import com.google.common.collect.Iterables;
 
@@ -41,8 +42,9 @@ public class TaskBuilder<T> {
     String description = null;
     Callable<T> body = null;
     Boolean swallowChildrenFailures = null;
-    List<TaskAdaptable<?>> children = new ArrayList<TaskAdaptable<?>>();
-    Set<Object> tags = new LinkedHashSet<Object>();
+    List<TaskAdaptable<?>> children = MutableList.of();
+    Set<Object> tags = MutableSet.of();
+    Map<String,Object> flags = MutableMap.of();
     Boolean dynamic = null;
     boolean parallel = false;
     
@@ -112,18 +114,30 @@ public class TaskBuilder<T> {
         tags.add(tag);
         return this;
     }
+    
+    /** adds a flag to the given task */
+    public TaskBuilder<T> flag(String flag, Object value) {
+        flags.put(flag, value);
+        return this;
+    }
+
+    /** adds the given flags to the given task */
+    public TaskBuilder<T> flags(Map<String,Object> flags) {
+        this.flags.putAll(flags);
+        return this;
+    }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public Task<T> build() {
-        MutableMap<String, Object> flags = MutableMap.of();
-        if (name!=null) flags.add("displayName", name);
-        if (description!=null) flags.add("description", description);
-        if (!tags.isEmpty()) flags.add("tags", tags);
+        MutableMap<String, Object> taskFlags = MutableMap.copyOf(flags);
+        if (name!=null) taskFlags.add("displayName", name);
+        if (description!=null) taskFlags.add("description", description);
+        if (!tags.isEmpty()) taskFlags.add("tags", tags);
         
         if (Boolean.FALSE.equals(dynamic) && children.isEmpty()) {
             if (swallowChildrenFailures!=null)
                 throw new IllegalArgumentException("Cannot set swallowChildrenFailures for
non-dynamic task: "+this);
-            return new BasicTask<T>(flags, body);
+            return new BasicTask<T>(taskFlags, body);
         }
         
         // prefer dynamic set unless (a) user has said not dynamic, or (b) it's parallel
(since there is no dynamic parallel yet)
@@ -132,7 +146,7 @@ public class TaskBuilder<T> {
         if (Boolean.TRUE.equals(dynamic) || (dynamic==null && !parallel)) {
             if (parallel)
                 throw new UnsupportedOperationException("No implementation of parallel dynamic
aggregate task available");
-            DynamicSequentialTask<T> result = new DynamicSequentialTask<T>(flags,
body);
+            DynamicSequentialTask<T> result = new DynamicSequentialTask<T>(taskFlags,
body);
             if (swallowChildrenFailures!=null && swallowChildrenFailures.booleanValue())
result.swallowChildrenFailures();
             for (TaskAdaptable t: children)
                 result.queue(t.asTask());
@@ -148,9 +162,9 @@ public class TaskBuilder<T> {
         }
         
         if (parallel)
-            return new ParallelTask(flags, children);
+            return new ParallelTask(taskFlags, children);
         else
-            return new SequentialTask(flags, children);
+            return new SequentialTask(taskFlags, children);
     }
 
     /** returns a a factory based on this builder */


Mime
View raw message