Skip to content

Commit e2f0e9e

Browse files
authored
add error proto mapper to workflow APIs (#691)
1 parent b839f34 commit e2f0e9e

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

src/main/java/com/uber/cadence/internal/compatibility/Thrift2ProtoAdapter.java

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ private void convertAndThrowStatusException(StatusRuntimeException e)
221221
throws BadRequestError, WorkflowExecutionAlreadyStartedError, ServiceBusyError,
222222
DomainNotActiveError, LimitExceededError, EntityNotExistsError,
223223
ClientVersionNotSupportedError {
224+
if (e.getCause() != null) {
225+
e.getMessage();
226+
}
224227
// TODO handle all errors depending on status
225228
switch (e.getStatus().getCode()) {
226229
case ALREADY_EXISTS: {
@@ -451,8 +454,7 @@ public void RespondActivityTaskCanceledByID(
451454
}
452455

453456
@Override
454-
public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest
455-
cancelRequest)
457+
public void RequestCancelWorkflowExecution(RequestCancelWorkflowExecutionRequest cancelRequest)
456458
throws BadRequestError, EntityNotExistsError, CancellationAlreadyRequestedError,
457459
ServiceBusyError, DomainNotActiveError, LimitExceededError,
458460
ClientVersionNotSupportedError, WorkflowExecutionAlreadyCompletedError, TException {
@@ -490,37 +492,52 @@ public StartWorkflowExecutionResponse SignalWithStartWorkflowExecution(
490492
throws BadRequestError, EntityNotExistsError, ServiceBusyError, DomainNotActiveError,
491493
LimitExceededError, WorkflowExecutionAlreadyStartedError, ClientVersionNotSupportedError,
492494
TException {
493-
signalWithStartRequest.setRequestId(UUID.randomUUID().toString());
494-
com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionResponse response =
495-
grpcServiceStubs
496-
.workflowBlockingStub()
497-
.signalWithStartWorkflowExecution(
498-
RequestMapper.signalWithStartWorkflowExecutionRequest(signalWithStartRequest));
499-
return ResponseMapper.signalWithStartWorkflowExecutionResponse(response);
495+
try {
496+
signalWithStartRequest.setRequestId(UUID.randomUUID().toString());
497+
com.uber.cadence.api.v1.SignalWithStartWorkflowExecutionResponse response =
498+
grpcServiceStubs
499+
.workflowBlockingStub()
500+
.signalWithStartWorkflowExecution(
501+
RequestMapper.signalWithStartWorkflowExecutionRequest(signalWithStartRequest));
502+
return ResponseMapper.signalWithStartWorkflowExecutionResponse(response);
503+
} catch (StatusRuntimeException e) {
504+
convertAndThrowStatusException(e);
505+
throw e;
506+
}
500507
}
501508

502509
@Override
503510
public ResetWorkflowExecutionResponse ResetWorkflowExecution(
504511
ResetWorkflowExecutionRequest resetRequest)
505512
throws BadRequestError, EntityNotExistsError, ServiceBusyError, DomainNotActiveError,
506513
LimitExceededError, ClientVersionNotSupportedError, TException {
507-
resetRequest.setRequestId(UUID.randomUUID().toString());
508-
com.uber.cadence.api.v1.ResetWorkflowExecutionResponse response =
509-
grpcServiceStubs
510-
.workflowBlockingStub()
511-
.resetWorkflowExecution(RequestMapper.resetWorkflowExecutionRequest(resetRequest));
512-
return ResponseMapper.resetWorkflowExecutionResponse(response);
514+
try {
515+
resetRequest.setRequestId(UUID.randomUUID().toString());
516+
com.uber.cadence.api.v1.ResetWorkflowExecutionResponse response =
517+
grpcServiceStubs
518+
.workflowBlockingStub()
519+
.resetWorkflowExecution(RequestMapper.resetWorkflowExecutionRequest(resetRequest));
520+
return ResponseMapper.resetWorkflowExecutionResponse(response);
521+
} catch (StatusRuntimeException e) {
522+
convertAndThrowStatusException(e);
523+
throw e;
524+
}
513525
}
514526

515527
@Override
516528
public void TerminateWorkflowExecution(TerminateWorkflowExecutionRequest terminateRequest)
517529
throws BadRequestError, EntityNotExistsError, ServiceBusyError, DomainNotActiveError,
518530
LimitExceededError, ClientVersionNotSupportedError,
519531
WorkflowExecutionAlreadyCompletedError, TException {
520-
grpcServiceStubs
521-
.workflowBlockingStub()
522-
.terminateWorkflowExecution(
523-
RequestMapper.terminateWorkflowExecutionRequest(terminateRequest));
532+
try {
533+
grpcServiceStubs
534+
.workflowBlockingStub()
535+
.terminateWorkflowExecution(
536+
RequestMapper.terminateWorkflowExecutionRequest(terminateRequest));
537+
} catch (StatusRuntimeException e) {
538+
convertAndThrowStatusException(e);
539+
throw e;
540+
}
524541
}
525542

526543
@Override
@@ -594,8 +611,7 @@ public CountWorkflowExecutionsResponse CountWorkflowExecutions(
594611
com.uber.cadence.api.v1.CountWorkflowExecutionsResponse response =
595612
grpcServiceStubs
596613
.visibilityBlockingStub()
597-
.countWorkflowExecutions(
598-
RequestMapper.countWorkflowExecutionsRequest(countRequest));
614+
.countWorkflowExecutions(RequestMapper.countWorkflowExecutionsRequest(countRequest));
599615
return ResponseMapper.countWorkflowExecutionsResponse(response);
600616
}
601617

@@ -615,13 +631,11 @@ public void RespondQueryTaskCompleted(RespondQueryTaskCompletedRequest completeR
615631
DomainNotActiveError, ClientVersionNotSupportedError, TException {
616632
grpcServiceStubs
617633
.workerBlockingStub()
618-
.respondQueryTaskCompleted(
619-
RequestMapper.respondQueryTaskCompletedRequest(completeRequest));
634+
.respondQueryTaskCompleted(RequestMapper.respondQueryTaskCompletedRequest(completeRequest));
620635
}
621636

622637
@Override
623-
public ResetStickyTaskListResponse ResetStickyTaskList(ResetStickyTaskListRequest
624-
resetRequest)
638+
public ResetStickyTaskListResponse ResetStickyTaskList(ResetStickyTaskListRequest resetRequest)
625639
throws BadRequestError, EntityNotExistsError, LimitExceededError, ServiceBusyError,
626640
DomainNotActiveError, ClientVersionNotSupportedError,
627641
WorkflowExecutionAlreadyCompletedError, TException {
@@ -705,15 +719,13 @@ public void RefreshWorkflowTasks(RefreshWorkflowTasksRequest request)
705719

706720
@Override
707721
public void RegisterDomain(
708-
RegisterDomainRequest registerRequest, AsyncMethodCallback resultHandler) throws
709-
TException {
722+
RegisterDomainRequest registerRequest, AsyncMethodCallback resultHandler) throws TException {
710723
throw new UnsupportedOperationException("not implemented");
711724
}
712725

713726
@Override
714727
public void DescribeDomain(
715-
DescribeDomainRequest describeRequest, AsyncMethodCallback resultHandler) throws
716-
TException {
728+
DescribeDomainRequest describeRequest, AsyncMethodCallback resultHandler) throws TException {
717729
throw new UnsupportedOperationException("not implemented");
718730
}
719731

@@ -752,8 +764,7 @@ public void GetWorkflowExecutionHistory(
752764

753765
@Override
754766
public void PollForDecisionTask(
755-
PollForDecisionTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws
756-
TException {
767+
PollForDecisionTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException {
757768
throw new UnsupportedOperationException("not implemented");
758769
}
759770

@@ -773,8 +784,7 @@ public void RespondDecisionTaskFailed(
773784

774785
@Override
775786
public void PollForActivityTask(
776-
PollForActivityTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws
777-
TException {
787+
PollForActivityTaskRequest pollRequest, AsyncMethodCallback resultHandler) throws TException {
778788
throw new UnsupportedOperationException("not implemented");
779789
}
780790

@@ -849,13 +859,11 @@ public void SignalWorkflowExecution(
849859
ListenableFuture<com.uber.cadence.api.v1.SignalWorkflowExecutionResponse> resultFuture =
850860
grpcServiceStubs
851861
.workflowFutureStub()
852-
.signalWorkflowExecution(
853-
RequestMapper.signalWorkflowExecutionRequest(signalRequest));
862+
.signalWorkflowExecution(RequestMapper.signalWorkflowExecutionRequest(signalRequest));
854863
resultFuture.addListener(
855864
() -> {
856865
try {
857-
com.uber.cadence.api.v1.SignalWorkflowExecutionResponse response = resultFuture
858-
.get();
866+
com.uber.cadence.api.v1.SignalWorkflowExecutionResponse response = resultFuture.get();
859867
resultHandler.onComplete(null);
860868
} catch (Exception e) {
861869
resultHandler.onError(e);
@@ -948,8 +956,7 @@ public void ResetStickyTaskList(
948956
}
949957

950958
@Override
951-
public void QueryWorkflow(QueryWorkflowRequest queryRequest, AsyncMethodCallback
952-
resultHandler)
959+
public void QueryWorkflow(QueryWorkflowRequest queryRequest, AsyncMethodCallback resultHandler)
953960
throws TException {
954961
throw new UnsupportedOperationException("not implemented");
955962
}
@@ -962,8 +969,7 @@ public void DescribeWorkflowExecution(
962969
}
963970

964971
@Override
965-
public void DescribeTaskList(DescribeTaskListRequest request, AsyncMethodCallback
966-
resultHandler)
972+
public void DescribeTaskList(DescribeTaskListRequest request, AsyncMethodCallback resultHandler)
967973
throws TException {
968974
throw new UnsupportedOperationException("not implemented");
969975
}
@@ -981,8 +987,7 @@ public void GetTaskListsByDomain(
981987

982988
@Override
983989
public void ListTaskListPartitions(
984-
ListTaskListPartitionsRequest request, AsyncMethodCallback resultHandler) throws
985-
TException {
990+
ListTaskListPartitionsRequest request, AsyncMethodCallback resultHandler) throws TException {
986991
throw new UnsupportedOperationException("not implemented");
987992
}
988993

@@ -1042,8 +1047,7 @@ public void StartWorkflowExecutionWithTimeout(
10421047
resultFuture.addListener(
10431048
() -> {
10441049
try {
1045-
com.uber.cadence.api.v1.StartWorkflowExecutionResponse response = resultFuture
1046-
.get();
1050+
com.uber.cadence.api.v1.StartWorkflowExecutionResponse response = resultFuture.get();
10471051
resultHandler.onComplete(ResponseMapper.startWorkflowExecutionResponse(response));
10481052
} catch (Exception e) {
10491053
resultHandler.onError(e);
@@ -1082,8 +1086,7 @@ public void GetWorkflowExecutionHistoryWithTimeout(
10821086
try {
10831087
com.uber.cadence.api.v1.GetWorkflowExecutionHistoryResponse response =
10841088
resultFuture.get();
1085-
resultHandler
1086-
.onComplete(ResponseMapper.getWorkflowExecutionHistoryResponse(response));
1089+
resultHandler.onComplete(ResponseMapper.getWorkflowExecutionHistoryResponse(response));
10871090
} catch (Exception e) {
10881091
resultHandler.onError(e);
10891092
}

0 commit comments

Comments
 (0)