Skip to content

Commit ef1fc22

Browse files
artur-ciocanuArtur Ciocanu
andauthored
Ensure DurableTask classes are hidden in Workflow Runtime package (dapr#1311)
* Ensure DurableTask classes are hidden in Workflow Runtime package Signed-off-by: Artur Ciocanu <[email protected]> * Fix the file header Signed-off-by: Artur Ciocanu <[email protected]> --------- Signed-off-by: Artur Ciocanu <[email protected]> Co-authored-by: Artur Ciocanu <[email protected]>
1 parent 8cb8099 commit ef1fc22

13 files changed

+601
-461
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/client/DaprWorkflowClient.java

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
import com.microsoft.durabletask.DurableTaskClient;
1717
import com.microsoft.durabletask.DurableTaskGrpcClientBuilder;
18+
import com.microsoft.durabletask.NewOrchestrationInstanceOptions;
1819
import com.microsoft.durabletask.OrchestrationMetadata;
1920
import com.microsoft.durabletask.PurgeResult;
2021
import io.dapr.config.Properties;
2122
import io.dapr.utils.NetworkUtils;
2223
import io.dapr.workflows.Workflow;
2324
import io.dapr.workflows.internal.ApiTokenClientInterceptor;
25+
import io.dapr.workflows.runtime.DefaultWorkflowInstanceStatus;
2426
import io.grpc.ClientInterceptor;
2527
import io.grpc.ManagedChannel;
2628

@@ -76,18 +78,6 @@ private DaprWorkflowClient(DurableTaskClient innerClient, ManagedChannel grpcCha
7678
this.grpcChannel = grpcChannel;
7779
}
7880

79-
/**
80-
* Static method to create the DurableTaskClient.
81-
*
82-
* @param grpcChannel ManagedChannel for GRPC.
83-
* @return a new instance of a DurableTaskClient with a GRPC channel.
84-
*/
85-
private static DurableTaskClient createDurableTaskClient(ManagedChannel grpcChannel) {
86-
return new DurableTaskGrpcClientBuilder()
87-
.grpcChannel(grpcChannel)
88-
.build();
89-
}
90-
9181
/**
9282
* Schedules a new workflow using DurableTask client.
9383
*
@@ -133,8 +123,10 @@ public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, Object in
133123
* @return the <code>instanceId</code> parameter value.
134124
*/
135125
public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, NewWorkflowOptions options) {
126+
NewOrchestrationInstanceOptions orchestrationInstanceOptions = fromNewWorkflowOptions(options);
127+
136128
return this.innerClient.scheduleNewOrchestrationInstance(clazz.getCanonicalName(),
137-
options.getNewOrchestrationInstanceOptions());
129+
orchestrationInstanceOptions);
138130
}
139131

140132
/**
@@ -158,10 +150,8 @@ public void terminateWorkflow(String workflowInstanceId, @Nullable Object output
158150
@Nullable
159151
public WorkflowInstanceStatus getInstanceState(String instanceId, boolean getInputsAndOutputs) {
160152
OrchestrationMetadata metadata = this.innerClient.getInstanceMetadata(instanceId, getInputsAndOutputs);
161-
if (metadata == null) {
162-
return null;
163-
}
164-
return new WorkflowInstanceStatus(metadata);
153+
154+
return metadata == null ? null : new DefaultWorkflowInstanceStatus(metadata);
165155
}
166156

167157
/**
@@ -186,7 +176,8 @@ public WorkflowInstanceStatus waitForInstanceStart(String instanceId, Duration t
186176
throws TimeoutException {
187177

188178
OrchestrationMetadata metadata = this.innerClient.waitForInstanceStart(instanceId, timeout, getInputsAndOutputs);
189-
return metadata == null ? null : new WorkflowInstanceStatus(metadata);
179+
180+
return metadata == null ? null : new DefaultWorkflowInstanceStatus(metadata);
190181
}
191182

192183
/**
@@ -210,11 +201,11 @@ public WorkflowInstanceStatus waitForInstanceStart(String instanceId, Duration t
210201
*/
211202
@Nullable
212203
public WorkflowInstanceStatus waitForInstanceCompletion(String instanceId, Duration timeout,
213-
boolean getInputsAndOutputs) throws TimeoutException {
204+
boolean getInputsAndOutputs) throws TimeoutException {
214205

215-
OrchestrationMetadata metadata =
216-
this.innerClient.waitForInstanceCompletion(instanceId, timeout, getInputsAndOutputs);
217-
return metadata == null ? null : new WorkflowInstanceStatus(metadata);
206+
OrchestrationMetadata metadata = this.innerClient.waitForInstanceCompletion(instanceId, timeout,
207+
getInputsAndOutputs);
208+
return metadata == null ? null : new DefaultWorkflowInstanceStatus(metadata);
218209
}
219210

