You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/10/19 11:46:53 UTC

[4/7] incubator-brooklyn git commit: Get a valid execution context even if no entity is available.

Get a valid execution context even if no entity is available.


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

Branch: refs/heads/master
Commit: 51750e2b1f3c2585d08ff774caf68c38d071de9d
Parents: f1d90c6
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Authored: Fri Oct 9 13:35:48 2015 +0100
Committer: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Committed: Mon Oct 19 08:51:15 2015 +0100

----------------------------------------------------------------------
 .../spi/dsl/BrooklynDslDeferredSupplier.java    | 26 +++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/51750e2b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslDeferredSupplier.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslDeferredSupplier.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslDeferredSupplier.java
index 389fe69..05eea1f 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslDeferredSupplier.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslDeferredSupplier.java
@@ -28,9 +28,11 @@ import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.camp.spi.resolve.interpret.PlanInterpretationNode;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.effector.EffectorTasks;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.util.core.task.BasicExecutionContext;
 import org.apache.brooklyn.util.core.task.DeferredSupplier;
+import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,18 +61,18 @@ public abstract class BrooklynDslDeferredSupplier<T> implements DeferredSupplier
     private static final long serialVersionUID = -8789624905412198233L;
 
     private static final Logger log = LoggerFactory.getLogger(BrooklynDslDeferredSupplier.class);
-    
+
     // TODO json of this object should *be* this, not wrapped this ($brooklyn:literal is a bit of a hack, though it might work!)
     @JsonInclude
     @JsonProperty(value="$brooklyn:literal")
     // currently marked transient because it's only needed for logging
     private transient Object dsl = "(gone)";
-    
+
     public BrooklynDslDeferredSupplier() {
         PlanInterpretationNode sourceNode = BrooklynDslInterpreter.currentNode();
         dsl = sourceNode!=null ? sourceNode.getOriginalValue() : null;
     }
-    
+
     /** returns the current entity; for use in implementations of {@link #get()} */
     protected final static EntityInternal entity() {
         // rely on implicit ThreadLocal for now
@@ -82,15 +84,27 @@ public abstract class BrooklynDslDeferredSupplier<T> implements DeferredSupplier
         try {
             if (log.isDebugEnabled())
                 log.debug("Queuing task to resolve "+dsl);
-            T result = Entities.submit(entity(), newTask()).get();
+
+            EntityInternal entity = (EntityInternal) BrooklynTaskTags.getTargetOrContextEntity(Tasks.current());
+            ExecutionContext exec =
+                    (entity != null) ? entity.getExecutionContext()
+                                     : BasicExecutionContext.getCurrentExecutionContext();
+            if (exec == null) {
+                throw new IllegalStateException("No execution context available to resolve " + dsl);
+            }
+
+            Task<T> task = newTask();
+            T result = exec.submit(task).get();
+
             if (log.isDebugEnabled())
                 log.debug("Resolved "+result+" from "+dsl);
             return result;
+
         } catch (Exception e) {
             throw Exceptions.propagate(e);
         }
     }
-    
+
     @Override
     public abstract Task<T> newTask();