From 053343284e34fc7bc60063c1949e86535976ef4b Mon Sep 17 00:00:00 2001 From: Shijie Sheng Date: Tue, 8 Apr 2025 10:00:07 -0700 Subject: [PATCH 1/3] add serviceclient exceptions --- .../compatibility/proto/ErrorMapper.java | 70 +++++++++++++++++++ .../exceptions/AccessDeniedException.java | 8 +++ ...CancellationAlreadyRequestedException.java | 7 ++ .../ClientVersionNotSupportedException.java | 25 +++++++ .../DomainAlreadyExistsException.java | 7 ++ .../exceptions/DomainNotActiveException.java | 25 +++++++ .../exceptions/EntityNotExistsException.java | 8 +++ .../FeatureNotEnabledException.java | 13 ++++ .../InternalDataInconsistencyException.java | 7 ++ .../exceptions/InternalServiceException.java | 7 ++ .../exceptions/LimitExceededException.java | 7 ++ .../exceptions/QueryFailedException.java | 4 ++ .../exceptions/ServiceBusyException.java | 7 ++ .../exceptions/ServiceClientException.java | 20 ++++++ .../StickyWorkerUnavailableException.java | 4 ++ ...lowExecutionAlreadyCompletedException.java | 7 ++ ...kflowExecutionAlreadyStartedException.java | 19 +++++ 17 files changed, 245 insertions(+) create mode 100644 src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java create mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java diff --git a/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java b/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java new file mode 100644 index 000000000..50218b91f --- /dev/null +++ b/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java @@ -0,0 +1,70 @@ +package com.uber.cadence.internal.compatibility.proto; + +import com.google.protobuf.Any; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Message; +import com.google.rpc.Status; +import com.uber.cadence.api.v1.*; +import com.uber.cadence.serviceclient.exceptions.*; +import io.grpc.StatusRuntimeException; +import io.grpc.protobuf.StatusProto; + +public class ErrorMapper { + public static ServiceClientException Error(StatusRuntimeException e) { + + Status status = StatusProto.fromThrowable(e); + if (status == null || status.getDetailsCount() == 0) { + return new ServiceClientException("empty status or status with empty details", e); + } + + Any detail = status.getDetails(0); + + try { + switch (e.getStatus().getCode()) { + case PERMISSION_DENIED: + return new AccessDeniedException(e); + case INTERNAL: + return new InternalServiceException(e); + case NOT_FOUND: + if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) { + return new WorkflowExecutionAlreadyCompletedException(e); + } else { + return new EntityNotExistsException(e); + } + case ALREADY_EXISTS: + if (detail.is(CancellationAlreadyRequestedError.class)) { + return new CancellationAlreadyRequestedException(e); + } else if (detail.is(DomainAlreadyExistsError.class)) { + return new DomainAlreadyExistsException(e); + } else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) { + WorkflowExecutionAlreadyStartedError error = detail.unpack(WorkflowExecutionAlreadyStartedError.class); + return new WorkflowExecutionAlreadyStartedException(error.getStartRequestId(), error.getRunId()); + } + case DATA_LOSS: + return new InternalDataInconsistencyException(e); + case FAILED_PRECONDITION: + if (detail.is(ClientVersionNotSupportedError.class)) { + ClientVersionNotSupportedError error = detail.unpack(ClientVersionNotSupportedError.class); + return new ClientVersionNotSupportedException(error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions()); + }else if (detail.is(FeatureNotEnabledError.class)) { + FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class); + return new FeatureNotEnabledException(error.getFeatureFlag()); + } else if (detail.is(DomainNotActiveError.class)) { + DomainNotActiveError error = detail.unpack(DomainNotActiveError.class); + return new DomainNotActiveException(error.getDomain(), error.getCurrentCluster(), error.getActiveCluster()); + } + case RESOURCE_EXHAUSTED: + if (detail.is(LimitExceededError.class)) { + return new LimitExceededException(e); + } else { + return new ServiceBusyException(e); + } + case UNKNOWN: + default: + return new ServiceClientException(e); + } + } catch (InvalidProtocolBufferException ex) { + return new ServiceClientException(ex); + } + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java new file mode 100644 index 000000000..bd5606981 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java @@ -0,0 +1,8 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class AccessDeniedException extends ServiceClientException { + + public AccessDeniedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java new file mode 100644 index 000000000..533712712 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class CancellationAlreadyRequestedException extends ServiceClientException { + public CancellationAlreadyRequestedException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java new file mode 100644 index 000000000..ffaa2065e --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java @@ -0,0 +1,25 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class ClientVersionNotSupportedException extends ServiceClientException { + private final String featureVersion; + private final String clientImpl; + private final String supportedVersions; + + public ClientVersionNotSupportedException(String featureVersion, String clientImpl, String supportedVersions) { + this.featureVersion = featureVersion; + this.clientImpl = clientImpl; + this.supportedVersions = supportedVersions; + } + + public String getFeatureVersion() { + return featureVersion; + } + + public String getClientImpl() { + return clientImpl; + } + + public String getSupportedVersions() { + return supportedVersions; + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java new file mode 100644 index 000000000..d8b111026 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class DomainAlreadyExistsException extends ServiceClientException { + public DomainAlreadyExistsException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java new file mode 100644 index 000000000..6a14bdf11 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java @@ -0,0 +1,25 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class DomainNotActiveException extends ServiceClientException { + private final String domain; + private final String currentCluster; + private final String activeCluster; + + public DomainNotActiveException(String domain, String currentCluster, String activeCluster) { + this.domain = domain; + this.currentCluster = currentCluster; + this.activeCluster = activeCluster; + } + + public String getDomain() { + return domain; + } + + public String getCurrentCluster() { + return currentCluster; + } + + public String getActiveCluster() { + return activeCluster; + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java new file mode 100644 index 000000000..7a86ac120 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java @@ -0,0 +1,8 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class EntityNotExistsException extends ServiceClientException { + + public EntityNotExistsException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java new file mode 100644 index 000000000..9526f858a --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java @@ -0,0 +1,13 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class FeatureNotEnabledException extends ServiceClientException { + private final String featureFlag; + + public FeatureNotEnabledException(String featureFlag) { + this.featureFlag = featureFlag; + } + + public String getFeatureFlag() { + return featureFlag; + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java new file mode 100644 index 000000000..916495778 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class InternalDataInconsistencyException extends ServiceClientException{ + public InternalDataInconsistencyException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java new file mode 100644 index 000000000..f2169a85b --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class InternalServiceException extends ServiceClientException{ + public InternalServiceException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java new file mode 100644 index 000000000..aee22155b --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class LimitExceededException extends ServiceClientException { + public LimitExceededException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java new file mode 100644 index 000000000..e4c3a6ce1 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java @@ -0,0 +1,4 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class QueryFailedException extends ServiceClientException { +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java new file mode 100644 index 000000000..00c4d6c19 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class ServiceBusyException extends ServiceClientException { + public ServiceBusyException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java new file mode 100644 index 000000000..9dbff17c3 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java @@ -0,0 +1,20 @@ +package com.uber.cadence.serviceclient.exceptions; + +/** + * Base class for all exceptions thrown by the service client. + * + *

This is a catchall for all other errors. + */ +public class ServiceClientException extends RuntimeException{ + ServiceClientException() { + super(); + } + + public ServiceClientException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceClientException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java new file mode 100644 index 000000000..c7a45ba4e --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java @@ -0,0 +1,4 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class StickyWorkerUnavailableException extends ServiceClientException { +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java new file mode 100644 index 000000000..423215de6 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java @@ -0,0 +1,7 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class WorkflowExecutionAlreadyCompletedException extends ServiceClientException { + public WorkflowExecutionAlreadyCompletedException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java new file mode 100644 index 000000000..b69b4f0a5 --- /dev/null +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java @@ -0,0 +1,19 @@ +package com.uber.cadence.serviceclient.exceptions; + +public class WorkflowExecutionAlreadyStartedException extends ServiceClientException { + private final String startRequestId; + private final String runId; + + public WorkflowExecutionAlreadyStartedException(String startRequestId, String runId) { + this.startRequestId = startRequestId; + this.runId = runId; + } + + public String getStartRequestId() { + return startRequestId; + } + + public String getRunId() { + return runId; + } +} From c57c685d6445126b1cca8dce317865e790aee40f Mon Sep 17 00:00:00 2001 From: Shijie Sheng Date: Tue, 8 Apr 2025 15:38:59 -0700 Subject: [PATCH 2/3] fix flaky test and add test --- .../compatibility/proto/ErrorMapper.java | 132 ++++++++++------- .../exceptions/AccessDeniedException.java | 23 ++- ...CancellationAlreadyRequestedException.java | 25 +++- .../ClientVersionNotSupportedException.java | 54 ++++--- .../DomainAlreadyExistsException.java | 25 +++- .../exceptions/DomainNotActiveException.java | 53 ++++--- .../exceptions/EntityNotExistsException.java | 23 ++- .../FeatureNotEnabledException.java | 33 ++++- .../InternalDataInconsistencyException.java | 25 +++- .../exceptions/InternalServiceException.java | 25 +++- .../exceptions/LimitExceededException.java | 25 +++- .../exceptions/QueryFailedException.java | 20 ++- .../exceptions/ServiceBusyException.java | 25 +++- .../exceptions/ServiceClientException.java | 37 +++-- .../StickyWorkerUnavailableException.java | 20 ++- ...lowExecutionAlreadyCompletedException.java | 24 ++- ...kflowExecutionAlreadyStartedException.java | 40 +++-- .../converter/JsonDataConverterTest.java | 6 +- .../compatibility/proto/ErrorMapperTest.java | 139 ++++++++++++++++++ 19 files changed, 593 insertions(+), 161 deletions(-) create mode 100644 src/test/java/com/uber/cadence/internal/compatibility/proto/ErrorMapperTest.java diff --git a/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java b/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java index 50218b91f..6e3ed1581 100644 --- a/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java +++ b/src/main/java/com/uber/cadence/internal/compatibility/proto/ErrorMapper.java @@ -1,8 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.internal.compatibility.proto; import com.google.protobuf.Any; import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Message; import com.google.rpc.Status; import com.uber.cadence.api.v1.*; import com.uber.cadence.serviceclient.exceptions.*; @@ -10,61 +26,69 @@ import io.grpc.protobuf.StatusProto; public class ErrorMapper { - public static ServiceClientException Error(StatusRuntimeException e) { + public static ServiceClientException Error(StatusRuntimeException e) { - Status status = StatusProto.fromThrowable(e); - if (status == null || status.getDetailsCount() == 0) { - return new ServiceClientException("empty status or status with empty details", e); - } + Status status = StatusProto.fromThrowable(e); + if (status == null) { + return new ServiceClientException("empty status", e); + } - Any detail = status.getDetails(0); + Any detail = Any.getDefaultInstance(); + if (status.getDetailsCount() > 0) { + detail = status.getDetails(0); + } - try { - switch (e.getStatus().getCode()) { - case PERMISSION_DENIED: - return new AccessDeniedException(e); - case INTERNAL: - return new InternalServiceException(e); - case NOT_FOUND: - if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) { - return new WorkflowExecutionAlreadyCompletedException(e); - } else { - return new EntityNotExistsException(e); - } - case ALREADY_EXISTS: - if (detail.is(CancellationAlreadyRequestedError.class)) { - return new CancellationAlreadyRequestedException(e); - } else if (detail.is(DomainAlreadyExistsError.class)) { - return new DomainAlreadyExistsException(e); - } else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) { - WorkflowExecutionAlreadyStartedError error = detail.unpack(WorkflowExecutionAlreadyStartedError.class); - return new WorkflowExecutionAlreadyStartedException(error.getStartRequestId(), error.getRunId()); - } - case DATA_LOSS: - return new InternalDataInconsistencyException(e); - case FAILED_PRECONDITION: - if (detail.is(ClientVersionNotSupportedError.class)) { - ClientVersionNotSupportedError error = detail.unpack(ClientVersionNotSupportedError.class); - return new ClientVersionNotSupportedException(error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions()); - }else if (detail.is(FeatureNotEnabledError.class)) { - FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class); - return new FeatureNotEnabledException(error.getFeatureFlag()); - } else if (detail.is(DomainNotActiveError.class)) { - DomainNotActiveError error = detail.unpack(DomainNotActiveError.class); - return new DomainNotActiveException(error.getDomain(), error.getCurrentCluster(), error.getActiveCluster()); - } - case RESOURCE_EXHAUSTED: - if (detail.is(LimitExceededError.class)) { - return new LimitExceededException(e); - } else { - return new ServiceBusyException(e); - } - case UNKNOWN: - default: - return new ServiceClientException(e); - } - } catch (InvalidProtocolBufferException ex) { - return new ServiceClientException(ex); - } + try { + switch (e.getStatus().getCode()) { + case PERMISSION_DENIED: + return new AccessDeniedException(e); + case INTERNAL: + return new InternalServiceException(e); + case NOT_FOUND: + if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) { + return new WorkflowExecutionAlreadyCompletedException(e); + } else { + return new EntityNotExistsException(e); + } + case ALREADY_EXISTS: + if (detail.is(CancellationAlreadyRequestedError.class)) { + return new CancellationAlreadyRequestedException(e); + } else if (detail.is(DomainAlreadyExistsError.class)) { + return new DomainAlreadyExistsException(e); + } else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) { + WorkflowExecutionAlreadyStartedError error = + detail.unpack(WorkflowExecutionAlreadyStartedError.class); + return new WorkflowExecutionAlreadyStartedException( + error.getStartRequestId(), error.getRunId()); + } + case DATA_LOSS: + return new InternalDataInconsistencyException(e); + case FAILED_PRECONDITION: + if (detail.is(ClientVersionNotSupportedError.class)) { + ClientVersionNotSupportedError error = + detail.unpack(ClientVersionNotSupportedError.class); + return new ClientVersionNotSupportedException( + error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions()); + } else if (detail.is(FeatureNotEnabledError.class)) { + FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class); + return new FeatureNotEnabledException(error.getFeatureFlag()); + } else if (detail.is(DomainNotActiveError.class)) { + DomainNotActiveError error = detail.unpack(DomainNotActiveError.class); + return new DomainNotActiveException( + error.getDomain(), error.getCurrentCluster(), error.getActiveCluster()); + } + case RESOURCE_EXHAUSTED: + if (detail.is(LimitExceededError.class)) { + return new LimitExceededException(e); + } else { + return new ServiceBusyException(e); + } + case UNKNOWN: + default: + return new ServiceClientException(e); + } + } catch (InvalidProtocolBufferException ex) { + return new ServiceClientException(ex); } + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java index bd5606981..a1ed1eee0 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/AccessDeniedException.java @@ -1,8 +1,25 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class AccessDeniedException extends ServiceClientException { - public AccessDeniedException(Throwable cause) { - super(cause); - } + public AccessDeniedException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java index 533712712..20be80a90 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/CancellationAlreadyRequestedException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class CancellationAlreadyRequestedException extends ServiceClientException { - public CancellationAlreadyRequestedException(Throwable cause) { - super(cause); - } -} \ No newline at end of file + public CancellationAlreadyRequestedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java index ffaa2065e..ab61e11d7 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ClientVersionNotSupportedException.java @@ -1,25 +1,43 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class ClientVersionNotSupportedException extends ServiceClientException { - private final String featureVersion; - private final String clientImpl; - private final String supportedVersions; + private final String featureVersion; + private final String clientImpl; + private final String supportedVersions; - public ClientVersionNotSupportedException(String featureVersion, String clientImpl, String supportedVersions) { - this.featureVersion = featureVersion; - this.clientImpl = clientImpl; - this.supportedVersions = supportedVersions; - } + public ClientVersionNotSupportedException( + String featureVersion, String clientImpl, String supportedVersions) { + this.featureVersion = featureVersion; + this.clientImpl = clientImpl; + this.supportedVersions = supportedVersions; + } - public String getFeatureVersion() { - return featureVersion; - } + public String getFeatureVersion() { + return featureVersion; + } - public String getClientImpl() { - return clientImpl; - } + public String getClientImpl() { + return clientImpl; + } - public String getSupportedVersions() { - return supportedVersions; - } -} \ No newline at end of file + public String getSupportedVersions() { + return supportedVersions; + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java index d8b111026..cddcc40db 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainAlreadyExistsException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class DomainAlreadyExistsException extends ServiceClientException { - public DomainAlreadyExistsException(Throwable cause) { - super(cause); - } -} \ No newline at end of file + public DomainAlreadyExistsException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java index 6a14bdf11..002bb471f 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/DomainNotActiveException.java @@ -1,25 +1,42 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class DomainNotActiveException extends ServiceClientException { - private final String domain; - private final String currentCluster; - private final String activeCluster; + private final String domain; + private final String currentCluster; + private final String activeCluster; - public DomainNotActiveException(String domain, String currentCluster, String activeCluster) { - this.domain = domain; - this.currentCluster = currentCluster; - this.activeCluster = activeCluster; - } + public DomainNotActiveException(String domain, String currentCluster, String activeCluster) { + this.domain = domain; + this.currentCluster = currentCluster; + this.activeCluster = activeCluster; + } - public String getDomain() { - return domain; - } + public String getDomain() { + return domain; + } - public String getCurrentCluster() { - return currentCluster; - } + public String getCurrentCluster() { + return currentCluster; + } - public String getActiveCluster() { - return activeCluster; - } -} \ No newline at end of file + public String getActiveCluster() { + return activeCluster; + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java index 7a86ac120..9553a0d8e 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/EntityNotExistsException.java @@ -1,8 +1,25 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class EntityNotExistsException extends ServiceClientException { - public EntityNotExistsException(Throwable cause) { - super(cause); - } + public EntityNotExistsException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java index 9526f858a..f8172b626 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/FeatureNotEnabledException.java @@ -1,13 +1,30 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class FeatureNotEnabledException extends ServiceClientException { - private final String featureFlag; + private final String featureFlag; - public FeatureNotEnabledException(String featureFlag) { - this.featureFlag = featureFlag; - } + public FeatureNotEnabledException(String featureFlag) { + this.featureFlag = featureFlag; + } - public String getFeatureFlag() { - return featureFlag; - } -} \ No newline at end of file + public String getFeatureFlag() { + return featureFlag; + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java index 916495778..79b679639 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalDataInconsistencyException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; -public class InternalDataInconsistencyException extends ServiceClientException{ - public InternalDataInconsistencyException(Throwable cause) { - super(cause); - } +public class InternalDataInconsistencyException extends ServiceClientException { + public InternalDataInconsistencyException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java index f2169a85b..17915be6b 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/InternalServiceException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; -public class InternalServiceException extends ServiceClientException{ - public InternalServiceException(Throwable cause) { - super(cause); - } +public class InternalServiceException extends ServiceClientException { + public InternalServiceException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java index aee22155b..112150646 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/LimitExceededException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class LimitExceededException extends ServiceClientException { - public LimitExceededException(Throwable cause) { - super(cause); - } -} \ No newline at end of file + public LimitExceededException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java index e4c3a6ce1..d808b777f 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java @@ -1,4 +1,20 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; -public class QueryFailedException extends ServiceClientException { -} \ No newline at end of file +public class QueryFailedException extends ServiceClientException {} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java index 00c4d6c19..1cf7cf65b 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceBusyException.java @@ -1,7 +1,24 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; public class ServiceBusyException extends ServiceClientException { - public ServiceBusyException(Throwable cause) { - super(cause); - } -} \ No newline at end of file + public ServiceBusyException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java index 9dbff17c3..f28de9469 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/ServiceClientException.java @@ -1,3 +1,20 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; /** @@ -5,16 +22,16 @@ * *

This is a catchall for all other errors. */ -public class ServiceClientException extends RuntimeException{ - ServiceClientException() { - super(); - } +public class ServiceClientException extends RuntimeException { + ServiceClientException() { + super(); + } - public ServiceClientException(String message, Throwable cause) { - super(message, cause); - } + public ServiceClientException(String message, Throwable cause) { + super(message, cause); + } - public ServiceClientException(Throwable cause) { - super(cause); - } + public ServiceClientException(Throwable cause) { + super(cause); + } } diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java index c7a45ba4e..2a74ea327 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java @@ -1,4 +1,20 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + package com.uber.cadence.serviceclient.exceptions; -public class StickyWorkerUnavailableException extends ServiceClientException { -} \ No newline at end of file +public class StickyWorkerUnavailableException extends ServiceClientException {} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java index 423215de6..72f70515a 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyCompletedException.java @@ -1,7 +1,23 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.uber.cadence.serviceclient.exceptions; public class WorkflowExecutionAlreadyCompletedException extends ServiceClientException { - public WorkflowExecutionAlreadyCompletedException(Throwable cause) { - super(cause); - } -} \ No newline at end of file + public WorkflowExecutionAlreadyCompletedException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java index b69b4f0a5..2dbbfecb5 100644 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java +++ b/src/main/java/com/uber/cadence/serviceclient/exceptions/WorkflowExecutionAlreadyStartedException.java @@ -1,19 +1,35 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.uber.cadence.serviceclient.exceptions; public class WorkflowExecutionAlreadyStartedException extends ServiceClientException { - private final String startRequestId; - private final String runId; + private final String startRequestId; + private final String runId; - public WorkflowExecutionAlreadyStartedException(String startRequestId, String runId) { - this.startRequestId = startRequestId; - this.runId = runId; - } + public WorkflowExecutionAlreadyStartedException(String startRequestId, String runId) { + this.startRequestId = startRequestId; + this.runId = runId; + } - public String getStartRequestId() { - return startRequestId; - } + public String getStartRequestId() { + return startRequestId; + } - public String getRunId() { - return runId; - } + public String getRunId() { + return runId; + } } diff --git a/src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java b/src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java index 20743414a..155c1b860 100644 --- a/src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java +++ b/src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java @@ -245,8 +245,6 @@ public NonSerializableException(Throwable cause) { } } - // TODO flaky test in local env: expected: but - // was: @Test public void testException() { RuntimeException rootException = new RuntimeException("root exception"); @@ -263,7 +261,9 @@ public void testException() { assertNotNull(causeFromConverted); assertEquals(DataConverterException.class, causeFromConverted.getClass()); assertNotNull(causeFromConverted.getCause()); - assertEquals(JsonIOException.class, causeFromConverted.getCause().getClass()); + Class causeClass = causeFromConverted.getCause().getClass(); + // it depends on the gson implementation on different runtimes + assertTrue(causeClass == JsonIOException.class || causeClass == StackOverflowError.class); assertNotNull(causeFromConverted.getSuppressed()); assertEquals(1, causeFromConverted.getSuppressed().length); diff --git a/src/test/java/com/uber/cadence/internal/compatibility/proto/ErrorMapperTest.java b/src/test/java/com/uber/cadence/internal/compatibility/proto/ErrorMapperTest.java new file mode 100644 index 000000000..8720efb7d --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/compatibility/proto/ErrorMapperTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.uber.cadence.internal.compatibility.proto; + +import static org.junit.Assert.assertEquals; + +import com.google.protobuf.Any; +import com.google.protobuf.Message; +import com.uber.cadence.api.v1.*; +import com.uber.cadence.serviceclient.exceptions.*; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import io.grpc.protobuf.StatusProto; +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class ErrorMapperTest { + + @Parameterized.Parameter(0) + public Status status; + + @Parameterized.Parameter(1) + public Message detail; + + @Parameterized.Parameter(2) + public Class expectedException; + + @Parameterized.Parameters + public static Collection data() { + Object[][] data = + new Object[][] { + {Status.PERMISSION_DENIED, null, AccessDeniedException.class}, + {Status.INTERNAL, null, InternalServiceException.class}, + {Status.NOT_FOUND, null, EntityNotExistsException.class}, + { + Status.ALREADY_EXISTS, + DomainAlreadyExistsError.getDefaultInstance(), + DomainAlreadyExistsException.class + }, + { + Status.FAILED_PRECONDITION, + FeatureNotEnabledError.getDefaultInstance(), + FeatureNotEnabledException.class + }, + { + Status.RESOURCE_EXHAUSTED, + LimitExceededError.getDefaultInstance(), + LimitExceededException.class + }, + {Status.UNKNOWN, null, ServiceClientException.class}, + { + Status.NOT_FOUND, + WorkflowExecutionAlreadyCompletedError.getDefaultInstance(), + WorkflowExecutionAlreadyCompletedException.class + }, + { + Status.ALREADY_EXISTS, + WorkflowExecutionAlreadyStartedError.getDefaultInstance(), + WorkflowExecutionAlreadyStartedException.class + }, + { + Status.FAILED_PRECONDITION, + DomainNotActiveError.getDefaultInstance(), + DomainNotActiveException.class + }, + { + Status.FAILED_PRECONDITION, + ClientVersionNotSupportedError.getDefaultInstance(), + ClientVersionNotSupportedException.class + }, + { + Status.FAILED_PRECONDITION, + FeatureNotEnabledError.getDefaultInstance(), + FeatureNotEnabledException.class + }, + { + Status.FAILED_PRECONDITION, + DomainNotActiveError.getDefaultInstance(), + DomainNotActiveException.class + }, + { + Status.FAILED_PRECONDITION, + ClientVersionNotSupportedError.getDefaultInstance(), + ClientVersionNotSupportedException.class + }, + { + Status.FAILED_PRECONDITION, + FeatureNotEnabledError.getDefaultInstance(), + FeatureNotEnabledException.class + }, + { + Status.RESOURCE_EXHAUSTED, + LimitExceededError.getDefaultInstance(), + LimitExceededException.class + }, + {Status.DATA_LOSS, null, InternalDataInconsistencyException.class}, + { + Status.RESOURCE_EXHAUSTED, + ServiceBusyError.getDefaultInstance(), + ServiceBusyException.class + }, + {Status.INTERNAL, null, InternalServiceException.class} + }; + return Arrays.asList(data); + } + + @Test + public void testErrorMapper() { + com.google.rpc.Status.Builder builder = + com.google.rpc.Status.newBuilder().setCode(status.getCode().value()); + + if (detail != null) { + builder.addDetails(Any.pack(detail)); + } + + StatusRuntimeException ex = StatusProto.toStatusRuntimeException(builder.build()); + ServiceClientException result = ErrorMapper.Error(ex); + assertEquals(expectedException, result.getClass()); + } +} From b3c999fe9b66d9708bb17c9ab1109a8dd334a5ce Mon Sep 17 00:00:00 2001 From: Shijie Sheng Date: Tue, 8 Apr 2025 15:45:15 -0700 Subject: [PATCH 3/3] remove unused exceptions --- .../exceptions/QueryFailedException.java | 20 ------------------- .../StickyWorkerUnavailableException.java | 20 ------------------- 2 files changed, 40 deletions(-) delete mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java delete mode 100644 src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java deleted file mode 100644 index d808b777f..000000000 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/QueryFailedException.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.uber.cadence.serviceclient.exceptions; - -public class QueryFailedException extends ServiceClientException {} diff --git a/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java b/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java deleted file mode 100644 index 2a74ea327..000000000 --- a/src/main/java/com/uber/cadence/serviceclient/exceptions/StickyWorkerUnavailableException.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Modifications copyright (C) 2017 Uber Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not - * use this file except in compliance with the License. A copy of the License is - * located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.uber.cadence.serviceclient.exceptions; - -public class StickyWorkerUnavailableException extends ServiceClientException {}