Skip to content

Commit caa9902

Browse files
committed
initial commit
1 parent dd2564b commit caa9902

6 files changed

Lines changed: 571 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.microsoft.durabletask;
4+
5+
import java.util.Objects;
6+
import javax.annotation.Nullable;
7+
8+
/**
9+
* Represents the parent orchestration of a sub-orchestration.
10+
* This is available via {@link TaskOrchestrationContext#getParent()} when the
11+
* current orchestration was started as a sub-orchestration.
12+
*/
13+
public final class ParentOrchestrationInstance {
14+
private final String name;
15+
private final String instanceId;
16+
17+
/**
18+
* Creates a new ParentOrchestrationInstance.
19+
*
20+
* @param name the name of the parent orchestration
21+
* @param instanceId the instance ID of the parent orchestration
22+
*/
23+
public ParentOrchestrationInstance(String name, String instanceId) {
24+
this.name = name;
25+
this.instanceId = instanceId;
26+
}
27+
28+
/**
29+
* Gets the name of the parent orchestration.
30+
*
31+
* @return the parent orchestration name
32+
*/
33+
@Nullable
34+
public String getName() {
35+
return this.name;
36+
}
37+
38+
/**
39+
* Gets the instance ID of the parent orchestration.
40+
*
41+
* @return the parent orchestration instance ID
42+
*/
43+
@Nullable
44+
public String getInstanceId() {
45+
return this.instanceId;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return String.format("ParentOrchestrationInstance{name='%s', instanceId='%s'}", name, instanceId);
51+
}
52+
53+
@Override
54+
public boolean equals(Object o) {
55+
if (this == o) return true;
56+
if (!(o instanceof ParentOrchestrationInstance)) return false;
57+
ParentOrchestrationInstance that = (ParentOrchestrationInstance) o;
58+
return Objects.equals(name, that.name) && Objects.equals(instanceId, that.instanceId);
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return Objects.hash(name, instanceId);
64+
}
65+
}

client/src/main/java/com/microsoft/durabletask/TaskOrchestrationContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,17 @@ default Task<AutoCloseable> lockEntities(@Nonnull EntityInstanceId... entityIds)
794794
*/
795795
void clearCustomStatus();
796796

797+
/**
798+
* Gets the parent orchestration instance, or {@code null} if this orchestration
799+
* was not started as a sub-orchestration.
800+
*
801+
* @return the parent orchestration instance, or {@code null}
802+
*/
803+
@Nullable
804+
default ParentOrchestrationInstance getParent() {
805+
return null;
806+
}
807+
797808
/**
798809
* Makes a durable HTTP request using the specified {@link DurableHttpRequest} and returns a {@link Task}
799810
* that completes when the HTTP call completes.

client/src/main/java/com/microsoft/durabletask/TaskOrchestrationExecutor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ private class ContextImplTask implements TaskOrchestrationContext {
146146
private boolean preserveUnprocessedEvents;
147147
private Object customStatus;
148148
private TraceContext parentTraceContext;
149+
private ParentOrchestrationInstance parentInstance;
149150

150151
// Entity integration state (Phase 4)
151152
private String executionId;
@@ -207,6 +208,12 @@ public String getInstanceId() {
207208
return this.instanceId;
208209
}
209210

211+
@Override
212+
@Nullable
213+
public ParentOrchestrationInstance getParent() {
214+
return this.parentInstance;
215+
}
216+
210217
private void setInstanceId(String instanceId) {
211218
// TODO: Throw if instance ID is not null
212219
this.instanceId = instanceId;
@@ -1705,6 +1712,14 @@ private void processEvent(HistoryEvent e) {
17051712
} else {
17061713
this.parentTraceContext = null;
17071714
}
1715+
if (startedEvent.hasParentInstance()) {
1716+
ParentInstanceInfo parentInfo = startedEvent.getParentInstance();
1717+
this.parentInstance = new ParentOrchestrationInstance(
1718+
parentInfo.getName().getValue(),
1719+
parentInfo.getOrchestrationInstance().getInstanceId());
1720+
} else {
1721+
this.parentInstance = null;
1722+
}
17081723
TaskOrchestrationFactory factory = TaskOrchestrationExecutor.this.orchestrationFactories.get(name);
17091724
if (factory == null) {
17101725
// Try getting the default orchestrator

0 commit comments

Comments
 (0)