Skip to content

Commit f9a2088

Browse files
shivamkm07mukundansundardaixiang0dapr-bot
authoredJan 17, 2024
Cascade terminate/Purge Workflow Support (dapr#7340)
* Updating protos Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * enable recursive terminate/purge Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Updating dtf-go Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * updating contrib Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Correct proto generated files Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * update comment Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * implementing getOrchestrationRuntimeState Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Adding unit tests Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * make modtidy-all Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Adding recursive option in query parameter Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Adding integration test for workflow Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * fix bug in Creating sub-orchestrations Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Setting recursive/terminate purge to default and adding tests for same Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * linter fixes Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * Removing fix from this PR Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * renaming to Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> * linter fixes Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> --------- Signed-off-by: Shivam Kumar <shivamkm07@gmail.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Loong Dai <long.dai@intel.com> Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
1 parent 994b037 commit f9a2088

File tree

13 files changed

+686
-373
lines changed

13 files changed

+686
-373
lines changed
 

‎Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ test-integration: test-deps
374374
################################################################################
375375
# Target: lint #
376376
################################################################################
377-
# Please use golangci-lint version v1.51.2 , otherwise you might encounter errors.
378-
# You can download version v1.51.2 at https://github.com/golangci/golangci-lint/releases/tag/v1.51.2
377+
# Please use golangci-lint version v1.55.2 , otherwise you might encounter errors.
378+
# You can download version v1.55.2 at https://github.com/golangci/golangci-lint/releases/tag/v1.55.2
379379
.PHONY: lint
380380
lint: check-linter
381381
$(GOLANGCI_LINT) run --build-tags=$(GOLANGCI_LINT_TAGS) --timeout=20m

‎dapr/proto/runtime/v1/dapr.proto

+4
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,8 @@ message TerminateWorkflowRequest {
10661066
string instance_id = 1 [json_name = "instanceID"];
10671067
// Name of the workflow component.
10681068
string workflow_component = 2 [json_name = "workflowComponent"];
1069+
// Indicates whether this is a non_recursive terminate request
1070+
bool non_recursive = 3 [json_name = "non_recursive"];
10691071
}
10701072

10711073
// PauseWorkflowRequest is the request for PauseWorkflowBeta1.
@@ -1102,6 +1104,8 @@ message PurgeWorkflowRequest {
11021104
string instance_id = 1 [json_name = "instanceID"];
11031105
// Name of the workflow component.
11041106
string workflow_component = 2 [json_name = "workflowComponent"];
1107+
// Indicates whether this is a non_recursive purge request
1108+
bool non_recursive = 3 [json_name = "non_recursive"];
11051109
}
11061110

11071111
// ShutdownRequest is the request for Shutdown.

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/jhump/protoreflect v1.15.2
3737
github.com/kelseyhightower/envconfig v1.4.0
3838
github.com/lestrrat-go/jwx/v2 v2.0.18
39-
github.com/microsoft/durabletask-go v0.4.0
39+
github.com/microsoft/durabletask-go v0.4.1-0.20231222205218-fc5756737d3c
4040
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4
4141
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
4242
github.com/prometheus/client_golang v1.16.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
11601160
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
11611161
github.com/microcosm-cc/bluemonday v1.0.24 h1:NGQoPtwGVcbGkKfvyYk1yRqknzBuoMiUrO6R7uFTPlw=
11621162
github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8=
1163-
github.com/microsoft/durabletask-go v0.4.0 h1:rGqKRZYyvxBaD/UIfVUnlGqrycqBg30Ngpt0ODcIzqY=
1164-
github.com/microsoft/durabletask-go v0.4.0/go.mod h1:svScWPnRqjf9YgxeCB3CkYLMAyvuu+qqNf4Hl9dmvcg=
1163+
github.com/microsoft/durabletask-go v0.4.1-0.20231222205218-fc5756737d3c h1:eng0MBn0jE65oWhzHbCugaGs6JetgfkdVW36nIJ0vgI=
1164+
github.com/microsoft/durabletask-go v0.4.1-0.20231222205218-fc5756737d3c/go.mod h1:OSZ4K7SgqBEsaouk3lAVdDzvanIzsdj7angZ0FTeSAU=
11651165
github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc=
11661166
github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU=
11671167
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=

‎pkg/api/http/http.go

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const (
9999
workflowComponent = "workflowComponent"
100100
workflowName = "workflowName"
101101
instanceID = "instanceID"
102+
nonRecursive = "non_recursive"
102103
eventName = "eventName"
103104
consistencyParam = "consistency"
104105
concurrencyParam = "concurrency"

‎pkg/api/http/http_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,30 @@ func TestV1Beta1Workflow(t *testing.T) {
28212821
assert.Nil(t, resp.ErrorBody)
28222822
})
28232823

2824+
t.Run("Terminate with non_recursive set to false", func(t *testing.T) {
2825+
// This has the same behavior as the case when non_recursive parameter is not set.
2826+
// This is because default case is set to recursive termination.
2827+
2828+
apiPath := "v1.0-beta1/workflows/dapr/instanceID/terminate?non_recursive=false"
2829+
2830+
resp := fakeServer.DoRequest("POST", apiPath, nil, nil)
2831+
assert.Equal(t, 202, resp.StatusCode)
2832+
2833+
// assert
2834+
assert.Nil(t, resp.ErrorBody)
2835+
})
2836+
2837+
t.Run("Terminate with non_recursive true", func(t *testing.T) {
2838+
// Note that in case of non_recursive true, MockWorkflow intentionally returns fake error, even when it is not an actual error.
2839+
// This is to test that non_recursive flag is being passed correctly to the workflow component.
2840+
2841+
apiPath := "v1.0-beta1/workflows/dapr/instanceID/terminate?non_recursive=true"
2842+
resp := fakeServer.DoRequest("POST", apiPath, nil, nil)
2843+
assert.Equal(t, 500, resp.StatusCode)
2844+
assert.Equal(t, "ERR_TERMINATE_WORKFLOW", resp.ErrorBody["errorCode"])
2845+
assert.Equal(t, fmt.Sprintf(messages.ErrTerminateWorkflow.Message(), "instanceID", daprt.ErrFakeWorkflowNonRecursiveTerminateError), resp.ErrorBody["message"])
2846+
})
2847+
28242848
///////////////////////////
28252849
// RAISE EVENT API TESTS //
28262850
///////////////////////////
@@ -2931,6 +2955,28 @@ func TestV1Beta1Workflow(t *testing.T) {
29312955
// assert
29322956
assert.Nil(t, resp.ErrorBody)
29332957
})
2958+
2959+
t.Run("Purge with non_recursive false", func(t *testing.T) {
2960+
// This has the same behavior as the case when non_recursive parameter is not set.
2961+
// This is because default case is set to recursive purge.
2962+
2963+
apiPath := "v1.0-beta1/workflows/dapr/instanceID/purge?non_recursive=false"
2964+
resp := fakeServer.DoRequest("POST", apiPath, nil, nil)
2965+
assert.Equal(t, 202, resp.StatusCode)
2966+
2967+
// assert
2968+
assert.Nil(t, resp.ErrorBody)
2969+
})
2970+
t.Run("Purge with non_recursive true", func(t *testing.T) {
2971+
// Note that in case of non_recursive true, MockWorkflow intentionally returns fake error, even when it is not an actual error.
2972+
// This is to test that non_recursive flag is being passed correctly to the workflow component.
2973+
2974+
apiPath := "v1.0-beta1/workflows/dapr/instanceID/purge?non_recursive=true"
2975+
resp := fakeServer.DoRequest("POST", apiPath, nil, nil)
2976+
assert.Equal(t, 500, resp.StatusCode)
2977+
assert.Equal(t, "ERR_PURGE_WORKFLOW", resp.ErrorBody["errorCode"])
2978+
assert.Equal(t, fmt.Sprintf(messages.ErrPurgeWorkflow.Message(), "instanceID", daprt.ErrFakeWorkflowNonRecurisvePurgeError), resp.ErrorBody["message"])
2979+
})
29342980
}
29352981

