Skip to content

Commit 24990db

Browse files
Ad support for local activity metadata (#2309)
1 parent c8a27ce commit 24990db

File tree

8 files changed

+172
-10
lines changed

8 files changed

+172
-10
lines changed

temporal-sdk/src/main/java/io/temporal/activity/LocalActivityOptions.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package io.temporal.activity;
2222

2323
import com.google.common.base.Objects;
24+
import io.temporal.common.Experimental;
2425
import io.temporal.common.MethodRetry;
2526
import io.temporal.common.RetryOptions;
2627
import java.time.Duration;
@@ -56,6 +57,7 @@ public static final class Builder {
5657
private Duration localRetryThreshold;
5758
private RetryOptions retryOptions;
5859
private Boolean doNotIncludeArgumentsIntoMarker;
60+
private String summary;
5961

6062
/** Copy Builder fields from the options. */
6163
private Builder(LocalActivityOptions options) {
@@ -68,6 +70,7 @@ private Builder(LocalActivityOptions options) {
6870
this.localRetryThreshold = options.getLocalRetryThreshold();
6971
this.retryOptions = options.getRetryOptions();
7072
this.doNotIncludeArgumentsIntoMarker = options.isDoNotIncludeArgumentsIntoMarker();
73+
this.summary = options.getSummary();
7174
}
7275

7376
/**
@@ -178,6 +181,18 @@ public Builder setDoNotIncludeArgumentsIntoMarker(boolean doNotIncludeArgumentsI
178181
return this;
179182
}
180183

184+
/**
185+
* Single-line fixed summary for this activity that will appear in UI/CLI. This can be in
186+
* single-line Temporal Markdown format.
187+
*
188+
* <p>Default is none/empty.
189+
*/
190+
@Experimental
191+
public Builder setSummary(String summary) {
192+
this.summary = summary;
193+
return this;
194+
}
195+
181196
public Builder mergeActivityOptions(LocalActivityOptions override) {
182197
if (override == null) {
183198
return this;
@@ -204,6 +219,7 @@ public Builder mergeActivityOptions(LocalActivityOptions override) {
204219
(override.doNotIncludeArgumentsIntoMarker != null)
205220
? override.doNotIncludeArgumentsIntoMarker
206221
: this.doNotIncludeArgumentsIntoMarker;
222+
this.summary = (override.summary == null) ? this.summary : override.summary;
207223
return this;
208224
}
209225

@@ -214,7 +230,8 @@ public LocalActivityOptions build() {
214230
scheduleToStartTimeout,
215231
localRetryThreshold,
216232
retryOptions,
217-
doNotIncludeArgumentsIntoMarker);
233+
doNotIncludeArgumentsIntoMarker,
234+
summary);
218235
}
219236

220237
public LocalActivityOptions validateAndBuildWithDefaults() {
@@ -228,7 +245,8 @@ public LocalActivityOptions validateAndBuildWithDefaults() {
228245
scheduleToStartTimeout,
229246
localRetryThreshold,
230247
RetryOptions.newBuilder(retryOptions).validateBuildWithDefaults(),
231-
doNotIncludeArgumentsIntoMarker);
248+
doNotIncludeArgumentsIntoMarker,
249+
summary);
232250
}
233251
}
234252

@@ -238,20 +256,23 @@ public LocalActivityOptions validateAndBuildWithDefaults() {
238256
private final Duration scheduleToStartTimeout;
239257
private final RetryOptions retryOptions;
240258
private final Boolean doNotIncludeArgumentsIntoMarker;
259+
private final String summary;
241260

242261
private LocalActivityOptions(
243262
Duration startToCloseTimeout,
244263
Duration scheduleToCloseTimeout,
245264
Duration scheduleToStartTimeout,
246265
Duration localRetryThreshold,
247266
RetryOptions retryOptions,
248-
Boolean doNotIncludeArgumentsIntoMarker) {
267+
Boolean doNotIncludeArgumentsIntoMarker,
268+
String summary) {
249269
this.scheduleToCloseTimeout = scheduleToCloseTimeout;
250270
this.startToCloseTimeout = startToCloseTimeout;
251271
this.scheduleToStartTimeout = scheduleToStartTimeout;
252272
this.localRetryThreshold = localRetryThreshold;
253273
this.retryOptions = retryOptions;
254274
this.doNotIncludeArgumentsIntoMarker = doNotIncludeArgumentsIntoMarker;
275+
this.summary = summary;
255276
}
256277

257278
public Duration getScheduleToCloseTimeout() {
@@ -278,6 +299,11 @@ public boolean isDoNotIncludeArgumentsIntoMarker() {
278299
return doNotIncludeArgumentsIntoMarker != null && doNotIncludeArgumentsIntoMarker;
279300
}
280301

302+
@Experimental
303+
public String getSummary() {
304+
return summary;
305+
}
306+
281307
public Builder toBuilder() {
282308
return new Builder(this);
283309
}
@@ -292,7 +318,8 @@ public boolean equals(Object o) {
292318
&& Objects.equal(startToCloseTimeout, that.startToCloseTimeout)
293319
&& Objects.equal(scheduleToStartTimeout, that.scheduleToStartTimeout)
294320
&& Objects.equal(localRetryThreshold, that.localRetryThreshold)
295-
&& Objects.equal(retryOptions, that.retryOptions);
321+
&& Objects.equal(retryOptions, that.retryOptions)
322+
&& Objects.equal(summary, that.summary);
296323
}
297324

298325
@Override
@@ -303,7 +330,8 @@ public int hashCode() {
303330
scheduleToStartTimeout,
304331
localRetryThreshold,
305332
retryOptions,
306-
doNotIncludeArgumentsIntoMarker);
333+
doNotIncludeArgumentsIntoMarker,
334+
summary);
307335
}
308336

309337
@Override
@@ -319,6 +347,8 @@ public String toString() {
319347
+ retryOptions
320348
+ ", doNotIncludeArgumentsIntoMarker="
321349
+ isDoNotIncludeArgumentsIntoMarker()
350+
+ ", summary="
351+
+ summary
322352
+ '}';
323353
}
324354
}

