Skip to content

Commit 0533432

Browse files
committed
add serviceclient exceptions
1 parent 8d0137a commit 0533432

17 files changed

+245
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.uber.cadence.internal.compatibility.proto;
2+
3+
import com.google.protobuf.Any;
4+
import com.google.protobuf.InvalidProtocolBufferException;
5+
import com.google.protobuf.Message;
6+
import com.google.rpc.Status;
7+
import com.uber.cadence.api.v1.*;
8+
import com.uber.cadence.serviceclient.exceptions.*;
9+
import io.grpc.StatusRuntimeException;
10+
import io.grpc.protobuf.StatusProto;
11+
12+
public class ErrorMapper {
13+
public static ServiceClientException Error(StatusRuntimeException e) {
14+
15+
Status status = StatusProto.fromThrowable(e);
16+
if (status == null || status.getDetailsCount() == 0) {
17+
return new ServiceClientException("empty status or status with empty details", e);
18+
}
19+
20+
Any detail = status.getDetails(0);
21+
22+
try {
23+
switch (e.getStatus().getCode()) {
24+
case PERMISSION_DENIED:
25+
return new AccessDeniedException(e);
26+
case INTERNAL:
27+
return new InternalServiceException(e);
28+
case NOT_FOUND:
29+
if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) {
30+
return new WorkflowExecutionAlreadyCompletedException(e);
31+
} else {
32+
return new EntityNotExistsException(e);
33+
}
34+
case ALREADY_EXISTS:
35+
if (detail.is(CancellationAlreadyRequestedError.class)) {
36+
return new CancellationAlreadyRequestedException(e);
37+
} else if (detail.is(DomainAlreadyExistsError.class)) {
38+
return new DomainAlreadyExistsException(e);
39+
} else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) {
40+
WorkflowExecutionAlreadyStartedError error = detail.unpack(WorkflowExecutionAlreadyStartedError.class);
41+
return new WorkflowExecutionAlreadyStartedException(error.getStartRequestId(), error.getRunId());
42+
}
43+
case DATA_LOSS:
44+
return new InternalDataInconsistencyException(e);
45+
case FAILED_PRECONDITION:
46+
if (detail.is(ClientVersionNotSupportedError.class)) {
47+
ClientVersionNotSupportedError error = detail.unpack(ClientVersionNotSupportedError.class);
48+
return new ClientVersionNotSupportedException(error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions());
49+
}else if (detail.is(FeatureNotEnabledError.class)) {
50+
FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class);
51+
return new FeatureNotEnabledException(error.getFeatureFlag());
52+
} else if (detail.is(DomainNotActiveError.class)) {
53+
DomainNotActiveError error = detail.unpack(DomainNotActiveError.class);
54+
return new DomainNotActiveException(error.getDomain(), error.getCurrentCluster(), error.getActiveCluster());
55+
}
56+
case RESOURCE_EXHAUSTED:
57+
if (detail.is(LimitExceededError.class)) {
58+
return new LimitExceededException(e);
59+
} else {
60+
return new ServiceBusyException(e);
61+
}
62+
case UNKNOWN:
63+
default:
64+
return new ServiceClientException(e);
65+
}
66+
} catch (InvalidProtocolBufferException ex) {
67+
return new ServiceClientException(ex);
68+
}
69+
}
70+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class AccessDeniedException extends ServiceClientException {
4+
5+
public AccessDeniedException(Throwable cause) {
6+
super(cause);
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class CancellationAlreadyRequestedException extends ServiceClientException {
4+
public CancellationAlreadyRequestedException(Throwable cause) {
5+
super(cause);
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class ClientVersionNotSupportedException extends ServiceClientException {
4+
private final String featureVersion;
5+
private final String clientImpl;
6+
private final String supportedVersions;
7+
8+
public ClientVersionNotSupportedException(String featureVersion, String clientImpl, String supportedVersions) {
9+
this.featureVersion = featureVersion;
10+
this.clientImpl = clientImpl;
11+
this.supportedVersions = supportedVersions;
12+
}
13+
14+
public String getFeatureVersion() {
15+
return featureVersion;
16+
}
17+
18+
public String getClientImpl() {
19+
return clientImpl;
20+
}
21+
22+
public String getSupportedVersions() {
23+
return supportedVersions;
24+
}
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class DomainAlreadyExistsException extends ServiceClientException {
4+
public DomainAlreadyExistsException(Throwable cause) {
5+
super(cause);
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class DomainNotActiveException extends ServiceClientException {
4+
private final String domain;
5+
private final String currentCluster;
6+
private final String activeCluster;
7+
8+
public DomainNotActiveException(String domain, String currentCluster, String activeCluster) {
9+
this.domain = domain;
10+
this.currentCluster = currentCluster;
11+
this.activeCluster = activeCluster;
12+
}
13+
14+
public String getDomain() {
15+
return domain;
16+
}
17+
18+
public String getCurrentCluster() {
19+
return currentCluster;
20+
}
21+
22+
public String getActiveCluster() {
23+
return activeCluster;
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class EntityNotExistsException extends ServiceClientException {
4+
5+
public EntityNotExistsException(Throwable cause) {
6+
super(cause);
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class FeatureNotEnabledException extends ServiceClientException {
4+
private final String featureFlag;
5+
6+
public FeatureNotEnabledException(String featureFlag) {
7+
this.featureFlag = featureFlag;
8+
}
9+
10+
public String getFeatureFlag() {
11+
return featureFlag;
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class InternalDataInconsistencyException extends ServiceClientException{
4+
public InternalDataInconsistencyException(Throwable cause) {
5+
super(cause);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.uber.cadence.serviceclient.exceptions;
2+
3+
public class InternalServiceException extends ServiceClientException{
4+
public InternalServiceException(Throwable cause) {
5+
super(cause);
6+
}
7+
}

0 commit comments

Comments
 (0)