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 4b388541622851a7171cc52c232cbeb5accb3f2e
Author: Alex Heneveld <[email protected]>
AuthorDate: Thu Mar 23 17:34:41 2023 +0000

    support target_index variable for list-based targets
---
 .../org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git 
a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
 
b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
index 0c87777f38..efc51fc185 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/CustomWorkflowStep.java
@@ -201,8 +201,9 @@ public class CustomWorkflowStep extends 
WorkflowStepDefinition implements Workfl
             targetR = MutableList.of(targetR);
         }
 
+        AtomicInteger index = new AtomicInteger(0);
         ((Iterable<?>) targetR).forEach(t -> {
-            WorkflowExecutionContext nw = newWorkflow(context, t);
+            WorkflowExecutionContext nw = newWorkflow(context, t, 
index.getAndIncrement());
             Maybe<Task<Object>> mt = nw.getTask(true);
 
             String targetS = wasList || t !=null ? " for target '"+t+"'" : "";
@@ -396,7 +397,7 @@ public class CustomWorkflowStep extends 
WorkflowStepDefinition implements Workfl
         return result;
     }
 
-    private WorkflowExecutionContext 
newWorkflow(WorkflowStepInstanceExecutionContext context, Object target) {
+    private WorkflowExecutionContext 
newWorkflow(WorkflowStepInstanceExecutionContext context, Object target, int 
targetIndex) {
         if (steps==null) throw new IllegalArgumentException("Cannot make new 
workflow with no steps");
 
         WorkflowExecutionContext nestedWorkflowContext = 
WorkflowExecutionContext.newInstanceUnpersistedWithParent(
@@ -406,6 +407,7 @@ public class CustomWorkflowStep extends 
WorkflowStepDefinition implements Workfl
                 ConfigBag.newInstance(getInput()), null);
         if (target!=null) {
             nestedWorkflowContext.getWorkflowScratchVariables().put("target", 
target);
+            
nestedWorkflowContext.getWorkflowScratchVariables().put("target_index", 
targetIndex);
         }
         return nestedWorkflowContext;
     }

Reply via email to