This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit f65e7c6652f0423364f696e29a7d4f453c9ee0b6
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Mar 20 11:01:40 2023 +0000

    allow interpolation when writing nested workflow inputs
---
 .../core/workflow/WorkflowExecutionContext.java        | 18 ++++++++++++++++--
 .../workflow/WorkflowNestedAndCustomExtensionTest.java | 13 ++++++++++++-
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
 
b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
index c05562c97e..40c9d0adb5 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowExecutionContext.java
@@ -547,8 +547,22 @@ public class WorkflowExecutionContext {
         if (inputResolved.containsKey(key)) return 
Maybe.ofAllowingNull((T)inputResolved.get(key));
 
         Object v = input.get(key);
-        // DSL resolution/coercion only, not workflow syntax here (as no 
workflow scope)
-        Maybe<T> vm = 
Tasks.resolving(v).as(type).context(getEntity()).immediately(true).deep().getMaybe();
+        // normally do DSL resolution/coercion only, not workflow syntax here 
(as no workflow scope);
+        // except if we are in a nested workflow, we allow resolving from the 
parent.
+        // (alternatively we could resolve when starting the custom workflow; 
that might be better.)
+        Maybe<T> vm = null;
+        if (v instanceof String && parent!=null && 
parent.getCurrentStepInstance()!=null) {
+            try {
+                vm = 
Maybe.of(parent.getCurrentStepInstance().resolve(WorkflowExpressionResolution.WorkflowExpressionStage.STEP_RUNNING,
 (String) v, type));
+            } catch (Exception e) {
+                Exceptions.propagateIfFatal(e);
+                vm = Maybe.absent(e);
+            }
+        }
+        if (vm==null || vm.isAbsent()) {
+            Maybe<T> vm2 = 
Tasks.resolving(v).as(type).context(getEntity()).immediately(true).deep().getMaybe();
+            if (vm2.isPresent() || vm==null) vm = vm2;  // if errors in both, 
prefer error in first
+        }
         if (vm.isPresent()) {
             if (WorkflowStepInstanceExecutionContext.REMEMBER_RESOLVED_INPUT) {
                 // this will keep spending time resolving, but will resolve 
the resolved value
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowNestedAndCustomExtensionTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowNestedAndCustomExtensionTest.java
index a0c0c17504..3120cfe261 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowNestedAndCustomExtensionTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowNestedAndCustomExtensionTest.java
@@ -196,7 +196,9 @@ public class WorkflowNestedAndCustomExtensionTest extends 
RebindTestFixture<Test
                 "output:",
                 "  message: hi ${name}"
         ));
-        Object output = 
invokeWorkflowStepsWithLogging(MutableList.of(MutableMap.of("type", "log-hi", 
"input", MutableMap.of("name", "bob"))));
+        Object output;
+
+        output = 
invokeWorkflowStepsWithLogging(MutableList.of(MutableMap.of("type", "log-hi", 
"input", MutableMap.of("name", "bob"))));
         assertLogStepMessages("hi bob");
         Asserts.assertEquals(output, MutableMap.of("message", "hi bob"));
 
@@ -204,6 +206,15 @@ public class WorkflowNestedAndCustomExtensionTest extends 
RebindTestFixture<Test
         output = 
invokeWorkflowStepsWithLogging(MutableList.of(MutableMap.of("type", "log-hi", 
"input", MutableMap.of("name", "bob"), "output", "I said ${message}")));
         assertLogStepMessages("hi bob");
         Asserts.assertEquals(output, "I said hi bob");
+
+        output = invokeWorkflowStepsWithLogging(MutableList.of(
+                "let outer_name = bob",
+                MutableMap.of("type", "log", "input", MutableMap.of("message", 
"hello ${name2}", "name2", "${outer_name}")),
+                MutableMap.of("type", "log-hi", "input", MutableMap.of("name", 
"${outer_name}"), "output", "Now I said ${message}")));
+        assertLogStepMessages(
+                "hello bob",
+                "hi bob");
+        Asserts.assertEquals(output, "Now I said hi bob");
     }
 
     @Test

Reply via email to