temporal-sdk/src/main/java/io/temporal/internal/statemachines/ExecuteLocalActivityParameters.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.temporal.api.common.v1.ActivityType;
2424
import io.temporal.api.common.v1.Payloads;
2525
import io.temporal.api.failure.v1.Failure;
26+
import io.temporal.api.sdk.v1.UserMetadata;
2627
import io.temporal.api.workflowservice.v1.PollActivityTaskQueueResponse;
2728
import io.temporal.internal.common.ProtobufTimeUtils;
2829
import io.temporal.workflow.Functions;
@@ -51,21 +52,24 @@ public class ExecuteLocalActivityParameters {
5152
private final boolean doNotIncludeArgumentsIntoMarker;
5253
private final @Nullable Duration scheduleToStartTimeout;
5354
private @Nullable Functions.Proc onNewAttemptCallback;
55+
private final UserMetadata metadata;
5456

5557
public ExecuteLocalActivityParameters(
5658
@Nonnull PollActivityTaskQueueResponse.Builder activityTaskBuilder,
5759
@Nullable Duration scheduleToStartTimeout,
5860
long originalScheduledTimestamp,
5961
@Nullable Failure previousLocalExecutionFailure,
6062
boolean doNotIncludeArgumentsIntoMarker,
61-
@Nonnull Duration localRetryThreshold) {
63+
@Nonnull Duration localRetryThreshold,
64+
UserMetadata metadata) {
6265
this.activityTaskBuilder = Objects.requireNonNull(activityTaskBuilder, "activityTaskBuilder");
6366
this.scheduleToStartTimeout = scheduleToStartTimeout;
6467
this.originalScheduledTimestamp = originalScheduledTimestamp;
6568
this.previousLocalExecutionFailure = previousLocalExecutionFailure;
6669
this.doNotIncludeArgumentsIntoMarker = doNotIncludeArgumentsIntoMarker;
6770
this.localRetryThreshold = localRetryThreshold;
6871
this.onNewAttemptCallback = null;
72+
this.metadata = metadata;
6973
}
7074

7175
public String getActivityId() {
@@ -136,4 +140,8 @@ public Functions.Proc getOnNewAttemptCallback() {
136140
public void setOnNewAttemptCallback(@Nonnull Functions.Proc onNewAttemptCallback) {
137141
this.onNewAttemptCallback = onNewAttemptCallback;
138142
}
143+
144+
public UserMetadata getMetadata() {
145+
return metadata;
146+
}
139147
}

temporal-sdk/src/main/java/io/temporal/internal/statemachines/LocalActivityStateMachine.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.temporal.api.failure.v1.CanceledFailureInfo;
3232
import io.temporal.api.failure.v1.Failure;
3333
import io.temporal.api.history.v1.MarkerRecordedEventAttributes;
34+
import io.temporal.api.sdk.v1.UserMetadata;
3435
import io.temporal.api.workflowservice.v1.RespondActivityTaskCanceledRequest;
3536
import io.temporal.api.workflowservice.v1.RespondActivityTaskCompletedRequest;
3637
import io.temporal.common.converter.DefaultDataConverter;
@@ -63,6 +64,7 @@ final class LocalActivityStateMachine
6364
private final LocalActivityCallback callback;
6465

6566
private ExecuteLocalActivityParameters localActivityParameters;
67+
private @Nullable UserMetadata userMetadata;
6668
private final Functions.Func<Boolean> replaying;
6769

6870
/** Accepts proposed current time. Returns accepted current time. */
@@ -211,6 +213,7 @@ private LocalActivityStateMachine(
211213
this.replaying = replaying;
212214
this.setCurrentTimeCallback = setCurrentTimeCallback;
213215
this.localActivityParameters = localActivityParameters;
216+
this.userMetadata = localActivityParameters.getMetadata();
214217
this.activityId = localActivityParameters.getActivityId();
215218
this.activityType = localActivityParameters.getActivityType();
216219
this.originalScheduledTimestamp = localActivityParameters.getOriginalScheduledTimestamp();
@@ -342,11 +345,15 @@ private void createMarker() {
342345
DefaultDataConverter.STANDARD_INSTANCE.toPayloads(localActivityMarkerMetadata).get());
343346
markerAttributes.putAllDetails(details);
344347
}
345-
addCommand(
348+
Command.Builder command =
346349
Command.newBuilder()
347350
.setCommandType(CommandType.COMMAND_TYPE_RECORD_MARKER)
348-
.setRecordMarkerCommandAttributes(markerAttributes.build())
349-
.build());
351+
.setRecordMarkerCommandAttributes(markerAttributes.build());
352+
if (userMetadata != null) {
353+
command.setUserMetadata(userMetadata);
354+
userMetadata = null;
355+
}
356+
addCommand(command.build());
350357
}
351358

352359
private void notifyResultFromEvent() {

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,18 @@ private ExecuteLocalActivityParameters constructExecuteLocalActivityParameters(
680680
localRetryThreshold = replayContext.getWorkflowTaskTimeout().multipliedBy(3);
681681
}
682682

683+
@Nullable
684+
UserMetadata userMetadata =
685+
makeUserMetaData(options.getSummary(), null, dataConverterWithCurrentWorkflowContext);
686+
683687
return new ExecuteLocalActivityParameters(
684688
activityTask,
685689
options.getScheduleToStartTimeout(),
686690
originalScheduledTime,
687691
previousExecutionFailure,
688692
options.isDoNotIncludeArgumentsIntoMarker(),
689-
localRetryThreshold);
693+
localRetryThreshold,
694+
userMetadata);
690695
}
691696

