Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Fixes #2528 - The UI was not supporting SWITCH task definitions or th…
Browse files Browse the repository at this point in the history
…e execution.

 With this change it will support both SWITCH and DECISION. Tested UI rendering manually screenshots attached to the issue. (#2547)
  • Loading branch information
boney9 authored Oct 29, 2021
1 parent 85db363 commit 62e8b1c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class ValueParamEvaluator implements Evaluator {

@Override
public Object evaluate(String expression, Object input) {
LOGGER.debug("ValueParam evaluator -- Evaluating: {}", expression);
LOGGER.debug("ValueParam evaluator -- evaluating: {}", expression);
if (input instanceof Map) {
Object result = ((Map<String, Object>) input).get(expression);
LOGGER.debug("ValueParam evaluator -- result: {}", result);
return result;
} else {
String errorMsg = String.format("Input must of a JSON object: %s", input.getClass());
String errorMsg = String.format("Input has to be a JSON object: %s", input.getClass());
LOGGER.error(errorMsg);
throw new TerminateWorkflowException(errorMsg);
}
Expand Down
15 changes: 12 additions & 3 deletions docs/docs/configuration/systask.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ A switch task is similar to ```case...switch``` statement in a programming langu
The `switch` expression, however, is simply an input parameter (`value-param` evaluator) or a complex javascript
expression (`javascript` evaluator). Only two evaluators are supported by default in conductor.

**For Developers** Any type of custom evaluator can be implemented without having to touch the way `switch` task works.

The task takes 2 parameters and even with growing number of evaluators, it always takes 2 parameters:
**For Conductor Developers**: Custom evaluators can be implemented without having to change the way `SWITCH` task works.
To implement and use the custom evaluators we can use the params `evaluatorType` and `expression`.

**Parameters:**

Expand Down Expand Up @@ -76,6 +75,16 @@ The task takes 2 parameters and even with growing number of evaluators, it alway
}
```

### Decision (Deprecated)

`DECISION` task type has been **deprecated** and replaced with the `SWITCH` task type. Switch task type is identical to how Decision tasks works except for the following differences:

`DECISION` task type used to take two parameters
1. `caseExpression` : If present, this takes precedence and will be evaluated as a Javascript expression
2. `caseValueParam` : If `caseExpression` param is null or empty, case value param will be used to determine the decision branch

`SWITCH` works with the `evaluatorType` and `expression` params as a replacement to the above. For details refer to the `SWITCH` task documentation

## Event
Event task provides ability to publish an event (message) to either Conductor or an external eventing system like SQS. Event tasks are useful for creating event based dependencies for workflows and tasks.

Expand Down
28 changes: 16 additions & 12 deletions ui/src/components/diagram/WorkflowDAG.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ export default class WorkflowDAG {
}
}

isTakenDecisionBranch(caseValue, decisionTaskRef) {
switchBranchTaken(caseValue, decisionTaskRef, type) {
if (!this.taskResults.has(decisionTaskRef)) return false;

const decisionTaskResult = this.getLastTaskResult(decisionTaskRef);
const cases = Object.keys(decisionTaskResult.workflowTask.decisionCases);
const switchTaskResult = this.getLastTaskResult(decisionTaskRef);
const cases = Object.keys(switchTaskResult.workflowTask.decisionCases);

const actualValue = _.get(decisionTaskResult, "outputData.caseOutput[0]");
// Required until DECISION is fully removed
let resultField = type === "SWITCH" ? "evaluationResult" : "caseOutput";
const actualValue = _.get(switchTaskResult, `outputData.${resultField}[0]`);
if (actualValue === undefined) return false;

if (caseValue) {
Expand Down Expand Up @@ -138,19 +140,20 @@ export default class WorkflowDAG {
);
const edgeParams = {};

// Special case - When the antecedent of an executed node is a DECISION, the edge may not necessarily be highlighted.
// Special case - When the antecedent of an executed node is a SWITCH, the edge may not necessarily be highlighted.
// E.g. the default edge not taken.

if (antecedent.type === "DECISION") {
// SWITCH is the newer version of DECISION and DECISION is deprecated
if (antecedent.type === "SWITCH" || antecedent.type === "DECISION") {
edgeParams.caseValue = getCaseValue(
taskConfig.taskReferenceName,
antecedent
);

// Highlight edge as executed only after thorough test
const branchTaken = this.isTakenDecisionBranch(
const branchTaken = this.switchBranchTaken(
edgeParams.caseValue,
antecedent.taskReferenceName
antecedent.taskReferenceName,
antecedent.type
);
if (branchTaken) {
edgeParams.executed = true;
Expand Down Expand Up @@ -183,7 +186,7 @@ export default class WorkflowDAG {
}

// Nodes are connected to previous
processDecisionTask(decisionTask, antecedents) {
processSwitchTask(decisionTask, antecedents) {
console.assert(Array.isArray(antecedents));
const retval = [];

Expand Down Expand Up @@ -268,8 +271,9 @@ export default class WorkflowDAG {
return this.processForkJoinDynamic(task, antecedents);
}

case "DECISION": {
return this.processDecisionTask(task, antecedents);
case "DECISION": // DECISION is deprecated and will be removed in a future release
case "SWITCH": {
return this.processSwitchTask(task, antecedents);
}

case "TERMINATE": {
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/diagram/WorkflowGraph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class WorkflowGraph extends React.PureComponent {
this.barNodes.push(v.ref);
break;
case "DECISION":
case "SWITCH":
retval.label = v.ref;
retval.shape = "diamond";
retval.height = 40;
Expand Down

0 comments on commit 62e8b1c

Please sign in to comment.