Skip to content

Commit 52aefa0

Browse files
authored
Merge pull request #2 from uber/master
Merging from master
2 parents 6924727 + 06174b4 commit 52aefa0

File tree

7 files changed

+65
-12
lines changed

7 files changed

+65
-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: 23 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;
@@ -53,6 +54,7 @@ public static ChildWorkflowOptions merge(
5354
.setTaskList(OptionsUtils.merge(a.taskList(), o.getTaskList(), String.class))
5455
.setRetryOptions(RetryOptions.merge(r, o.getRetryOptions()))
5556
.setCronSchedule(OptionsUtils.merge(cronAnnotation, o.getCronSchedule(), String.class))
57+
.setParentClosePolicy(o.getParentClosePolicy())
5658
.setMemo(o.getMemo())
5759
.setSearchAttributes(o.getSearchAttributes())
5860
.validateAndBuildWithDefaults();
@@ -76,6 +78,8 @@ public static final class Builder {
7678

7779
private String cronSchedule;
7880

81+
private ParentClosePolicy parentClosePolicy;
82+
7983
private Map<String, Object> memo;
8084

8185
private Map<String, Object> searchAttributes;
@@ -94,6 +98,7 @@ public Builder(ChildWorkflowOptions source) {
9498
this.taskList = source.getTaskList();
9599
this.retryOptions = source.getRetryOptions();
96100
this.cronSchedule = source.getCronSchedule();
101+
this.parentClosePolicy = source.getParentClosePolicy();
97102
this.memo = source.getMemo();
98103
this.searchAttributes = source.getSearchAttributes();
99104
}
@@ -188,6 +193,12 @@ public Builder setCronSchedule(String cronSchedule) {
188193
return this;
189194
}
190195

196+
/** Specifies how this workflow reacts to the death of the parent workflow. */
197+
public Builder setParentClosePolicy(ParentClosePolicy parentClosePolicy) {
198+
this.parentClosePolicy = parentClosePolicy;
199+
return this;
200+
}
201+
191202
/** Specifies additional non-indexed information in result of list workflow. */
192203
public Builder setMemo(Map<String, Object> memo) {
193204
this.memo = memo;
@@ -210,6 +221,7 @@ public ChildWorkflowOptions build() {
210221
taskList,
211222
retryOptions,
212223
cronSchedule,
224+
parentClosePolicy,
213225
memo,
214226
searchAttributes);
215227
}
@@ -224,6 +236,7 @@ public ChildWorkflowOptions validateAndBuildWithDefaults() {
224236
taskList,
225237
retryOptions,
226238
cronSchedule,
239+
parentClosePolicy,
227240
memo,
228241
searchAttributes);
229242
}
@@ -245,6 +258,8 @@ public ChildWorkflowOptions validateAndBuildWithDefaults() {
245258

246259
private final String cronSchedule;
247260

261+
private final ParentClosePolicy parentClosePolicy;
262+
248263
private final Map<String, Object> memo;
249264

250265
private final Map<String, Object> searchAttributes;
@@ -258,6 +273,7 @@ private ChildWorkflowOptions(
258273
String taskList,
259274
RetryOptions retryOptions,
260275
String cronSchedule,
276+
ParentClosePolicy parentClosePolicy,
261277
Map<String, Object> memo,
262278
Map<String, Object> searchAttributes) {
263279
this.domain = domain;
@@ -268,6 +284,7 @@ private ChildWorkflowOptions(
268284
this.taskList = taskList;
269285
this.retryOptions = retryOptions;
270286
this.cronSchedule = cronSchedule;
287+
this.parentClosePolicy = parentClosePolicy;
271288
this.memo = memo;
272289
this.searchAttributes = searchAttributes;
273290
}
@@ -304,6 +321,8 @@ public String getCronSchedule() {
304321
return cronSchedule;
305322
}
306323

324+
public ParentClosePolicy getParentClosePolicy() { return parentClosePolicy; }
325+
307326
public Map<String, Object> getMemo() {
308327
return memo;
309328
}
@@ -326,6 +345,7 @@ public boolean equals(Object o) {
326345
&& Objects.equals(taskList, that.taskList)
327346
&& Objects.equals(retryOptions, that.retryOptions)
328347
&& Objects.equals(cronSchedule, that.cronSchedule)
348+
&& Objects.equals(parentClosePolicy, that.parentClosePolicy)
329349
&& Objects.equals(memo, that.memo)
330350
&& Objects.equals(searchAttributes, that.searchAttributes);
331351
}
@@ -341,6 +361,7 @@ public int hashCode() {
341361
taskList,
342362
retryOptions,
343363
cronSchedule,
364+
parentClosePolicy,
344365
memo,
345366
searchAttributes);
346367
}
@@ -367,6 +388,8 @@ public String toString() {
367388
+ retryOptions
368389
+ ", cronSchedule="
369390
+ cronSchedule
391+
+ ", parentClosePolicy="
392+
+ parentClosePolicy
370393
+ ", memo='"
371394
+ memo
372395
+ '\''

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)