220211
/**
@@ -236,18 +227,12 @@ public void raiseEvent(String workflowInstanceId, String eventName, Object event
236227
*/
237228
public boolean purgeInstance(String workflowInstanceId) {
238229
PurgeResult result = this.innerClient.purgeInstance(workflowInstanceId);
230+
239231
if (result != null) {
240232
return result.getDeletedInstanceCount() > 0;
241233
}
242-
return false;
243-
}
244-
245-
public void createTaskHub(boolean recreateIfExists) {
246-
this.innerClient.createTaskHub(recreateIfExists);
247-
}
248234

249-
public void deleteTaskHub() {
250-
this.innerClient.deleteTaskHub();
235+
return false;
251236
}
252237

253238
/**
@@ -267,6 +252,38 @@ public void close() throws InterruptedException {
267252
}
268253
}
269254

255+
/**
256+
* Static method to create the DurableTaskClient.
257+
*
258+
* @param grpcChannel ManagedChannel for GRPC.
259+
* @return a new instance of a DurableTaskClient with a GRPC channel.
260+
*/
261+
private static DurableTaskClient createDurableTaskClient(ManagedChannel grpcChannel) {
262+
return new DurableTaskGrpcClientBuilder()
263+
.grpcChannel(grpcChannel)
264+
.build();
265+
}
270266

271-
}
267+
private static NewOrchestrationInstanceOptions fromNewWorkflowOptions(NewWorkflowOptions options) {
268+
NewOrchestrationInstanceOptions instanceOptions = new NewOrchestrationInstanceOptions();
272269

270+
if (options.getVersion() != null) {
271+
instanceOptions.setVersion(options.getVersion());
272+
}
273+
274+
if (options.getInstanceId() != null) {
275+
instanceOptions.setInstanceId(options.getInstanceId());
276+
}
277+
278+
if (options.getInput() != null) {
279+
instanceOptions.setInput(options.getInput());
280+
}
281+
282+
if (options.getStartTime() != null) {
283+
instanceOptions.setStartTime(options.getStartTime());
284+
}
285+
286+
return instanceOptions;
287+
}
288+
289+
}

sdk-workflows/src/main/java/io/dapr/workflows/client/NewWorkflowOptions.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
package io.dapr.workflows.client;
1515

16-
import com.microsoft.durabletask.NewOrchestrationInstanceOptions;
17-
1816
import java.time.Instant;
1917

