Skip to content

Commit 7906e00

Browse files
committed
test
1 parent 20ffca3 commit 7906e00

File tree

5 files changed

+25
-82
lines changed

5 files changed

+25
-82
lines changed

src/main/java/io/orkes/samples/models/Distribution.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@
88
public class Distribution {
99
private String translation;
1010
private String distributeTo;
11-
private String sendToORB = "Y";
12-
private String taskType = "HTTP";
13-
private String natsWorkflowName;
14-
private Integer natsWorkflowVersion;
15-
private Map<String, Object> natsWorkflowInput;
11+
private OrbpFlags orbpFlags;
1612
}

src/main/java/io/orkes/samples/models/Enrichment.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
import lombok.Data;
44

5-
import java.util.Map;
65

76
@Data
87
public class Enrichment {
98
private String enrichmentType;
10-
private String sendToORB = "N";
11-
private String taskType = "HTTP";
12-
private String natsWorkflowName;
13-
private Integer natsWorkflowVersion;
14-
private Map<String, Object> natsWorkflowInput;
9+
private OrbpFlags orbpFlags;
1510
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.orkes.samples.models;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class OrbpFlags {
7+
private String audit = "N";
8+
private String parse = "N";
9+
private String status = "N";
10+
}

src/main/java/io/orkes/samples/models/Translation.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@
99
public class Translation {
1010
private String name;
1111
private List<String> enrichments;
12-
private String sendToORB = "N";
13-
private String taskType = "HTTP";
14-
private String natsWorkflowName;
15-
private Integer natsWorkflowVersion;
16-
private Map<String, Object> natsWorkflowInput;
17-
12+
private OrbpFlags orbpFlags;
1813
}

src/main/java/io/orkes/samples/workers/DynamicSubworkflowWorker.java

+12-65
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
import com.netflix.conductor.client.worker.Worker;
66
import com.netflix.conductor.common.metadata.tasks.Task;
77
import com.netflix.conductor.common.metadata.tasks.TaskResult;
8-
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest;
98
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;
109
import com.netflix.conductor.sdk.workflow.def.ConductorWorkflow;
1110
import com.netflix.conductor.sdk.workflow.def.tasks.*;
1211
import com.netflix.conductor.sdk.workflow.executor.WorkflowExecutor;
13-
import io.orkes.conductor.client.WorkflowClient;
1412
import io.orkes.samples.models.MediationRules;
1513
import lombok.AllArgsConstructor;
1614
import lombok.extern.slf4j.Slf4j;
1715
import org.springframework.stereotype.Component;
1816

1917

20-
import java.util.HashMap;
2118
import java.util.List;
2219
import java.util.Map;
2320

@@ -26,13 +23,12 @@
2623
@AllArgsConstructor
2724
public class DynamicSubworkflowWorker implements Worker {
2825

29-
private final WorkflowClient workflowClient;
3026
private final ObjectMapper objectMapper = new ObjectMapper();
3127
private final WorkflowExecutor executor;
3228

3329
@Override
3430
public String getTaskDefName() {
35-
return "quest_start_subworkflow";
31+
return "create_dynamic_workflow_def";
3632
}
3733

3834
/**
@@ -42,7 +38,7 @@ public String getTaskDefName() {
4238
*/
4339
@Override
4440
public TaskResult execute(Task task) {
45-
System.out.println("Starting quest_start_subworkflow task");
41+
System.out.println("Starting create_dynamic_workflow_def task");
4642
TaskResult result = new TaskResult(task);
4743
try {
4844
MediationRules mediationRules = objectMapper.convertValue(task.getInputData().get("mediation_rules"), MediationRules.class);
@@ -55,17 +51,8 @@ public TaskResult execute(Task task) {
5551
}
5652

5753
public Map<String, Object> startExistingWorkflow(MediationRules mediationRules) throws JsonProcessingException {
58-
StartWorkflowRequest request = new StartWorkflowRequest();
59-
request.setName("dynamic_workflow");
60-
Map<String, Object> inputData = new HashMap<>();
61-
//inputData.put("enrichmentSubworkflowsDef", subworkflowDef());
6254
Object dynamicSubworkflowDef = objectMapper.convertValue(createDynamicSubworkflow(mediationRules), Object.class);
63-
inputData.put("dynamicSubworkflowDef", dynamicSubworkflowDef);
64-
request.setInput(inputData);
65-
66-
String workflowId = workflowClient.startWorkflow(request);
67-
log.info("Workflow id: {}", workflowId);
68-
return Map.of("workflowId", workflowId);
55+
return Map.of("workflow_def", dynamicSubworkflowDef);
6956
}
7057

7158
private WorkflowDef createDynamicSubworkflow(MediationRules mediationRules) throws JsonProcessingException {
@@ -83,20 +70,8 @@ private WorkflowDef createDynamicSubworkflow(MediationRules mediationRules) thro
8370
// --------------- Enrichment level started ------------------
8471
com.netflix.conductor.sdk.workflow.def.tasks.Task[][] enrichmentForkTasks = new com.netflix.conductor.sdk.workflow.def.tasks.Task[mediationRules.getEnrichments().size()][1];
8572
for (int i = 0; i < mediationRules.getEnrichments().size(); i++) {
86-
ConductorWorkflow conductorWorkflow = new ConductorWorkflow(executor);
87-
conductorWorkflow.setName(mediationRules.getEnrichments().get(i).getEnrichmentType() + "_workflow");
88-
89-
SubWorkflow natsSubworkflow = new SubWorkflow("nats_" + mediationRules.getEnrichments().get(i).getEnrichmentType() + "_subworkflow_ref", mediationRules.getEnrichments().get(i).getNatsWorkflowName(), mediationRules.getEnrichments().get(i).getNatsWorkflowVersion());
90-
natsSubworkflow.input(mediationRules.getEnrichments().get(i).getNatsWorkflowInput());
91-
Switch sendToORBEnrichmentSwitch = new Switch("send_to_" + mediationRules.getEnrichments().get(i).getEnrichmentType() + "_switch", "${workflow.input.sendToORB}").switchCase("Y", natsSubworkflow).defaultCase(List.of());
92-
conductorWorkflow.add(sendToORBEnrichmentSwitch);
93-
94-
Http httptask = new Http(mediationRules.getEnrichments().get(i).getEnrichmentType() + "_enrichment_workflow_task");
95-
httptask.url("https://orkes-api-tester.orkesconductor.com/api");
96-
conductorWorkflow.add(httptask);
97-
98-
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getEnrichments().get(i).getEnrichmentType() + "_subworkflow_ref", conductorWorkflow);
99-
forkSubworkflow.input("sendToORB", mediationRules.getEnrichments().get(i).getSendToORB());
73+
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getEnrichments().get(i).getEnrichmentType() + "_subworkflow_ref", "OP_" + mediationRules.getEnrichments().get(i).getEnrichmentType(), 1);
74+
forkSubworkflow.input("sendToORB", mediationRules.getEnrichments().get(i).getOrbpFlags());
10075
enrichmentForkTasks[i][0] = forkSubworkflow;
10176
}
10277
ForkJoin forkEnrichment = new ForkJoin("fork_enrichment", enrichmentForkTasks);
@@ -107,24 +82,11 @@ private WorkflowDef createDynamicSubworkflow(MediationRules mediationRules) thro
10782
// -------------- Translation Level started ----------------
10883
com.netflix.conductor.sdk.workflow.def.tasks.Task[][] translationForkTasks = new com.netflix.conductor.sdk.workflow.def.tasks.Task[mediationRules.getTranslations().size()][1];
10984
for (int i = 0; i < mediationRules.getTranslations().size(); i++) {
110-
ConductorWorkflow conductorWorkflow = new ConductorWorkflow(executor);
111-
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getTranslations().get(i).getName() + "_subworkflow_ref", conductorWorkflow);
112-
forkSubworkflow.input("sendToORB", mediationRules.getTranslations().get(i).getSendToORB());
113-
conductorWorkflow.setName(mediationRules.getTranslations().get(i).getName() + "_workflow");
114-
SubWorkflow natsSubworkflow = new SubWorkflow("nats_" + mediationRules.getTranslations().get(i).getName() + "_subworkflow_ref", mediationRules.getTranslations().get(i).getNatsWorkflowName(), mediationRules.getTranslations().get(i).getNatsWorkflowVersion());
115-
natsSubworkflow.input(mediationRules.getTranslations().get(i).getNatsWorkflowInput());
116-
Switch sendToORBTranslationSwitch = new Switch("send_to_" + mediationRules.getTranslations().get(i).getName() + "_switch", "${workflow.input.sendToORB}").switchCase("Y", natsSubworkflow).defaultCase(List.of());
117-
conductorWorkflow.add(sendToORBTranslationSwitch);
118-
119-
for (int j = 0; j < mediationRules.getTranslations().get(i).getEnrichments().size(); j++) {
120-
Http httptask = new Http(mediationRules.getTranslations().get(i).getEnrichments().get(j)+ "_translations_workflow_task");
121-
httptask.url("https://orkes-api-tester.orkesconductor.com/api");
122-
String taskRef = mediationRules.getTranslations().get(i).getEnrichments().get(j) + "_subworkflow_ref";
123-
String outputExpression = "${" + taskRef + ".output.response}"; //Can differ with different different tasks. Example with Simple/Inline tasks we might have to use result
124-
forkSubworkflow.input(mediationRules.getTranslations().get(i).getEnrichments().get(j), outputExpression);
125-
conductorWorkflow.add(httptask);
85+
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getTranslations().get(i).getName() + "_subworkflow_ref", "OP_" + mediationRules.getTranslations().get(i).getName(), 1);
86+
forkSubworkflow.input("sendToORB", mediationRules.getTranslations().get(i).getOrbpFlags());
87+
for (String enrichmentInput : mediationRules.getTranslations().get(i).getEnrichments()) {
88+
forkSubworkflow.input(enrichmentInput, "${" + enrichmentInput + "_subworkflow_ref" + ".output.result}");
12689
}
127-
12890
translationForkTasks[i][0] = forkSubworkflow;
12991
}
13092
ForkJoin forkTranslation = new ForkJoin("fork_translation", translationForkTasks);
@@ -135,24 +97,9 @@ private WorkflowDef createDynamicSubworkflow(MediationRules mediationRules) thro
13597
// -------------- Distribution level started --------------------
13698
com.netflix.conductor.sdk.workflow.def.tasks.Task[][] distributionForkTasks = new com.netflix.conductor.sdk.workflow.def.tasks.Task[mediationRules.getDistributions().size()][1];
13799
for (int i = 0; i < mediationRules.getDistributions().size(); i++) {
138-
ConductorWorkflow conductorWorkflow = new ConductorWorkflow(executor);
139-
conductorWorkflow.setName(mediationRules.getDistributions().get(i).getDistributeTo() + "_workflow");
140-
141-
SubWorkflow natsSubworkflow = new SubWorkflow("nats_" + mediationRules.getDistributions().get(i).getDistributeTo() + "_subworkflow_ref", mediationRules.getDistributions().get(i).getNatsWorkflowName(), mediationRules.getDistributions().get(i).getNatsWorkflowVersion());
142-
natsSubworkflow.input(mediationRules.getDistributions().get(i).getNatsWorkflowInput());
143-
Switch sendToORBDistributionSwitch = new Switch("send_to_" + mediationRules.getDistributions().get(i).getDistributeTo() + "_switch", "${workflow.input.sendToORB}").switchCase("Y", natsSubworkflow).defaultCase(List.of());
144-
conductorWorkflow.add(sendToORBDistributionSwitch);
145-
146-
Http httptask = new Http(mediationRules.getDistributions().get(i).getDistributeTo() + "_distributions_workflow_task");
147-
httptask.url("https://orkes-api-tester.orkesconductor.com/api");
148-
conductorWorkflow.add(httptask);
149-
150-
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getDistributions().get(i).getDistributeTo() + "_subworkflow_ref", conductorWorkflow);
151-
forkSubworkflow.input("sendToORB", mediationRules.getDistributions().get(i).getSendToORB());
152-
String taskRef = mediationRules.getDistributions().get(i).getTranslation() + "_subworkflow_ref";
153-
String outputExpression = "${" + taskRef + ".output.response}"; //Can differ with different different tasks. Example with Simple/Inline tasks we might have to use result
154-
forkSubworkflow.input(mediationRules.getDistributions().get(i).getTranslation(), outputExpression);
155-
forkSubworkflow.input("sink", "nats:nats-integ:subject");
100+
SubWorkflow forkSubworkflow = new SubWorkflow(mediationRules.getDistributions().get(i).getDistributeTo() + "_subworkflow_ref", "OP_" + mediationRules.getDistributions().get(i).getDistributeTo(), 1);
101+
forkSubworkflow.input("sendToORB", mediationRules.getDistributions().get(i).getOrbpFlags());
102+
forkSubworkflow.input(mediationRules.getDistributions().get(i).getTranslation(), "${" + mediationRules.getDistributions().get(i).getTranslation() + "_subworkflow_ref" + ".output.result}");
156103
distributionForkTasks[i][0] = forkSubworkflow;
157104
}
158105
ForkJoin forkDistribution = new ForkJoin("fork_distribution", distributionForkTasks);

0 commit comments

Comments
 (0)