Skip to content

Commit 7e385ac

Browse files
authored
Add memo and search attributes to child workflow (#641)
1 parent 9898a41 commit 7e385ac

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/main/java/com/uber/cadence/internal/common/InternalUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.uber.cadence.History;
2424
import com.uber.cadence.HistoryEvent;
2525
import com.uber.cadence.HistoryEventFilterType;
26+
import com.uber.cadence.Memo;
2627
import com.uber.cadence.SearchAttributes;
2728
import com.uber.cadence.TaskList;
2829
import com.uber.cadence.TaskListKind;
@@ -142,6 +143,16 @@ public static Object getValueOrDefault(Object value, Class<?> valueClass) {
142143
return Defaults.defaultValue(valueClass);
143144
}
144145

146+
public static Memo convertMapToMemo(Map<String, Object> memo) {
147+
DataConverter converter = JsonDataConverter.getInstance();
148+
Map<String, ByteBuffer> mapOfByteBuffer = new HashMap<>();
149+
memo.forEach(
150+
(key, value) -> {
151+
mapOfByteBuffer.put(key, ByteBuffer.wrap(converter.toData(value)));
152+
});
153+
return new Memo().setFields(mapOfByteBuffer);
154+
}
155+
145156
public static SearchAttributes convertMapToSearchAttributes(
146157
Map<String, Object> searchAttributes) {
147158
DataConverter converter = JsonDataConverter.getInstance();

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public static final class Builder {
5151

5252
private String cronSchedule;
5353

54+
private Map<String, Object> memo;
55+
56+
private Map<String, Object> searchAttributes;
57+
5458
private Map<String, byte[]> context;
5559

5660
private ParentClosePolicy parentClosePolicy;
@@ -111,6 +115,16 @@ public Builder setCronSchedule(String cronSchedule) {
111115
return this;
112116
}
113117

118+
public Builder setMemo(Map<String, Object> memo) {
119+
this.memo = memo;
120+
return this;
121+
}
122+
123+
public Builder setSearchAttributes(Map<String, Object> searchAttributes) {
124+
this.searchAttributes = searchAttributes;
125+
return this;
126+
}
127+
114128
public Builder setContext(Map<String, byte[]> context) {
115129
this.context = context;
116130
return this;
@@ -134,6 +148,8 @@ public StartChildWorkflowExecutionParameters build() {
134148
workflowIdReusePolicy,
135149
retryParameters,
136150
cronSchedule,
151+
memo,
152+
searchAttributes,
137153
context,
138154
parentClosePolicy);
139155
}
@@ -161,6 +177,10 @@ public StartChildWorkflowExecutionParameters build() {
161177

162178
private final String cronSchedule;
163179

180+
private Map<String, Object> memo;
181+
182+
private Map<String, Object> searchAttributes;
183+
164184
private Map<String, byte[]> context;
165185

166186
private final ParentClosePolicy parentClosePolicy;
@@ -177,6 +197,8 @@ private StartChildWorkflowExecutionParameters(
177197
WorkflowIdReusePolicy workflowIdReusePolicy,
178198
RetryParameters retryParameters,
179199
String cronSchedule,
200+
Map<String, Object> memo,
201+
Map<String, Object> searchAttributes,
180202
Map<String, byte[]> context,
181203
ParentClosePolicy parentClosePolicy) {
182204
this.domain = domain;
@@ -190,6 +212,8 @@ private StartChildWorkflowExecutionParameters(
190212
this.workflowIdReusePolicy = workflowIdReusePolicy;
191213
this.retryParameters = retryParameters;
192214
this.cronSchedule = cronSchedule;
215+
this.memo = memo;
216+
this.searchAttributes = searchAttributes;
193217
this.context = context;
194218
this.parentClosePolicy = parentClosePolicy;
195219
}
@@ -238,6 +262,14 @@ public String getCronSchedule() {
238262
return cronSchedule;
239263
}
240264

265+
public Map<String, Object> getMemo() {
266+
return memo;
267+
}
268+
269+
public Map<String, Object> getSearchAttributes() {
270+
return searchAttributes;
271+
}
272+
241273
public Map<String, byte[]> getContext() {
242274
return context;
243275
}
@@ -262,6 +294,8 @@ public boolean equals(Object o) {
262294
&& workflowIdReusePolicy == that.workflowIdReusePolicy
263295
&& Objects.equals(retryParameters, that.retryParameters)
264296
&& Objects.equals(cronSchedule, that.cronSchedule)
297+
&& Objects.equals(memo, that.memo)
298+
&& Objects.equals(searchAttributes, that.searchAttributes)
265299
&& Objects.equals(context, that.context)
266300
&& Objects.equals(parentClosePolicy, that.parentClosePolicy);
267301
}
@@ -280,6 +314,8 @@ public int hashCode() {
280314
workflowIdReusePolicy,
281315
retryParameters,
282316
cronSchedule,
317+
memo,
318+
searchAttributes,
283319
context,
284320
parentClosePolicy);
285321
result = 31 * result + Arrays.hashCode(input);
@@ -315,6 +351,10 @@ public String toString() {
315351
+ retryParameters
316352
+ ", cronSchedule="
317353
+ cronSchedule
354+
+ ", memo="
355+
+ memo
356+
+ ", searchAttributes="
357+
+ searchAttributes
318358
+ ", context='"
319359
+ context
320360
+ ", parentClosePolicy="

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.uber.cadence.TaskList;
3838
import com.uber.cadence.WorkflowExecution;
3939
import com.uber.cadence.WorkflowType;
40+
import com.uber.cadence.internal.common.InternalUtils;
4041
import com.uber.cadence.internal.common.RetryParameters;
4142
import com.uber.cadence.workflow.ChildWorkflowTerminatedException;
4243
import com.uber.cadence.workflow.ChildWorkflowTimedOutException;
@@ -153,6 +154,17 @@ Consumer<Exception> startChildWorkflow(
153154
attributes.setParentClosePolicy(parentClosePolicy);
154155
}
155156

157+
Map<String, Object> memoMap = parameters.getMemo();
158+
if (memoMap != null) {
159+
attributes.setMemo(InternalUtils.convertMapToMemo(memoMap));
160+
}
161+
162+
Map<String, Object> searchAttributesMap = parameters.getSearchAttributes();
163+
if (searchAttributesMap != null) {
164+
attributes.setSearchAttributes(
165+
InternalUtils.convertMapToSearchAttributes(searchAttributesMap));
166+
}
167+
156168
long initiatedEventId = decisions.startChildWorkflowExecution(attributes);
157169
final OpenChildWorkflowRequestInfo context =
158170
new OpenChildWorkflowRequestInfo(executionCallback);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ private Promise<byte[]> executeChildWorkflow(
375375
.setTaskStartToCloseTimeout(options.getTaskStartToCloseTimeout())
376376
.setWorkflowId(options.getWorkflowId())
377377
.setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy())
378+
.setMemo(options.getMemo())
379+
.setSearchAttributes(options.getSearchAttributes())
378380
.setParentClosePolicy(options.getParentClosePolicy())
379381
.build();
380382
return WorkflowRetryerInternal.retryAsync(
@@ -412,6 +414,8 @@ private Promise<byte[]> executeChildWorkflowOnce(
412414
.setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy())
413415
.setRetryParameters(retryParameters)
414416
.setCronSchedule(options.getCronSchedule())
417+
.setMemo(options.getMemo())
418+
.setSearchAttributes(options.getSearchAttributes())
415419
.setContext(extractContextsAndConvertToBytes(propagators))
416420
.setParentClosePolicy(options.getParentClosePolicy())
417421
.build();

0 commit comments

Comments
 (0)