692697
@Override

temporal-sdk/src/test/java/io/temporal/internal/replay/OutdatedDirectQueryReplayWorkflowRunTaskHandlerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private ReplayWorkflow createReplayWorkflow(WorkflowExecutionHistory workflowExe
159159
System.currentTimeMillis(),
160160
null,
161161
false,
162+
null,
162163
null),
163164
(r, e) -> {});
164165
return false;

temporal-sdk/src/test/java/io/temporal/internal/replay/ReplayWorkflowRunTaskHandlerTaskHandlerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public void localActivityMeteringHelper() {
151151
0,
152152
null,
153153
false,
154+
null,
154155
null);
155156
laMeteringHelper.addNewLocalActivity(executeLA);
156157
laMeteringHelper.addNewLocalActivity(
@@ -160,6 +161,7 @@ public void localActivityMeteringHelper() {
160161
0,
161162
null,
162163
false,
164+
null,
163165
null));
164166
for (int i = 0; i < 5; i++) {
165167
executeLA.getOnNewAttemptCallback().apply();

temporal-sdk/src/test/java/io/temporal/internal/statemachines/LocalActivityStateMachineTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
102102
System.currentTimeMillis(),
103103
null,
104104
true,
105+
null,
105106
null);
106107
ExecuteLocalActivityParameters parameters2 =
107108
new ExecuteLocalActivityParameters(
@@ -112,6 +113,7 @@ protected void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
112113
System.currentTimeMillis(),
113114
null,
114115
false,
116+
null,
115117
null);
116118
ExecuteLocalActivityParameters parameters3 =
117119
new ExecuteLocalActivityParameters(
@@ -122,6 +124,7 @@ protected void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
122124
System.currentTimeMillis(),
123125
null,
124126
true,
127+
null,
125128
null);
126129

127130
builder
@@ -303,6 +306,7 @@ protected void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
303306
System.currentTimeMillis(),
304307
null,
305308
false,
309+
null,
306310
null);
307311
builder
308312
.<Optional<Payloads>, LocalActivityCallback.LocalActivityFailedException>add2(
@@ -368,6 +372,7 @@ protected void buildWorkflow(AsyncWorkflowBuilder<Void> builder) {
368372
System.currentTimeMillis(),
369373
null,
370374
false,
375+
null,
371376
null);
372377
// TODO: This is a workaround for the lack of support for child workflow in the test
373378
// framework.

0 commit comments

Comments
 (0)