-
Notifications
You must be signed in to change notification settings - Fork 115
add serviceclient exceptions #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class AccessDeniedException extends ServiceClientException { | ||
|
||
public AccessDeniedException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class CancellationAlreadyRequestedException extends ServiceClientException { | ||
public CancellationAlreadyRequestedException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class DomainAlreadyExistsException extends ServiceClientException { | ||
public DomainAlreadyExistsException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class EntityNotExistsException extends ServiceClientException { | ||
|
||
public EntityNotExistsException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class InternalDataInconsistencyException extends ServiceClientException{ | ||
public InternalDataInconsistencyException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class InternalServiceException extends ServiceClientException{ | ||
public InternalServiceException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class LimitExceededException extends ServiceClientException { | ||
public LimitExceededException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class QueryFailedException extends ServiceClientException { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class ServiceBusyException extends ServiceClientException { | ||
public ServiceBusyException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
/** | ||
* Base class for all exceptions thrown by the service client. | ||
* | ||
* <p>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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class StickyWorkerUnavailableException extends ServiceClientException { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.uber.cadence.serviceclient.exceptions; | ||
|
||
public class WorkflowExecutionAlreadyCompletedException extends ServiceClientException { | ||
public WorkflowExecutionAlreadyCompletedException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: When can this happen? What kind of exception does GRPC throw if we have a connection issue rather than an error returned by the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Server controls whether to pass details. https://github.com/uber/cadence/blob/f4e219ae4248552e53a8ba57036b9af62485221b/common/types/mapper/proto/errors.go#L274
I've simplified the logic to handle such cases.