29362982
func buildHTTPPineline(spec config.PipelineSpec) httpMiddleware.Pipeline {

‎pkg/api/http/workflow.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package http
1616
import (
1717
"io"
1818
"net/http"
19+
"strconv"
1920

2021
"github.com/go-chi/chi/v5"
2122
"github.com/google/uuid"
@@ -238,7 +239,21 @@ func (a *api) onTerminateWorkflowHandler() http.HandlerFunc {
238239
return UniversalHTTPHandler(
239240
a.universal.TerminateWorkflowBeta1,
240241
UniversalHTTPHandlerOpts[*runtimev1pb.TerminateWorkflowRequest, *emptypb.Empty]{
241-
InModifier: workflowInModifier[*runtimev1pb.TerminateWorkflowRequest],
242+
InModifier: func(r *http.Request, in *runtimev1pb.TerminateWorkflowRequest) (*runtimev1pb.TerminateWorkflowRequest, error) {
243+
in.SetWorkflowComponent(chi.URLParam(r, workflowComponent))
244+
in.SetInstanceId(chi.URLParam(r, instanceID))
245+
246+
// Extract non_recursive option from query string
247+
nonRecursive := r.URL.Query().Get(nonRecursive)
248+
if nonRecursive != "" {
249+
var err error
250+
in.NonRecursive, err = strconv.ParseBool(nonRecursive)
251+
if err != nil {
252+
return nil, err
253+
}
254+
}
255+
return in, nil
256+
},
242257
SuccessStatusCode: http.StatusAccepted,
243258
})
244259
}
@@ -292,7 +307,21 @@ func (a *api) onPurgeWorkflowHandler() http.HandlerFunc {
292307
return UniversalHTTPHandler(
293308
a.universal.PurgeWorkflowBeta1,
294309
UniversalHTTPHandlerOpts[*runtimev1pb.PurgeWorkflowRequest, *emptypb.Empty]{
295-
InModifier: workflowInModifier[*runtimev1pb.PurgeWorkflowRequest],
310+
InModifier: func(r *http.Request, in *runtimev1pb.PurgeWorkflowRequest) (*runtimev1pb.PurgeWorkflowRequest, error) {
311+
in.SetWorkflowComponent(chi.URLParam(r, workflowComponent))
312+
in.SetInstanceId(chi.URLParam(r, instanceID))
313+
314+
// Extract non_recursive option from query string
315+
nonRecursive := r.URL.Query().Get(nonRecursive)
316+
if nonRecursive != "" {
317+
var err error
318+
in.NonRecursive, err = strconv.ParseBool(nonRecursive)
319+
if err != nil {
320+
return nil, err
321+
}
322+
}
323+
return in, nil
324+
},
296325
SuccessStatusCode: http.StatusAccepted,
297326
})
298327
}

‎pkg/api/universal/workflow.go

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (a *Universal) TerminateWorkflowBeta1(ctx context.Context, in *runtimev1pb.
125125

126126
req := &workflows.TerminateRequest{
127127
InstanceID: in.GetInstanceId(),
128+
Recursive: !in.GetNonRecursive(),
128129
}
129130
if err := workflowComponent.Terminate(ctx, req); err != nil {
130131
if errors.Is(err, api.ErrInstanceNotFound) {
@@ -247,6 +248,7 @@ func (a *Universal) PurgeWorkflowBeta1(ctx context.Context, in *runtimev1pb.Purg
247248

248249
req := workflows.PurgeRequest{
249250
InstanceID: in.GetInstanceId(),
251+
Recursive: !in.GetNonRecursive(),
250252
}
251253

252254
err = workflowComponent.Purge(ctx, &req)

0 commit comments

Comments
 (0)
Please sign in to comment.