Skip to content

Commit 82fb728

Browse files
authored
remove subflow State type, add subFlowRef to Action (#37)
Signed-off-by: mattgarmon <mjg2790@gmail.com>
1 parent 82a7c16 commit 82fb728

10 files changed

+102
-41
lines changed

model/event.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
package model
1616

1717
import (
18+
"reflect"
19+
1820
val "github.com/serverlessworkflow/sdk-go/validator"
1921
"gopkg.in/go-playground/validator.v8"
20-
"reflect"
2122
)
2223

2324
const (
@@ -78,3 +79,11 @@ type EventRef struct {
7879
// Add additional extension context attributes to the produced event
7980
ContextAttributes map[string]interface{} `json:"contextAttributes,omitempty"`
8081
}
82+
83+
// SubFlowRef ...
84+
type SubFlowRef struct {
85+
// Sub-workflow unique id
86+
WorkflowID string `json:"workflowId" validate:"required"`
87+
// Sub-workflow version
88+
Version string `json:"version,omitempty"`
89+
}

model/states.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package model
1616

1717
import (
1818
"encoding/json"
19+
1920
"k8s.io/apimachinery/pkg/util/intstr"
2021
)
2122

@@ -32,8 +33,6 @@ const (
3233
StateTypeSwitch = "switch"
3334
// StateTypeForEach ...
3435
StateTypeForEach = "foreach"
35-
// StateTypeSubflow ...
36-
StateTypeSubflow = "subflow"
3736
// StateTypeInject ...
3837
StateTypeInject = "inject"
3938
// StateTypeCallback ...
@@ -187,17 +186,6 @@ type ParallelState struct {
187186
N intstr.IntOrString `json:"n,omitempty"`
188187
}
189188

190-
// SubflowState Defines a sub-workflow to be executed
191-
type SubflowState struct {
192-
BaseState
193-
// Workflow execution must wait for sub-workflow to finish before continuing
194-
WaitForCompletion bool `json:"waitForCompletion,omitempty"`
195-
// Sub-workflow unique id
196-
WorkflowID string `json:"workflowId" validate:"required"`
197-
// SubFlow state repeat exec definition
198-
Repeat Repeat `json:"repeat,omitempty"`
199-
}
200-
201189
// InjectState ...
202190
type InjectState struct {
203191
BaseState
@@ -218,8 +206,6 @@ type ForEachState struct {
218206
Max intstr.IntOrString `json:"max,omitempty"`
219207
// Actions to be executed for each of the elements of inputCollection
220208
Actions []Action `json:"actions,omitempty"`
221-
// Unique Id of a workflow to be executed for each of the elements of inputCollection
222-
WorkflowID string `json:"workflowId,omitempty"`
223209
}
224210

225211
// CallbackState ...

model/workflow.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ var actionsModelMapping = map[string]func(state map[string]interface{}) State{
3939
}
4040
return &EventBasedSwitchState{}
4141
},
42-
StateTypeSubflow: func(map[string]interface{}) State { return &SubflowState{} },
4342
StateTypeInject: func(map[string]interface{}) State { return &InjectState{} },
4443
StateTypeForEach: func(map[string]interface{}) State { return &ForEachState{} },
4544
StateTypeCallback: func(map[string]interface{}) State { return &CallbackState{} },
@@ -330,6 +329,8 @@ type Action struct {
330329
FunctionRef FunctionRef `json:"functionRef,omitempty"`
331330
// References a 'trigger' and 'result' reusable event definitions
332331
EventRef EventRef `json:"eventRef,omitempty"`
332+
// References a sub-workflow to be executed
333+
SubFlowRef SubFlowRef `json:"subFlowRef,omitempty"`
333334
// Time period to wait for function execution to complete
334335
Timeout string `json:"timeout,omitempty"`
335336
// Action data filter
@@ -401,8 +402,6 @@ type Branch struct {
401402
Name string `json:"name" validate:"required"`
402403
// Actions to be executed in this branch
403404
Actions []Action `json:"actions,omitempty"`
404-
// Unique Id of a workflow to be executed in this branch
405-
WorkflowID string `json:"workflowId,omitempty"`
406405
}
407406

408407
// ActionDataFilter ...

parser/parser_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func TestFromFile(t *testing.T) {
6666
assert.IsType(t, &model.TransitionDataCondition{}, eventState.DataConditions[0])
6767
assert.Equal(t, "TimeoutRetryStrategy", w.Retries[0].Name)
6868
assert.Equal(t, "CheckApplication", w.Start.StateName)
69+
assert.IsType(t, &model.OperationState{}, w.States[1])
70+
operationState := w.States[1].(*model.OperationState)
71+
assert.NotNil(t, operationState)
72+
assert.NotEmpty(t, operationState.Actions)
73+
assert.Equal(t, "startApplicationWorkflowId", operationState.Actions[0].SubFlowRef.WorkflowID)
6974
},
7075
"./testdata/applicationrequest.rp.json": func(t *testing.T, w *model.Workflow) {
7176
assert.IsType(t, &model.DataBasedSwitchState{}, w.States[0])

parser/testdata/applicationrequest-issue16.sw.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ states:
3131
default:
3232
transition: RejectApplication
3333
- name: StartApplication
34-
type: subflow
35-
workflowId: startApplicationWorkflowId
34+
type: operation
35+
actions:
36+
- subFlowRef:
37+
workflowId: startApplicationWorkflowId
3638
end: true
3739
- name: RejectApplication
3840
type: operation

parser/testdata/applicationrequest.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@
4343
},
4444
{
4545
"name": "StartApplication",
46-
"type": "subflow",
47-
"workflowId": "startApplicationWorkflowId",
46+
"type": "operation",
47+
"actions": [
48+
{
49+
"subFlowRef": {
50+
"workflowId": "startApplicationWorkflowId"
51+
}
52+
}
53+
],
4854
"end": {
4955
"terminate": true
5056
}

parser/testdata/applicationrequest.rp.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
},
3535
{
3636
"name": "StartApplication",
37-
"type": "subflow",
38-
"workflowId": "startApplicationWorkflowId",
37+
"type": "operation",
38+
"actions": [
39+
{
40+
"subFlowRef": {
41+
"workflowId": "startApplicationWorkflowId"
42+
}
43+
}
44+
],
3945
"end": {
4046
"terminate": true
4147
}

parser/testdata/applicationrequest.url.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
},
3535
{
3636
"name": "StartApplication",
37-
"type": "subflow",
38-
"workflowId": "startApplicationWorkflowId",
37+
"type": "operation",
38+
"actions": [
39+
{
40+
"subFlowRef": {
41+
"workflowId": "startApplicationWorkflowId"
42+
}
43+
}
44+
],
3945
"end": {
4046
"terminate": true
4147
}

parser/testdata/eventbasedswitch.sw.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,42 @@
4545
},
4646
{
4747
"name": "HandleApprovedVisa",
48-
"type": "subflow",
49-
"workflowId": "handleApprovedVisaWorkflowID",
48+
"type": "operation",
49+
"actions": [
50+
{
51+
"subFlowRef": {
52+
"workflowId": "handleApprovedVisaWorkflowID"
53+
}
54+
}
55+
],
5056
"end": {
5157
"terminate": true
5258
}
5359
},
5460
{
5561
"name": "HandleRejectedVisa",
56-
"type": "subflow",
57-
"workflowId": "handleRejectedVisaWorkflowID",
62+
"type": "operation",
63+
"actions": [
64+
{
65+
"subFlowRef": {
66+
"workflowId": "handleRejectedVisaWorkflowID"
67+
}
68+
}
69+
],
5870
"end": {
5971
"terminate": true
6072
}
6173
},
6274
{
6375
"name": "HandleNoVisaDecision",
64-
"type": "subflow",
65-
"workflowId": "handleNoVisaDecisionWorkfowId",
76+
"type": "operation",
77+
"actions": [
78+
{
79+
"subFlowRef": {
80+
"workflowId": "handleNoVisaDecisionWorkfowId"
81+
}
82+
}
83+
],
6684
"end": {
6785
"terminate": true
6886
}

parser/testdata/provisionorders.sw.json

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,56 @@
5656
},
5757
{
5858
"name": "MissingId",
59-
"type": "subflow",
60-
"workflowId": "handleMissingIdExceptionWorkflow",
59+
"type": "operation",
60+
"actions": [
61+
{
62+
"subFlowRef": {
63+
"workflowId": "handleMissingIdExceptionWorkflow"
64+
}
65+
}
66+
],
6167
"end": {
6268
"terminate": true
6369
}
6470
},
6571
{
6672
"name": "MissingItem",
67-
"type": "subflow",
68-
"workflowId": "handleMissingItemExceptionWorkflow",
73+
"type": "operation",
74+
"actions": [
75+
{
76+
"subFlowRef": {
77+
"workflowId": "handleMissingItemExceptionWorkflow"
78+
}
79+
}
80+
],
6981
"end": {
7082
"terminate": true
7183
}
7284
},
7385
{
7486
"name": "MissingQuantity",
75-
"type": "subflow",
76-
"workflowId": "handleMissingQuantityExceptionWorkflow",
87+
"type": "operation",
88+
"actions": [
89+
{
90+
"subFlowRef": {
91+
"workflowId": "handleMissingQuantityExceptionWorkflow"
92+
}
93+
}
94+
],
7795
"end": {
7896
"terminate": true
7997
}
8098
},
8199
{
82100
"name": "ApplyOrder",
83-
"type": "subflow",
84-
"workflowId": "applyOrderWorkflowId",
101+
"type": "operation",
102+
"actions": [
103+
{
104+
"subFlowRef": {
105+
"workflowId": "applyOrderWorkflowId"
106+
}
107+
}
108+
],
85109
"end": {
86110
"terminate": true
87111
}

0 commit comments

Comments
 (0)