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 d6d53dc85897b7c2f97b0f1c4429fc42472cabdc Author: Alex Heneveld <a...@cloudsoft.io> AuthorDate: Fri Feb 9 19:27:09 2024 +0000 allow workflow step names to include freemarker expressions, and resolve them --- .../brooklyn/core/workflow/WorkflowStepDefinition.java | 16 ++++++++++++++++ .../apache/brooklyn/core/workflow/WorkflowBasicTest.java | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowStepDefinition.java b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowStepDefinition.java index 72f04fc002..34a5502996 100644 --- a/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowStepDefinition.java +++ b/core/src/main/java/org/apache/brooklyn/core/workflow/WorkflowStepDefinition.java @@ -27,6 +27,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; +import org.apache.brooklyn.core.workflow.WorkflowExpressionResolution.WorkflowExpressionStage; import org.apache.brooklyn.util.collections.CollectionMerger; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; @@ -60,6 +61,7 @@ public abstract class WorkflowStepDefinition { // name: a name to display in the UI; if omitted it is constructed from the step ID and step type protected String name; + protected String nameUnresolved; // raw name, if we resolve it public String getName() { return name; @@ -222,6 +224,7 @@ public abstract class WorkflowStepDefinition { continuationInstructions.customBehavior.run(); } // if continuing, all the info needed is now in the step state on the context and should be used by the method below + updateName(context); return doTaskBody(context); }; }; @@ -235,6 +238,19 @@ public abstract class WorkflowStepDefinition { return t; } + protected void updateName(WorkflowStepInstanceExecutionContext context) { + if (Strings.isNonBlank(getName())) { + try { + if (this.nameUnresolved==null) this.nameUnresolved = getName(); + this.name = context.resolve(WorkflowExpressionStage.STEP_PRE_INPUT, this.nameUnresolved, String.class); + context.name = this.name; + } catch (Exception e) { + Exceptions.propagateIfFatal(e); + // otherwise ignore + } + } + } + protected abstract Object doTaskBody(WorkflowStepInstanceExecutionContext context); public String computeName(WorkflowStepInstanceExecutionContext context, boolean includeStepNumber) { diff --git a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java index 1ab20b9887..9c4bd303e6 100644 --- a/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/workflow/WorkflowBasicTest.java @@ -533,5 +533,19 @@ public class WorkflowBasicTest extends BrooklynMgmtUnitTestSupport { w1.getTask(false).get().getUnchecked(), 42); } + + @Test + public void testWorkflowStepWithCustomName() { + loadTypes(); + BasicApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)); + WorkflowExecutionContext w1 = WorkflowBasicTest.runWorkflow(app, Strings.lines( + "- name: step on entity ${entity.id}", + " step: return ${entity.id}" + ), null); + Asserts.assertEquals( + w1.getTask(false).get().getUnchecked(), + app.getId()); + Asserts.assertEquals(w1.getStepsResolved().get(0).getName(), "step on entity "+app.getId()); + } }