Skip to content

Commit 8ff8b85

Browse files
RemcoBuddelmeijermfateev
authored andcommitted
Implemented StartChildWorkflowExecutionParameters's ParentClosePolicy #433 (#437)
* Implemented StartChildWorkflowExecutionParameters's ParentClosePolicy #433 In order to support that ChildWorkflows have the ability to have a ParentClosePolicy, the field has to be added. * Added ParentClosePolicy to StateMachines #433 * Added ParentClosePolicy to testWorkflowInput #433
1 parent 854d161 commit 8ff8b85

File tree

7 files changed

+64
-12
lines changed

7 files changed

+64
-12
lines changed

src/main/java/com/uber/cadence/internal/replay/StartChildWorkflowExecutionParameters.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.uber.cadence.internal.replay;
1919

20+
import com.uber.cadence.ParentClosePolicy;
2021
import com.uber.cadence.WorkflowIdReusePolicy;
2122
import com.uber.cadence.WorkflowType;
2223
import com.uber.cadence.internal.common.RetryParameters;
@@ -49,6 +50,8 @@ public static final class Builder {
4950

5051
private String cronSchedule;
5152

53+
private ParentClosePolicy parentClosePolicy;
54+
5255
public Builder setDomain(String domain) {
5356
this.domain = domain;
5457
return this;
@@ -105,6 +108,11 @@ public Builder setCronSchedule(String cronSchedule) {
105108
return this;
106109
}
107110

111+
public Builder setParentClosePolicy(ParentClosePolicy parentClosePolicy) {
112+
this.parentClosePolicy = parentClosePolicy;
113+
return this;
114+
}
115+
108116
public StartChildWorkflowExecutionParameters build() {
109117
return new StartChildWorkflowExecutionParameters(
110118
domain,
@@ -117,7 +125,8 @@ public StartChildWorkflowExecutionParameters build() {
117125
workflowType,
118126
workflowIdReusePolicy,
119127
retryParameters,
120-
cronSchedule);
128+
cronSchedule,
129+
parentClosePolicy);
121130
}
122131
}
123132

@@ -143,6 +152,8 @@ public StartChildWorkflowExecutionParameters build() {
143152

144153
private final String cronSchedule;
145154

155+
private final ParentClosePolicy parentClosePolicy;
156+
146157
private StartChildWorkflowExecutionParameters(
147158
String domain,
148159
byte[] input,
@@ -154,7 +165,8 @@ private StartChildWorkflowExecutionParameters(
154165
WorkflowType workflowType,
155166
WorkflowIdReusePolicy workflowIdReusePolicy,
156167
RetryParameters retryParameters,
157-
String cronSchedule) {
168+
String cronSchedule,
169+
ParentClosePolicy parentClosePolicy) {
158170
this.domain = domain;
159171
this.input = input;
160172
this.control = control;
@@ -166,6 +178,7 @@ private StartChildWorkflowExecutionParameters(
166178
this.workflowIdReusePolicy = workflowIdReusePolicy;
167179
this.retryParameters = retryParameters;
168180
this.cronSchedule = cronSchedule;
181+
this.parentClosePolicy = parentClosePolicy;
169182
}
170183

171184
public String getDomain() {
@@ -212,6 +225,10 @@ public String getCronSchedule() {
212225
return cronSchedule;
213226
}
214227

228+
public ParentClosePolicy getParentClosePolicy() {
229+
return parentClosePolicy;
230+
}
231+
215232
@Override
216233
public boolean equals(Object o) {
217234
if (this == o) return true;
@@ -227,7 +244,8 @@ public boolean equals(Object o) {
227244
&& Objects.equals(workflowType, that.workflowType)
228245
&& workflowIdReusePolicy == that.workflowIdReusePolicy
229246
&& Objects.equals(retryParameters, that.retryParameters)
230-
&& Objects.equals(cronSchedule, that.cronSchedule);
247+
&& Objects.equals(cronSchedule, that.cronSchedule)
248+
&& Objects.equals(parentClosePolicy, that.parentClosePolicy);
231249
}
232250

233251
@Override
@@ -243,7 +261,8 @@ public int hashCode() {
243261
workflowType,
244262
workflowIdReusePolicy,
245263
retryParameters,
246-
cronSchedule);
264+
cronSchedule,
265+
parentClosePolicy);
247266
result = 31 * result + Arrays.hashCode(input);
248267
return result;
249268
}
@@ -277,6 +296,8 @@ public String toString() {
277296
+ retryParameters
278297
+ ", cronSchedule="
279298
+ cronSchedule
299+
+ ", parentClosePolicy="
300+
+ parentClosePolicy
280301
+ '}';
281302
}
282303
}

src/main/java/com/uber/cadence/internal/replay/WorkflowDecisionContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes;
2828
import com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes;
2929
import com.uber.cadence.HistoryEvent;
30+
import com.uber.cadence.ParentClosePolicy;
3031
import com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes;
3132
import com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes;
3233
import com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes;
@@ -143,6 +144,11 @@ Consumer<Exception> startChildWorkflow(
143144
attributes.setCronSchedule(parameters.getCronSchedule());
144145
}
145146

147+
ParentClosePolicy parentClosePolicy = parameters.getParentClosePolicy();
148+
if(parentClosePolicy != null) {
149+
attributes.setParentClosePolicy(parentClosePolicy);
150+
}
151+
146152
long initiatedEventId = decisions.startChildWorkflowExecution(attributes);
147153
final OpenChildWorkflowRequestInfo context =
148154
new OpenChildWorkflowRequestInfo(executionCallback);

src/main/java/com/uber/cadence/internal/sync/SyncDecisionContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ private Promise<byte[]> executeChildWorkflow(
353353
.setTaskStartToCloseTimeout(options.getTaskStartToCloseTimeout())
354354
.setWorkflowId(options.getWorkflowId())
355355
.setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy())
356+
.setParentClosePolicy(options.getParentClosePolicy())
356357
.build();
357358
return WorkflowRetryerInternal.retryAsync(
358359
retryOptions, () -> executeChildWorkflowOnce(name, o1, input, executionResult));
@@ -384,6 +385,7 @@ private Promise<byte[]> executeChildWorkflowOnce(
384385
.setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy())
385386
.setRetryParameters(retryParameters)
386387
.setCronSchedule(options.getCronSchedule())
388+
.setParentClosePolicy(options.getParentClosePolicy())
387389
.build();
388390
CompletablePromise<byte[]> result = Workflow.newPromise();
389391
Consumer<Exception> cancellationCallback =

src/main/java/com/uber/cadence/internal/testservice/StateMachines.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ private static void initiateChildWorkflow(
446446
.setWorkflowIdReusePolicy(d.getWorkflowIdReusePolicy())
447447
.setWorkflowType(d.getWorkflowType())
448448
.setRetryPolicy(d.getRetryPolicy())
449-
.setCronSchedule(d.getCronSchedule());
449+
.setCronSchedule(d.getCronSchedule())
450+
.setParentClosePolicy(d.getParentClosePolicy());
450451
HistoryEvent event =
451452
new HistoryEvent()
452453
.setEventType(EventType.StartChildWorkflowExecutionInitiated)

src/main/java/com/uber/cadence/workflow/ChildWorkflowOptions.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static com.uber.cadence.internal.common.OptionsUtils.roundUpToSeconds;
2121

22+
import com.uber.cadence.ParentClosePolicy;
2223
import com.uber.cadence.WorkflowIdReusePolicy;
2324
import com.uber.cadence.common.CronSchedule;
2425
import com.uber.cadence.common.MethodRetry;
@@ -76,6 +77,8 @@ public static final class Builder {
7677

7778
private String cronSchedule;
7879

80+
private ParentClosePolicy parentClosePolicy;
81+
7982
private Map<String, Object> memo;
8083

8184
private Map<String, Object> searchAttributes;
@@ -94,6 +97,7 @@ public Builder(ChildWorkflowOptions source) {
9497
this.taskList = source.getTaskList();
9598
this.retryOptions = source.getRetryOptions();
9699
this.cronSchedule = source.getCronSchedule();
100+
this.parentClosePolicy = source.getParentClosePolicy();
97101
this.memo = source.getMemo();
98102
this.searchAttributes = source.getSearchAttributes();
99103
}
@@ -188,6 +192,12 @@ public Builder setCronSchedule(String cronSchedule) {
188192
return this;
189193
}
190194

195+
/** Specifies how this workflow reacts to the death of the parent workflow. */
196+
public Builder setParentClosePolicy(ParentClosePolicy parentClosePolicy) {
197+
this.parentClosePolicy = parentClosePolicy;
198+
return this;
199+
}
200+
191201
/** Specifies additional non-indexed information in result of list workflow. */
192202
public Builder setMemo(Map<String, Object> memo) {
193203
this.memo = memo;
@@ -210,6 +220,7 @@ public ChildWorkflowOptions build() {
210220
taskList,
211221
retryOptions,
212222
cronSchedule,
223+
parentClosePolicy,
213224
memo,
214225
searchAttributes);
215226
}
@@ -224,6 +235,7 @@ public ChildWorkflowOptions validateAndBuildWithDefaults() {
224235
taskList,
225236
retryOptions,
226237
cronSchedule,
238+
parentClosePolicy,
227239
memo,
228240
searchAttributes);
229241
}
@@ -245,6 +257,8 @@ public ChildWorkflowOptions validateAndBuildWithDefaults() {
245257

246258
private final String cronSchedule;
247259

260+
private final ParentClosePolicy parentClosePolicy;
261+
248262
private final Map<String, Object> memo;
249263

250264
private final Map<String, Object> searchAttributes;
@@ -258,6 +272,7 @@ private ChildWorkflowOptions(
258272
String taskList,
259273
RetryOptions retryOptions,
260274
String cronSchedule,
275+
ParentClosePolicy parentClosePolicy,
261276
Map<String, Object> memo,
262277
Map<String, Object> searchAttributes) {
263278
this.domain = domain;
@@ -268,6 +283,7 @@ private ChildWorkflowOptions(
268283
this.taskList = taskList;
269284
this.retryOptions = retryOptions;
270285
this.cronSchedule = cronSchedule;
286+
this.parentClosePolicy = parentClosePolicy;
271287
this.memo = memo;
272288
this.searchAttributes = searchAttributes;
273289
}
@@ -304,6 +320,8 @@ public String getCronSchedule() {
304320
return cronSchedule;
305321
}
306322

323+
public ParentClosePolicy getParentClosePolicy() { return parentClosePolicy; }
324+
307325
public Map<String, Object> getMemo() {
308326
return memo;
309327
}
@@ -326,6 +344,7 @@ public boolean equals(Object o) {
326344
&& Objects.equals(taskList, that.taskList)
327345
&& Objects.equals(retryOptions, that.retryOptions)
328346
&& Objects.equals(cronSchedule, that.cronSchedule)
347+
&& Objects.equals(parentClosePolicy, that.parentClosePolicy)
329348
&& Objects.equals(memo, that.memo)
330349
&& Objects.equals(searchAttributes, that.searchAttributes);
331350
}
@@ -341,6 +360,7 @@ public int hashCode() {
341360
taskList,
342361
retryOptions,
343362
cronSchedule,
363+
parentClosePolicy,
344364
memo,
345365
searchAttributes);
346366
}
@@ -367,6 +387,8 @@ public String toString() {
367387
+ retryOptions
368388
+ ", cronSchedule="
369389
+ cronSchedule
390+
+ ", parentClosePolicy="
391+
+ parentClosePolicy
370392
+ ", memo='"
371393
+ memo
372394
+ '\''

src/test/resources/resetWorkflowHistory.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
},
162162
"executionStartToCloseTimeoutSeconds": 1000,
163163
"taskStartToCloseTimeoutSeconds": 10,
164-
"childPolicy": "TERMINATE",
164+
"parentClosePolicy": "TERMINATE",
165165
"decisionTaskCompletedEventId": 10,
166166
"workflowIdReusePolicy": "AllowDuplicateFailedOnly",
167167
"retryPolicy": {
@@ -432,7 +432,7 @@
432432
},
433433
"executionStartToCloseTimeoutSeconds": 1000,
434434
"taskStartToCloseTimeoutSeconds": 10,
435-
"childPolicy": "TERMINATE",
435+
"parentClosePolicy": "TERMINATE",
436436
"decisionTaskCompletedEventId": 28,
437437
"workflowIdReusePolicy": "AllowDuplicateFailedOnly",
438438
"retryPolicy": {
@@ -622,7 +622,7 @@
622622
},
623623
"executionStartToCloseTimeoutSeconds": 1000,
624624
"taskStartToCloseTimeoutSeconds": 10,
625-
"childPolicy": "TERMINATE",
625+
"parentClosePolicy": "TERMINATE",
626626
"decisionTaskCompletedEventId": 40,
627627
"workflowIdReusePolicy": "AllowDuplicateFailedOnly",
628628
"retryPolicy": {
@@ -1063,7 +1063,7 @@
10631063
},
10641064
"executionStartToCloseTimeoutSeconds": 1000,
10651065
"taskStartToCloseTimeoutSeconds": 10,
1066-
"childPolicy": "TERMINATE",
1066+
"parentClosePolicy": "TERMINATE",
10671067
"decisionTaskCompletedEventId": 70,
10681068
"workflowIdReusePolicy": "AllowDuplicateFailedOnly",
10691069
"retryPolicy": {

src/test/resources/testChildWorkflowRetryHistory.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"input": "IldvcmtmbG93VGVzdC10ZXN0Q2hpbGRXb3JrZmxvd1JldHJ5W0RvY2tlciBTdGlja3kgT05dLTdmMTY0MmE5LTkwOTItNGFiMS05ODIwLWZmZGY5ZWVjOTVjZSI=",
8282
"executionStartToCloseTimeoutSeconds": 500,
8383
"taskStartToCloseTimeoutSeconds": 2,
84-
"childPolicy": "TERMINATE",
84+
"parentClosePolicy": "TERMINATE",
8585
"decisionTaskCompletedEventId": 4,
8686
"workflowIdReusePolicy": "AllowDuplicateFailedOnly"
8787
}
@@ -277,7 +277,7 @@
277277
"input": "IldvcmtmbG93VGVzdC10ZXN0Q2hpbGRXb3JrZmxvd1JldHJ5W0RvY2tlciBTdGlja3kgT05dLTdmMTY0MmE5LTkwOTItNGFiMS05ODIwLWZmZGY5ZWVjOTVjZSI=",
278278
"executionStartToCloseTimeoutSeconds": 500,
279279
"taskStartToCloseTimeoutSeconds": 2,
280-
"childPolicy": "TERMINATE",
280+
"parentClosePolicy": "TERMINATE",
281281
"decisionTaskCompletedEventId": 19,
282282
"workflowIdReusePolicy": "AllowDuplicateFailedOnly"
283283
}
@@ -473,7 +473,7 @@
473473
"input": "IldvcmtmbG93VGVzdC10ZXN0Q2hpbGRXb3JrZmxvd1JldHJ5W0RvY2tlciBTdGlja3kgT05dLTdmMTY0MmE5LTkwOTItNGFiMS05ODIwLWZmZGY5ZWVjOTVjZSI=",
474474
"executionStartToCloseTimeoutSeconds": 500,
475475
"taskStartToCloseTimeoutSeconds": 2,
476-
"childPolicy": "TERMINATE",
476+
"parentClosePolicy": "TERMINATE",
477477
"decisionTaskCompletedEventId": 34,
478478
"workflowIdReusePolicy": "AllowDuplicateFailedOnly"
479479
}

0 commit comments

Comments
 (0)