Skip to content

Commit 334e129

Browse files
Add support for metadata to test server (#2441)
Add support for metadata to test server
1 parent 0271192 commit 334e129

File tree

17 files changed

+265
-81
lines changed

17 files changed

+265
-81
lines changed

temporal-sdk/src/main/java/io/temporal/client/WorkflowExecutionDescription.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,70 @@
2121
package io.temporal.client;
2222

2323
import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse;
24+
import io.temporal.common.Experimental;
2425
import io.temporal.common.converter.DataConverter;
26+
import io.temporal.payload.context.WorkflowSerializationContext;
2527
import javax.annotation.Nonnull;
28+
import javax.annotation.Nullable;
2629

2730
/** Contains information about a workflow execution. */
2831
public class WorkflowExecutionDescription extends WorkflowExecutionMetadata {
32+
private final @Nonnull DataConverter dataConverter;
2933
private final @Nonnull DescribeWorkflowExecutionResponse response;
3034

3135
public WorkflowExecutionDescription(
3236
@Nonnull DescribeWorkflowExecutionResponse response, @Nonnull DataConverter dataConverter) {
3337
super(response.getWorkflowExecutionInfo(), dataConverter);
38+
this.dataConverter = dataConverter;
3439
this.response = response;
3540
}
3641

42+
/**
43+
* Get the fixed summary for this workflow execution.
44+
*
45+
* @apiNote Will be decoded on each invocation, so it is recommended to cache the result if it is
46+
* used multiple times.
47+
*/
48+
@Experimental
49+
@Nullable
50+
public String getStaticSummary() {
51+
if (!response.getExecutionConfig().getUserMetadata().hasSummary()) {
52+
return null;
53+
}
54+
return dataConverter
55+
.withContext(
56+
new WorkflowSerializationContext(
57+
response.getWorkflowExecutionInfo().getParentNamespaceId(),
58+
response.getWorkflowExecutionInfo().getExecution().getWorkflowId()))
59+
.fromPayload(
60+
response.getExecutionConfig().getUserMetadata().getSummary(),
61+
String.class,
62+
String.class);
63+
}
64+
65+
/**
66+
* Get the details summary for this workflow execution.
67+
*
68+
* @apiNote Will be decoded on each invocation, so it is recommended to cache the result if it is
69+
* used multiple times.
70+
*/
71+
@Experimental
72+
@Nullable
73+
public String getStaticDetails() {
74+
if (!response.getExecutionConfig().getUserMetadata().hasDetails()) {
75+
return null;
76+
}
77+
return dataConverter
78+
.withContext(
79+
new WorkflowSerializationContext(
80+
response.getWorkflowExecutionInfo().getParentNamespaceId(),
81+
response.getWorkflowExecutionInfo().getExecution().getWorkflowId()))
82+
.fromPayload(
83+
response.getExecutionConfig().getUserMetadata().getDetails(),
84+
String.class,
85+
String.class);
86+
}
87+
3788
/** Returns the raw response from the Temporal service. */
3889
public DescribeWorkflowExecutionResponse getRawDescription() {
3990
return response;

temporal-sdk/src/main/java/io/temporal/client/WorkflowExecutionMetadata.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.temporal.internal.common.SearchAttributesUtil;
3232
import io.temporal.payload.context.WorkflowSerializationContext;
3333
import java.lang.reflect.Type;
34+
import java.time.Duration;
3435
import java.time.Instant;
3536
import java.util.Collections;
3637
import java.util.List;
@@ -98,6 +99,23 @@ public WorkflowExecution getParentExecution() {
9899
return info.hasParentExecution() ? info.getParentExecution() : null;
99100
}
100101

102+
@Nullable
103+
public WorkflowExecution getRootExecution() {
104+
return info.hasRootExecution() ? info.getRootExecution() : null;
105+
}
106+
107+
@Nullable
108+
public String getFirstRunId() {
109+
return info.getFirstRunId();
110+
}
111+
112+
@Nullable
113+
public Duration getExecutionDuration() {
114+
return info.hasExecutionDuration()
115+
? ProtobufTimeUtils.toJavaDuration(info.getExecutionDuration())
116+
: null;
117+
}
118+
101119
/**
102120
* @deprecated use {@link #getTypedSearchAttributes} instead.
103121
*/

temporal-sdk/src/main/java/io/temporal/internal/replay/BasicWorkflowContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ WorkflowExecution getParentWorkflowExecution() {
9696
: null;
9797
}
9898

99+
WorkflowExecution getRootWorkflowExecution() {
100+
return startedAttributes.hasRootWorkflowExecution()
101+
? startedAttributes.getRootWorkflowExecution()
102+
: null;
103+
}
104+
99105
Duration getWorkflowRunTimeout() {
100106
return ProtobufTimeUtils.toJavaDuration(startedAttributes.getWorkflowRunTimeout());
101107
}

temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public Functions.Proc1<Exception> getCancellationHandle() {
7878

7979
WorkflowExecution getParentWorkflowExecution();
8080

81+
WorkflowExecution getRootWorkflowExecution();
82+
8183
WorkflowType getWorkflowType();
8284

8385
/**

temporal-sdk/src/main/java/io/temporal/internal/replay/ReplayWorkflowContextImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public WorkflowExecution getParentWorkflowExecution() {
108108
return basicWorkflowContext.getParentWorkflowExecution();
109109
}
110110

111+
@Override
112+
public WorkflowExecution getRootWorkflowExecution() {
113+
return basicWorkflowContext.getRootWorkflowExecution();
114+
}
115+
111116
@Override
112117
public String getFirstExecutionRunId() {
113118
return basicWorkflowContext.getFirstExecutionRunId();

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public Optional<String> getParentRunId() {
125125
: Optional.of(parentWorkflowExecution.getRunId());
126126
}
127127

128+
public String getRootWorkflowId() {
129+
WorkflowExecution rootWorkflowExecution = context.getRootWorkflowExecution();
130+
return rootWorkflowExecution == null ? null : rootWorkflowExecution.getWorkflowId();
131+
}
132+
133+
@Override
134+
public String getRootRunId() {
135+
WorkflowExecution rootWorkflowExecution = context.getRootWorkflowExecution();
136+
return rootWorkflowExecution == null ? null : rootWorkflowExecution.getRunId();
137+
}
138+
128139
@Override
129140
public int getAttempt() {
130141
return context.getAttempt();
@@ -183,6 +194,10 @@ public String toString() {
183194
+ getParentWorkflowId()
184195
+ ", parentRunId="
185196
+ getParentRunId()
197+
+ ", rootWorkflowId="
198+
+ getRootWorkflowId()
199+
+ ", rootRunId="
200+
+ getRootRunId()
186201
+ ", attempt="
187202
+ getAttempt()
188203
+ ", cronSchedule="

temporal-sdk/src/main/java/io/temporal/workflow/ChildWorkflowOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,12 @@ public VersioningIntent getVersioningIntent() {
507507
return versioningIntent;
508508
}
509509

510+
@Experimental
510511
public String getStaticSummary() {
511512
return staticSummary;
512513
}
513514

515+
@Experimental
514516
public String getStaticDetails() {
515517
return staticDetails;
516518
}

temporal-sdk/src/main/java/io/temporal/workflow/WorkflowInfo.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ public interface WorkflowInfo {
136136
*/
137137
Optional<String> getParentRunId();
138138

139+
/**
140+
* @return Workflow ID of the root Workflow
141+
* @apiNote On server versions prior to v1.27.0, this method will return null. Otherwise, it will
142+
* always return a non-null value.
143+
*/
144+
@Nullable
145+
String getRootWorkflowId();
146+
147+
/**
148+
* @return Run ID of the root Workflow
149+
* @apiNote On server versions prior to v1.27.0, this method will return null. Otherwise, it will
150+
* always return a non-null value.
151+
*/
152+
@Nullable
153+
String getRootRunId();
154+
139155
/**
140156
* @return Workflow retry attempt handled by this Workflow code execution. Starts on "1".
141157
*/

temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityMetadataTest.java

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

2323
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assume.assumeTrue;
2524

2625
import io.temporal.activity.ActivityOptions;
2726
import io.temporal.api.common.v1.WorkflowExecution;
@@ -36,7 +35,6 @@
3635
import java.time.Duration;
3736
import java.util.List;
3837
import java.util.stream.Collectors;
39-
import org.junit.Before;
4038
import org.junit.Rule;
4139
import org.junit.Test;
4240

@@ -51,11 +49,6 @@ public class ActivityMetadataTest {
5149

5250
static final String activitySummary = "activity-summary";
5351

54-
@Before
55-
public void checkRealServer() {
56-
assumeTrue("skipping for test server", SDKTestWorkflowRule.useExternalService);
57-
}
58-
5952
@Test
6053
public void testActivityWithMetaData() {
6154
TestWorkflow1 stub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class);

temporal-sdk/src/test/java/io/temporal/workflow/activityTests/LocalActivityMetadataTest.java

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

2323
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assume.assumeTrue;
2524

2625
import io.temporal.activity.LocalActivityOptions;
2726
import io.temporal.api.common.v1.WorkflowExecution;
@@ -36,7 +35,6 @@
3635
import java.time.Duration;
3736
import java.util.List;
3837
import java.util.stream.Collectors;
39-
import org.junit.Before;
4038
import org.junit.Rule;
4139
import org.junit.Test;
4240

@@ -51,11 +49,6 @@ public class LocalActivityMetadataTest {
5149

5250
static final String localActivitySummary = "local-activity-summary";
5351

54-
@Before
55-
public void checkRealServer() {
56-
assumeTrue("skipping for test server", SDKTestWorkflowRule.useExternalService);
57-
}
58-
5952
@Test
6053
public void testLocalActivityWithMetaData() {
6154
TestWorkflow1 stub = testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class);

0 commit comments

Comments
 (0)