Skip to content

Commit 8de07b9

Browse files
Support workflow completed error in java client (#606)
* Support workflow completed error in java client * Add/Fix no retry tests and increment the version
1 parent 8a224cf commit 8de07b9

14 files changed

+176
-42
lines changed

src/main/idls

Submodule idls updated from 615f1ca to b1a9b9e
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
package com.uber.cadence.client;
19+
20+
import com.uber.cadence.WorkflowExecution;
21+
import java.util.Optional;
22+
23+
/**
24+
* Thrown when workflow already completed its execution and when the client is trying to run an
25+
* operation on the workflow like signal, terminate, cancel, poll etc.
26+
*/
27+
public final class WorkflowAlreadyCompletedException extends WorkflowException {
28+
29+
public WorkflowAlreadyCompletedException(
30+
WorkflowExecution execution, Optional<String> workflowType, String message) {
31+
super(message, execution, workflowType, null);
32+
}
33+
}

src/main/java/com/uber/cadence/internal/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Version {
4343
* support. This can be used for client capibility check, on Cadence server, for backward
4444
* compatibility Format: MAJOR.MINOR.PATCH
4545
*/
46-
public static final String FEATURE_VERSION = "1.3.0";
46+
public static final String FEATURE_VERSION = "1.4.0";
4747

4848
static {
4949
// Load version from version.properties generated by Gradle into build/resources/main directory.

src/main/java/com/uber/cadence/internal/common/RpcRetryer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.uber.cadence.DomainNotActiveError;
2626
import com.uber.cadence.EntityNotExistsError;
2727
import com.uber.cadence.QueryFailedError;
28+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
2829
import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
2930
import com.uber.cadence.common.RetryOptions;
3031
import java.time.Duration;
@@ -59,6 +60,7 @@ public final class RpcRetryer {
5960
roBuilder.setDoNotRetry(
6061
BadRequestError.class,
6162
EntityNotExistsError.class,
63+
WorkflowExecutionAlreadyCompletedError.class,
6264
WorkflowExecutionAlreadyStartedError.class,
6365
DomainAlreadyExistsError.class,
6466
QueryFailedError.class,

src/main/java/com/uber/cadence/internal/external/ManualActivityCompletionClientImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.uber.cadence.RespondActivityTaskFailedByIDRequest;
2828
import com.uber.cadence.RespondActivityTaskFailedRequest;
2929
import com.uber.cadence.WorkflowExecution;
30+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
3031
import com.uber.cadence.client.ActivityCancelledException;
3132
import com.uber.cadence.client.ActivityCompletionFailureException;
3233
import com.uber.cadence.client.ActivityNotExistsException;
@@ -99,6 +100,8 @@ public void complete(Object result) {
99100
metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_COUNTER).inc(1);
100101
} catch (EntityNotExistsError e) {
101102
throw new ActivityNotExistsException(e);
103+
} catch (WorkflowExecutionAlreadyCompletedError e) {
104+
throw new ActivityNotExistsException(e);
102105
} catch (TException e) {
103106
throw new ActivityCompletionFailureException(e);
104107
}
@@ -119,6 +122,8 @@ public void complete(Object result) {
119122
metricsScope.counter(MetricsType.ACTIVITY_TASK_COMPLETED_BY_ID_COUNTER).inc(1);
120123
} catch (EntityNotExistsError e) {
121124
throw new ActivityNotExistsException(e);
125+
} catch (WorkflowExecutionAlreadyCompletedError e) {
126+
throw new ActivityNotExistsException(e);
122127
} catch (TException e) {
123128
throw new ActivityCompletionFailureException(activityId, e);
124129
}
@@ -141,6 +146,8 @@ public void fail(Throwable failure) {
141146
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_COUNTER).inc(1);
142147
} catch (EntityNotExistsError e) {
143148
throw new ActivityNotExistsException(e);
149+
} catch (WorkflowExecutionAlreadyCompletedError e) {
150+
throw new ActivityNotExistsException(e);
144151
} catch (TException e) {
145152
throw new ActivityCompletionFailureException(e);
146153
}
@@ -156,6 +163,8 @@ public void fail(Throwable failure) {
156163
metricsScope.counter(MetricsType.ACTIVITY_TASK_FAILED_BY_ID_COUNTER).inc(1);
157164
} catch (EntityNotExistsError e) {
158165
throw new ActivityNotExistsException(e);
166+
} catch (WorkflowExecutionAlreadyCompletedError e) {
167+
throw new ActivityNotExistsException(e);
159168
} catch (TException e) {
160169
throw new ActivityCompletionFailureException(activityId, e);
161170
}
@@ -176,6 +185,8 @@ public void recordHeartbeat(Object details) throws CancellationException {
176185
}
177186
} catch (EntityNotExistsError e) {
178187
throw new ActivityNotExistsException(e);
188+
} catch (WorkflowExecutionAlreadyCompletedError e) {
189+
throw new ActivityNotExistsException(e);
179190
} catch (TException e) {
180191
throw new ActivityCompletionFailureException(e);
181192
}

src/main/java/com/uber/cadence/internal/sync/ActivityExecutionContextImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.uber.cadence.RecordActivityTaskHeartbeatRequest;
2323
import com.uber.cadence.RecordActivityTaskHeartbeatResponse;
2424
import com.uber.cadence.WorkflowExecution;
25+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
2526
import com.uber.cadence.activity.ActivityTask;
2627
import com.uber.cadence.client.ActivityCancelledException;
2728
import com.uber.cadence.client.ActivityCompletionException;
@@ -176,6 +177,8 @@ private void sendHeartbeatRequest(Object details) throws TException {
176177
}
177178
} catch (EntityNotExistsError e) {
178179
lastException = new ActivityNotExistsException(task, e);
180+
} catch (WorkflowExecutionAlreadyCompletedError e) {
181+
throw new ActivityNotExistsException(task, e);
179182
} catch (BadRequestError e) {
180183
lastException = new ActivityCompletionFailureException(task, e);
181184
}

src/main/java/com/uber/cadence/internal/sync/TestActivityEnvironmentInternal.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ private WorkflowServiceWrapper(IWorkflowService impl) {
337337
@Override
338338
public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeat(
339339
RecordActivityTaskHeartbeatRequest heartbeatRequest)
340-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
340+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
341+
WorkflowExecutionAlreadyCompletedError, TException {
341342
if (activityHeartbetListener != null) {
342343
Object details =
343344
testEnvironmentOptions
@@ -355,60 +356,68 @@ public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeat(
355356
@Override
356357
public RecordActivityTaskHeartbeatResponse RecordActivityTaskHeartbeatByID(
357358
RecordActivityTaskHeartbeatByIDRequest heartbeatRequest)
358-
throws BadRequestError, InternalServiceError, EntityNotExistsError, DomainNotActiveError,
359-
LimitExceededError, ServiceBusyError, TException {
359+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
360+
WorkflowExecutionAlreadyCompletedError, DomainNotActiveError, LimitExceededError,
361+
ServiceBusyError, TException {
360362
return impl.RecordActivityTaskHeartbeatByID(heartbeatRequest);
361363
}
362364

363365
@Override
364366
public void RespondActivityTaskCompleted(RespondActivityTaskCompletedRequest completeRequest)
365-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
367+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
368+
WorkflowExecutionAlreadyCompletedError, TException {
366369
impl.RespondActivityTaskCompleted(completeRequest);
367370
}
368371

369372
@Override
370373
public void RespondActivityTaskCompletedByID(
371374
RespondActivityTaskCompletedByIDRequest completeRequest)
372-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
375+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
376+
WorkflowExecutionAlreadyCompletedError, TException {
373377
impl.RespondActivityTaskCompletedByID(completeRequest);
374378
}
375379

376380
@Override
377381
public void RespondActivityTaskFailed(RespondActivityTaskFailedRequest failRequest)
378-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
382+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
383+
WorkflowExecutionAlreadyCompletedError, TException {
379384
impl.RespondActivityTaskFailed(failRequest);
380385
}
381386

382387
@Override
383388
public void RespondActivityTaskFailedByID(RespondActivityTaskFailedByIDRequest failRequest)
384-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
389+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
390+
WorkflowExecutionAlreadyCompletedError, TException {
385391
impl.RespondActivityTaskFailedByID(failRequest);
386392
}
387393

388394
@Override
389395
public void RespondActivityTaskCanceled(RespondActivityTaskCanceledRequest canceledRequest)
390-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
396+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
397+
WorkflowExecutionAlreadyCompletedError, TException {
391398
impl.RespondActivityTaskCanceled(canceledRequest);
392399
}
393400

394401
@Override
395402
public void RespondActivityTaskCanceledByID(
396403
RespondActivityTaskCanceledByIDRequest canceledRequest)
397-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
404+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
405+
WorkflowExecutionAlreadyCompletedError, TException {
398406
impl.RespondActivityTaskCanceledByID(canceledRequest);
399407
}
400408

401409
@Override
402410
public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest)
403411
throws BadRequestError, InternalServiceError, EntityNotExistsError,
404-
CancellationAlreadyRequestedError, ServiceBusyError, TException {
412+
CancellationAlreadyRequestedError, ServiceBusyError,
413+
WorkflowExecutionAlreadyCompletedError, TException {
405414
impl.RequestCancelWorkflowExecution(cancelRequest);
406415
}
407416

408417
@Override
409418
public void SignalWorkflowExecution(SignalWorkflowExecutionRequest signalRequest)
410-
throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
411-
TException {
419+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
420+
WorkflowExecutionAlreadyCompletedError, ServiceBusyError, TException {
412421
impl.SignalWorkflowExecution(signalRequest);
413422
}
414423

@@ -431,8 +440,8 @@ public ResetWorkflowExecutionResponse ResetWorkflowExecution(
431440

432441
@Override
433442
public void TerminateWorkflowExecution(TerminateWorkflowExecutionRequest terminateRequest)
434-
throws BadRequestError, InternalServiceError, EntityNotExistsError, ServiceBusyError,
435-
TException {
443+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
444+
WorkflowExecutionAlreadyCompletedError, ServiceBusyError, TException {
436445
impl.TerminateWorkflowExecution(terminateRequest);
437446
}
438447

@@ -492,7 +501,8 @@ public GetSearchAttributesResponse GetSearchAttributes()
492501

493502
@Override
494503
public void RespondQueryTaskCompleted(RespondQueryTaskCompletedRequest completeRequest)
495-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
504+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
505+
WorkflowExecutionAlreadyCompletedError, TException {
496506
impl.RespondQueryTaskCompleted(completeRequest);
497507
}
498508

@@ -882,13 +892,15 @@ public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskReques
882892
@Override
883893
public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(
884894
RespondDecisionTaskCompletedRequest completeRequest)
885-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
895+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
896+
WorkflowExecutionAlreadyCompletedError, TException {
886897
return impl.RespondDecisionTaskCompleted(completeRequest);
887898
}
888899

889900
@Override
890901
public void RespondDecisionTaskFailed(RespondDecisionTaskFailedRequest failedRequest)
891-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
902+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
903+
WorkflowExecutionAlreadyCompletedError, TException {
892904
impl.RespondDecisionTaskFailed(failedRequest);
893905
}
894906

src/main/java/com/uber/cadence/internal/sync/TestWorkflowEnvironmentInternal.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.uber.cadence.UpdateDomainRequest;
8383
import com.uber.cadence.UpdateDomainResponse;
8484
import com.uber.cadence.WorkflowExecution;
85+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
8586
import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
8687
import com.uber.cadence.client.ActivityCompletionClient;
8788
import com.uber.cadence.client.WorkflowClient;
@@ -764,13 +765,15 @@ public PollForDecisionTaskResponse PollForDecisionTask(PollForDecisionTaskReques
764765
@Override
765766
public RespondDecisionTaskCompletedResponse RespondDecisionTaskCompleted(
766767
RespondDecisionTaskCompletedRequest completeRequest)
767-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
768+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
769+
WorkflowExecutionAlreadyCompletedError, TException {
768770
return impl.RespondDecisionTaskCompleted(completeRequest);
769771
}
770772

771773
@Override
772774
public void RespondDecisionTaskFailed(RespondDecisionTaskFailedRequest failedRequest)
773-
throws BadRequestError, InternalServiceError, EntityNotExistsError, TException {
775+
throws BadRequestError, InternalServiceError, EntityNotExistsError,
776+
WorkflowExecutionAlreadyCompletedError, TException {
774777
impl.RespondDecisionTaskFailed(failedRequest);
775778
}
776779

src/main/java/com/uber/cadence/internal/sync/WorkflowStubImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.uber.cadence.QueryRejectCondition;
2424
import com.uber.cadence.QueryWorkflowResponse;
2525
import com.uber.cadence.WorkflowExecution;
26+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
2627
import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
2728
import com.uber.cadence.WorkflowType;
2829
import com.uber.cadence.client.*;
@@ -390,6 +391,9 @@ private <R> R mapToWorkflowFailureException(
390391
execution.get(), workflowType, executionFailed.getDecisionTaskCompletedEventId(), cause);
391392
} else if (failure instanceof EntityNotExistsError) {
392393
throw new WorkflowNotFoundException(execution.get(), workflowType, failure.getMessage());
394+
} else if (failure instanceof WorkflowExecutionAlreadyCompletedError) {
395+
throw new WorkflowAlreadyCompletedException(
396+
execution.get(), workflowType, failure.getMessage());
393397
} else if (failure instanceof CancellationException) {
394398
throw (CancellationException) failure;
395399
} else if (failure instanceof WorkflowException) {

src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableState.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes;
4949
import com.uber.cadence.StartWorkflowExecutionRequest;
5050
import com.uber.cadence.StickyExecutionAttributes;
51+
import com.uber.cadence.WorkflowExecutionAlreadyCompletedError;
5152
import com.uber.cadence.WorkflowExecutionCloseStatus;
5253
import com.uber.cadence.internal.testservice.TestWorkflowMutableStateImpl.QueryId;
5354
import java.util.Optional;
@@ -76,7 +77,8 @@ void failSignalExternalWorkflowExecution(
7677
throws EntityNotExistsError, InternalServiceError, BadRequestError;
7778

7879
void failDecisionTask(RespondDecisionTaskFailedRequest request)
79-
throws InternalServiceError, EntityNotExistsError, BadRequestError;
80+
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
81+
BadRequestError;
8082

8183
void childWorkflowStarted(ChildWorkflowExecutionStartedEventAttributes a)
8284
throws InternalServiceError, EntityNotExistsError, BadRequestError;
@@ -104,34 +106,44 @@ void startActivityTask(PollForActivityTaskResponse task, PollForActivityTaskRequ
104106
throws InternalServiceError, EntityNotExistsError, BadRequestError;
105107

106108
void completeActivityTask(String activityId, RespondActivityTaskCompletedRequest request)
107-
throws InternalServiceError, EntityNotExistsError, BadRequestError;
109+
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
110+
BadRequestError;
108111

109112
void completeActivityTaskById(String activityId, RespondActivityTaskCompletedByIDRequest request)
110-
throws InternalServiceError, EntityNotExistsError, BadRequestError;
113+
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
114+
BadRequestError;
111115

112116
void failActivityTask(String activityId, RespondActivityTaskFailedRequest request)
113-
throws InternalServiceError, EntityNotExistsError, BadRequestError;
117+
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
118+
BadRequestError;
114119

115120
void failActivityTaskById(String id, RespondActivityTaskFailedByIDRequest failRequest)
116-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
121+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
122+
BadRequestError;
117123

118124
RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, byte[] details)
119-
throws InternalServiceError, EntityNotExistsError, BadRequestError;
125+
throws InternalServiceError, EntityNotExistsError, WorkflowExecutionAlreadyCompletedError,
126+
BadRequestError;
120127

121128
void signal(SignalWorkflowExecutionRequest signalRequest)
122-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
129+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
130+
BadRequestError;
123131

124132
void signalFromWorkflow(SignalExternalWorkflowExecutionDecisionAttributes a)
125-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
133+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
134+
BadRequestError;
126135

127136
void requestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest)
128-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
137+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
138+
BadRequestError;
129139

130140
void cancelActivityTask(String id, RespondActivityTaskCanceledRequest canceledRequest)
131-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
141+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
142+
BadRequestError;
132143

133144
void cancelActivityTaskById(String id, RespondActivityTaskCanceledByIDRequest canceledRequest)
134-
throws EntityNotExistsError, InternalServiceError, BadRequestError;
145+
throws EntityNotExistsError, InternalServiceError, WorkflowExecutionAlreadyCompletedError,
146+
BadRequestError;
135147

136148
QueryWorkflowResponse query(QueryWorkflowRequest queryRequest) throws TException;
137149

0 commit comments

Comments
 (0)