1515
1616import com .microsoft .durabletask .DurableTaskClient ;
1717import com .microsoft .durabletask .DurableTaskGrpcClientBuilder ;
18+ import com .microsoft .durabletask .NewOrchestrationInstanceOptions ;
1819import com .microsoft .durabletask .OrchestrationMetadata ;
1920import com .microsoft .durabletask .PurgeResult ;
2021import io .dapr .config .Properties ;
2122import io .dapr .utils .NetworkUtils ;
2223import io .dapr .workflows .Workflow ;
2324import io .dapr .workflows .internal .ApiTokenClientInterceptor ;
25+ import io .dapr .workflows .runtime .DefaultWorkflowInstanceStatus ;
2426import io .grpc .ClientInterceptor ;
2527import 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+ }
0 commit comments