2018
/**
2119
* Options for starting a new instance of a workflow.
2220
*/
2321
public class NewWorkflowOptions {
24-
private final NewOrchestrationInstanceOptions newOrchestrationInstanceOptions = new NewOrchestrationInstanceOptions();
22+
23+
private String version;
24+
private String instanceId;
25+
private Object input;
26+
private Instant startTime;
2527

2628
/**
2729
* Sets the version of the workflow to start.
@@ -30,7 +32,7 @@ public class NewWorkflowOptions {
3032
* @return this {@link NewWorkflowOptions} object
3133
*/
3234
public NewWorkflowOptions setVersion(String version) {
33-
this.newOrchestrationInstanceOptions.setVersion(version);
35+
this.version = version;
3436
return this;
3537
}
3638

@@ -43,7 +45,7 @@ public NewWorkflowOptions setVersion(String version) {
4345
* @return this {@link NewWorkflowOptions} object
4446
*/
4547
public NewWorkflowOptions setInstanceId(String instanceId) {
46-
this.newOrchestrationInstanceOptions.setInstanceId(instanceId);
48+
this.instanceId = instanceId;
4749
return this;
4850
}
4951

@@ -54,7 +56,7 @@ public NewWorkflowOptions setInstanceId(String instanceId) {
5456
* @return this {@link NewWorkflowOptions} object
5557
*/
5658
public NewWorkflowOptions setInput(Object input) {
57-
this.newOrchestrationInstanceOptions.setInput(input);
59+
this.input = input;
5860
return this;
5961
}
6062

@@ -68,7 +70,7 @@ public NewWorkflowOptions setInput(Object input) {
6870
* @return this {@link NewWorkflowOptions} object
6971
*/
7072
public NewWorkflowOptions setStartTime(Instant startTime) {
71-
this.newOrchestrationInstanceOptions.setStartTime(startTime);
73+
this.startTime = startTime;
7274
return this;
7375
}
7476

@@ -78,7 +80,7 @@ public NewWorkflowOptions setStartTime(Instant startTime) {
7880
* @return the user-specified version of the new workflow.
7981
*/
8082
public String getVersion() {
81-
return this.newOrchestrationInstanceOptions.getVersion();
83+
return this.version;
8284
}
8385

8486
/**
@@ -87,7 +89,7 @@ public String getVersion() {
8789
* @return the instance ID of the new workflow.
8890
*/
8991
public String getInstanceId() {
90-
return this.newOrchestrationInstanceOptions.getInstanceId();
92+
return this.instanceId;
9193
}
9294

9395
/**
@@ -96,7 +98,7 @@ public String getInstanceId() {
9698
* @return the input of the new workflow.
9799
*/
98100
public Object getInput() {
99-
return this.newOrchestrationInstanceOptions.getInput();
101+
return this.input;
100102
}
101103

102104
/**
@@ -105,10 +107,7 @@ public Object getInput() {
105107
* @return the configured start time of the new workflow instance.
106108
*/
107109
public Instant getStartTime() {
108-
return this.newOrchestrationInstanceOptions.getStartTime();
110+
return this.startTime;
109111
}
110112

111-
public NewOrchestrationInstanceOptions getNewOrchestrationInstanceOptions() {
112-
return newOrchestrationInstanceOptions;
113-
}
114113
}

sdk-workflows/src/main/java/io/dapr/workflows/client/WorkflowFailureDetails.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,30 @@
1313

1414
package io.dapr.workflows.client;
1515

16-
import com.microsoft.durabletask.FailureDetails;
17-
1816
/**
1917
* Represents a workflow failure details.
2018
*/
21-
public class WorkflowFailureDetails {
22-
23-
private final FailureDetails workflowFailureDetails;
24-
25-
/**
26-
* Class constructor.
27-
*
28-
* @param failureDetails failure Details
29-
*/
30-
public WorkflowFailureDetails(FailureDetails failureDetails) {
31-
this.workflowFailureDetails = failureDetails;
32-
}
19+
public interface WorkflowFailureDetails {
3320

3421
/**
3522
* Gets the error type, which is the namespace-qualified exception type name.
3623
*
3724
* @return the error type, which is the namespace-qualified exception type name
3825
*/
39-
public String getErrorType() {
40-
return workflowFailureDetails.getErrorType();
41-
}
26+
String getErrorType();
4227

4328
/**
4429
* Gets the error message.
4530
*
4631
* @return the error message
4732
*/
48-
public String getErrorMessage() {
49-
return workflowFailureDetails.getErrorMessage();
50-
}
33+
String getErrorMessage();
5134

5235
/**
5336
* Gets the stack trace.
5437
*
5538
* @return the stack trace
5639
*/
57-
public String getStackTrace() {
58-
return workflowFailureDetails.getStackTrace();
59-
}
40+
String getStackTrace();
6041

61-
@Override
62-
public String toString() {
63-
return workflowFailureDetails.toString();
64-
}
6542
}

0 commit comments

Comments
 (0)