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

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 426e4566a5 Ability to start workflow at specific action via hop-run 
#3178
     new 2647427594 Merge pull request #3181 from nadment/3178
426e4566a5 is described below

commit 426e4566a5aaaf6895fc6217191d8cdbc3dfed39
Author: Nicolas Adment <[email protected]>
AuthorDate: Tue Aug 29 22:09:29 2023 +0200

    Ability to start workflow at specific action via hop-run #3178
---
 .../modules/ROOT/pages/hop-run/index.adoc          |  6 ++++++
 .../src/main/java/org/apache/hop/run/HopRun.java   | 24 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/docs/hop-user-manual/modules/ROOT/pages/hop-run/index.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/hop-run/index.adoc
index 5f5a9b66df..7468007649 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/hop-run/index.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/hop-run/index.adoc
@@ -48,6 +48,8 @@ Usage: <main class> [-ho] [-e=<environmentOption>] 
[-f=<filename>]
                     [-r=<runConfigurationName>] [-ps=<parametersSeparator] 
[-p=<parameters>[,
                     <parameters>...]]... [-s=<systemProperties>[,
                     <systemProperties>...]]...
+  -a, --startaction=<startActionName>
+                          The name of the action where to start a workflow
   -e, --environment=<environmentOption>
                           The name of the lifecycle environment to use
   -f, --file=<filename>   The filename of the workflow or pipeline to run
@@ -82,6 +84,10 @@ The available options are listed in more detail in the table 
below:
 
 Check the xref:projects/projects-environments.adoc[documentation on 
environments] for more details.
 
+|```-a```
+|```--startaction```
+|The name of the action where to start a workflow
+
 |```-f```
 |```--file```
 |The filename of the workflow or pipeline to run
diff --git a/engine/src/main/java/org/apache/hop/run/HopRun.java 
b/engine/src/main/java/org/apache/hop/run/HopRun.java
index b686736955..2e1221e743 100644
--- a/engine/src/main/java/org/apache/hop/run/HopRun.java
+++ b/engine/src/main/java/org/apache/hop/run/HopRun.java
@@ -53,6 +53,7 @@ import org.apache.hop.pipeline.engine.PipelineEngineFactory;
 import org.apache.hop.server.HopServer;
 import org.apache.hop.workflow.WorkflowExecutionConfiguration;
 import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.action.ActionMeta;
 import org.apache.hop.workflow.config.WorkflowRunConfiguration;
 import org.apache.hop.workflow.engine.IWorkflowEngine;
 import org.apache.hop.workflow.engine.WorkflowEngineFactory;
@@ -119,6 +120,11 @@ public class HopRun implements Runnable, 
IHasHopMetadataProvider {
       description = "The name of the Run Configuration to use")
   private String runConfigurationName = null;
 
+  @Option(
+      names = {"-a", "--startaction"},
+      description = "The name of the action where to start a workflow")
+  private String startActionName = null;
+  
   @Option(
       names = {"-m", "--metadata-export"},
       description = "A file containing exported metadata in JSON format")
@@ -357,6 +363,10 @@ public class HopRun implements Runnable, 
IHasHopMetadataProvider {
         }
       }
 
+      // Start workflow at action
+      //  
+      configuration.setStartActionName(startActionName);      
+      
       // Certain Hop plugins rely on this.  Meh.
       //
       ExtensionPointHandler.callExtensionPoint(
@@ -405,7 +415,19 @@ public class HopRun implements Runnable, 
IHasHopMetadataProvider {
       // Also copy the parameter values over to the variables...
       //
       workflow.activateParameters(workflow);
-
+      
+      // If there is an alternative start action, pass it to the workflow
+      //
+      if (!Utils.isEmpty(configuration.getStartActionName())) {
+        ActionMeta startActionMeta =
+            workflowMeta.findAction(configuration.getStartActionName());
+        
+        if ( startActionMeta==null ) {
+          throw new ExecutionException(cmd, "Error running workflow, specified 
start action not found");
+        } 
+        workflow.setStartActionMeta(startActionMeta);
+      }
+      
       log.logMinimal("Starting workflow: " + workflowMeta.getFilename());
 
       workflow.startExecution();

Reply via email to