-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added very simple examples used in "Getting Started"
- Loading branch information
1 parent
bfea636
commit b858441
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...-java-sdk/examples/src/main/java/com/netflix/conductor/gettingstarted/CreateWorkflow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.netflix.conductor.gettingstarted; | ||
|
||
import com.netflix.conductor.sdk.workflow.def.WorkflowBuilder; | ||
import com.netflix.conductor.sdk.workflow.def.tasks.SimpleTask; | ||
import com.netflix.conductor.sdk.workflow.executor.WorkflowExecutor; | ||
|
||
/** | ||
* Very Simple Workflow As Code Example. | ||
* | ||
* You can use the following code to register this "hello_workflow" workflow. | ||
* | ||
* { | ||
* "name": "hello_workflow", | ||
* "description": "Hello Workflow!", | ||
* "version": 1, | ||
* "tasks": [ | ||
* { | ||
* "name": "hello_task", | ||
* "taskReferenceName": "hello_task_ref", | ||
* "type": "SIMPLE", | ||
* "inputParameters": {} | ||
* } | ||
* ], | ||
* "inputParameters": [], | ||
* "outputParameters": { | ||
* | ||
* }, | ||
* "schemaVersion": 2, | ||
* "restartable": true, | ||
* "workflowStatusListenerEnabled": false, | ||
* "ownerEmail": "[email protected]", | ||
* "timeoutPolicy": "ALERT_ONLY", | ||
* "timeoutSeconds": 0 | ||
* } | ||
*/ | ||
public class CreateWorkflow { | ||
|
||
public static void main(String[] args) { | ||
var executor = new WorkflowExecutor("http://localhost:8080/api"); | ||
var workflow = new WorkflowBuilder<Void>(executor) | ||
.name("hello_workflow") | ||
.version(1) | ||
.description("Hello Workflow!") | ||
.ownerEmail("[email protected]") | ||
.add(new SimpleTask("hello_task", "hello_task_ref")) | ||
.build(); | ||
workflow.registerWorkflow(true, true); | ||
executor.shutdown(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...tor-java-sdk/examples/src/main/java/com/netflix/conductor/gettingstarted/HelloWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.netflix.conductor.gettingstarted; | ||
|
||
import com.netflix.conductor.client.automator.TaskRunnerConfigurer; | ||
import com.netflix.conductor.client.http.ConductorClient; | ||
import com.netflix.conductor.client.http.TaskClient; | ||
import com.netflix.conductor.client.worker.Worker; | ||
import com.netflix.conductor.common.metadata.tasks.Task; | ||
import com.netflix.conductor.common.metadata.tasks.TaskResult; | ||
|
||
import java.util.List; | ||
|
||
public class HelloWorker implements Worker { | ||
|
||
@Override | ||
public TaskResult execute(Task task) { | ||
var taskResult = new TaskResult(task); | ||
taskResult.setStatus(TaskResult.Status.COMPLETED); | ||
taskResult.getOutputData().put("message", "Hello World!"); | ||
return taskResult; | ||
} | ||
|
||
@Override | ||
public String getTaskDefName() { | ||
return "hello_task"; | ||
} | ||
|
||
public static void main(String[] args) { | ||
var client = new ConductorClient("http://localhost:8080/api"); | ||
var taskClient = new TaskClient(client); | ||
var runnerConfigurer = new TaskRunnerConfigurer | ||
.Builder(taskClient, List.of(new HelloWorker())) | ||
.withThreadCount(10) | ||
.build(); | ||
runnerConfigurer.init(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...r-java-sdk/examples/src/main/java/com/netflix/conductor/gettingstarted/StartWorkflow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.netflix.conductor.gettingstarted; | ||
|
||
import com.netflix.conductor.client.http.ConductorClient; | ||
import com.netflix.conductor.client.http.WorkflowClient; | ||
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; | ||
|
||
public class StartWorkflow { | ||
|
||
public static void main(String[] args) { | ||
var client = new ConductorClient("http://localhost:8080/api"); | ||
var workflowClient = new WorkflowClient(client); | ||
var workflowId = workflowClient.startWorkflow(new StartWorkflowRequest() | ||
.withName("hello_workflow") | ||
.withVersion(1)); | ||
|
||
System.out.println("Started workflow " + workflowId); | ||
} | ||
} |