From 55ab3ea26979128b616fd915ada46c27fe0fb807 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 14 Apr 2017 16:02:39 -0700 Subject: [PATCH] Update definition of AlluxioTException --- .../block/RetryHandlingBlockWorkerClient.java | 11 +- .../src/main/java/alluxio/AbstractClient.java | 19 +- .../java/alluxio/AbstractThriftClient.java | 28 +- .../alluxio/exception/AlluxioException.java | 115 --------- .../status/AlluxioStatusException.java | 52 ++++ .../alluxio/thrift/AlluxioTException.java | 239 ++++++------------ .../exception/AlluxioExceptionTest.java | 28 -- core/common/src/thrift/exception.thrift | 3 +- .../src/main/java/alluxio/RpcUtils.java | 19 +- 9 files changed, 167 insertions(+), 347 deletions(-) delete mode 100644 core/common/src/test/java/alluxio/exception/AlluxioExceptionTest.java diff --git a/core/client/src/main/java/alluxio/client/block/RetryHandlingBlockWorkerClient.java b/core/client/src/main/java/alluxio/client/block/RetryHandlingBlockWorkerClient.java index fc5a2213c4bd..4cc187a5db19 100644 --- a/core/client/src/main/java/alluxio/client/block/RetryHandlingBlockWorkerClient.java +++ b/core/client/src/main/java/alluxio/client/block/RetryHandlingBlockWorkerClient.java @@ -22,7 +22,7 @@ import alluxio.exception.ExceptionMessage; import alluxio.exception.UfsBlockAccessTokenUnavailableException; import alluxio.exception.WorkerOutOfSpaceException; -import alluxio.exception.status.UnavailableException; +import alluxio.exception.status.AlluxioStatusException; import alluxio.metrics.MetricsSystem; import alluxio.retry.CountingRetry; import alluxio.retry.ExponentialBackoffRetry; @@ -349,12 +349,9 @@ public void sessionHeartbeat(RetryPolicy retryPolicy) throws IOException, Interr Metrics.BLOCK_WORKER_HEATBEATS.inc(); return; } catch (AlluxioTException e) { - AlluxioException ae = AlluxioException.fromThrift(e); - LOG.warn(ae.getMessage()); - throw new IOException(ae); - } catch (UnavailableException e) { - LOG.warn(e.getMessage()); - throw new IOException(e); + AlluxioStatusException se = AlluxioStatusException.fromThrift(e); + LOG.warn(se.getMessage()); + throw new IOException(se); } catch (TException e) { client.getOutputProtocol().getTransport().close(); exception = e; diff --git a/core/common/src/main/java/alluxio/AbstractClient.java b/core/common/src/main/java/alluxio/AbstractClient.java index accaf0b7ac89..7d6d792852ca 100644 --- a/core/common/src/main/java/alluxio/AbstractClient.java +++ b/core/common/src/main/java/alluxio/AbstractClient.java @@ -15,7 +15,8 @@ import alluxio.exception.ConnectionFailedException; import alluxio.exception.ExceptionMessage; import alluxio.exception.PreconditionMessage; -import alluxio.exception.status.UnavailableException; +import alluxio.exception.status.AlluxioStatusException; +import alluxio.exception.status.ExceptionStatus; import alluxio.retry.ExponentialBackoffRetry; import alluxio.retry.RetryPolicy; import alluxio.security.authentication.TransportProvider; @@ -320,10 +321,12 @@ protected synchronized V retryRPC(RpcCallable rpc) throws IOException, connect(); try { return rpc.call(); - } catch (UnavailableException e) { - throw new IOException(e); } catch (AlluxioTException e) { - throw new RuntimeException(AlluxioException.fromThrift(e)); + AlluxioStatusException se = AlluxioStatusException.fromThrift(e); + if (se.getStatus() == ExceptionStatus.UNAVAILABLE) { + throw new IOException(e); + } + throw se; } catch (TException e) { LOG.error(e.getMessage(), e); disconnect(); @@ -356,9 +359,11 @@ protected synchronized V retryRPC(RpcCallableThrowsAlluxioTException rpc) try { return rpc.call(); } catch (AlluxioTException e) { - throw AlluxioException.fromThrift(e); - } catch (UnavailableException e) { - throw new IOException(e); + AlluxioStatusException se = AlluxioStatusException.fromThrift(e); + if (se.getStatus() == ExceptionStatus.UNAVAILABLE) { + throw new IOException(e); + } + throw se; } catch (TException e) { LOG.error(e.getMessage(), e); disconnect(); diff --git a/core/common/src/main/java/alluxio/AbstractThriftClient.java b/core/common/src/main/java/alluxio/AbstractThriftClient.java index d8491fe76a9b..bb52298d7a83 100644 --- a/core/common/src/main/java/alluxio/AbstractThriftClient.java +++ b/core/common/src/main/java/alluxio/AbstractThriftClient.java @@ -12,7 +12,8 @@ package alluxio; import alluxio.exception.AlluxioException; -import alluxio.exception.status.UnavailableException; +import alluxio.exception.status.AlluxioStatusException; +import alluxio.exception.status.ExceptionStatus; import alluxio.network.connection.ThriftClientPool; import alluxio.retry.ExponentialBackoffRetry; import alluxio.retry.RetryPolicy; @@ -106,16 +107,18 @@ protected V retryRPC(RpcCallable rpc) throws IOException { C client = acquireClient(); try { return rpc.call(client); - } catch (UnavailableException e) { - throw new IOException(e); } catch (AlluxioTException e) { - AlluxioException ae = AlluxioException.fromThrift(e); + AlluxioStatusException se = AlluxioStatusException.fromThrift(e); + if (se.getStatus() == ExceptionStatus.UNAVAILABLE) { + throw new IOException(e); + } try { - processException(client, ae); - } catch (AlluxioException ee) { + // TODO(andrew): figure out what's going on here and fix it + processException(client, se); + } catch (AlluxioStatusException ee) { throw new IOException(ee); } - exception = new TException(ae); + exception = new TException(se); } catch (TException e) { LOG.warn(e.getMessage()); closeClient(client); @@ -151,11 +154,12 @@ protected V retryRPC(RpcCallableThrowsAlluxioTException rpc) try { return rpc.call(client); } catch (AlluxioTException e) { - AlluxioException ae = AlluxioException.fromThrift(e); - processException(client, ae); - exception = new TException(ae); - } catch (UnavailableException e) { - throw new IOException(e); + AlluxioStatusException se = AlluxioStatusException.fromThrift(e); + if (se.getStatus() == ExceptionStatus.UNAVAILABLE) { + throw new IOException(e); + } + processException(client, se); + exception = new TException(se); } catch (TException e) { LOG.error(e.getMessage(), e); closeClient(client); diff --git a/core/common/src/main/java/alluxio/exception/AlluxioException.java b/core/common/src/main/java/alluxio/exception/AlluxioException.java index 04b0d2a95721..0a76b3567750 100644 --- a/core/common/src/main/java/alluxio/exception/AlluxioException.java +++ b/core/common/src/main/java/alluxio/exception/AlluxioException.java @@ -59,119 +59,4 @@ protected AlluxioException(String message) { protected AlluxioException(String message, Throwable cause) { super(message, cause); } - - /** - * Constructs a {@link AlluxioTException} from a {@link AlluxioException}. - * - * @return a {@link AlluxioTException} of the type of this exception - */ - public AlluxioTException toThrift() { - return new AlluxioTException(AlluxioExceptionType.getAlluxioExceptionType(getClass()), - getMessage(), getClass().getName()); - } - - /** - * Converts an Alluxio exception from Thrift representation to native representation. - * - * @param e the Alluxio Thrift exception - * @return the native Alluxio exception - */ - public static AlluxioException fromThrift(AlluxioTException e) { - Class throwClass; - if (e.isSetClassName()) { - // server version 1.1.0 or newer - try { - throwClass = (Class) Class.forName(e.getClassName()); - } catch (ClassNotFoundException ee) { - // this can happen when the client is talking to a newer version of a server that - // introduced an exception that the client does not recognize - return new AlluxioException(e.getMessage()); - } - } else { - // server version 1.0.x - throwClass = AlluxioExceptionType.getAlluxioExceptionClass(e.getType()); - if (throwClass == null) { - return new AlluxioException(e.getMessage()); - } - } - try { - return throwClass.getConstructor(String.class).newInstance(e.getMessage()); - } catch (ReflectiveOperationException ee) { - String errorMessage = String - .format("Could not instantiate %s with a String-only constructor: %s", e.getType(), - ee.getMessage()); - throw new IllegalStateException(errorMessage, ee); - } - } - - /** - * Holds the different types of exceptions thrown by Alluxio. - * - * @deprecated since version 1.1 and will be removed in version 2.0 - */ - @ThreadSafe - @Deprecated - private enum AlluxioExceptionType { - ACCESS_CONTROL(AccessControlException.class), - BLOCK_ALREADY_EXISTS(BlockAlreadyExistsException.class), - BLOCK_DOES_NOT_EXIST(BlockDoesNotExistException.class), - BLOCK_INFO(BlockInfoException.class), - CONNECTION_FAILED(ConnectionFailedException.class), - DEPENDENCY_DOES_NOT_EXIST(DependencyDoesNotExistException.class), - DIRECTORY_NOT_EMPTY_EXCEPTION(DirectoryNotEmptyException.class), - FAILED_TO_CHECKPOINT(FailedToCheckpointException.class), - FILE_ALREADY_COMPLETED(FileAlreadyCompletedException.class), - FILE_ALREADY_EXISTS(FileAlreadyExistsException.class), - FILE_DOES_NOT_EXIST(FileDoesNotExistException.class), - INVALID_FILE_SIZE(InvalidFileSizeException.class), - INVALID_PATH(InvalidPathException.class), - INVALID_WORKER_STATE(InvalidWorkerStateException.class), - LINEAGE_DELETION(LineageDeletionException.class), - LINEAGE_DOES_NOT_EXIST(LineageDoesNotExistException.class), - NO_WORKER(NoWorkerException.class), - WORKER_OUT_OF_SPACE(WorkerOutOfSpaceException.class); - - private final Class mExceptionClass; - - /** - * Constructs a {@link AlluxioExceptionType} with its corresponding {@link AlluxioException}. - */ - AlluxioExceptionType(Class exceptionClass) { - mExceptionClass = exceptionClass; - } - - /** - * Produces an Alluxio exception whose type matches the given name. - * - * @param text the type name - * @return the Alluxio exception - */ - static Class getAlluxioExceptionClass(String text) { - if (text != null) { - for (AlluxioExceptionType t : AlluxioExceptionType.values()) { - if (text.equalsIgnoreCase(t.name())) { - return t.mExceptionClass; - } - } - } - return null; - } - - /** - * Produces the type name for the type that matches the given Alluxio exception. - * - * @param e the Alluxio exception - * @return the type name - */ - static String getAlluxioExceptionType(Class e) { - if (e != null) { - for (AlluxioExceptionType t : AlluxioExceptionType.values()) { - if (t.mExceptionClass.equals(e)) { - return t.name(); - } - } - } - return null; - } - } } diff --git a/core/common/src/main/java/alluxio/exception/status/AlluxioStatusException.java b/core/common/src/main/java/alluxio/exception/status/AlluxioStatusException.java index 3458352f4cbd..f538586b48e3 100644 --- a/core/common/src/main/java/alluxio/exception/status/AlluxioStatusException.java +++ b/core/common/src/main/java/alluxio/exception/status/AlluxioStatusException.java @@ -31,6 +31,7 @@ import alluxio.exception.NoWorkerException; import alluxio.exception.UfsBlockAccessTokenUnavailableException; import alluxio.exception.WorkerOutOfSpaceException; +import alluxio.thrift.AlluxioTException; import java.io.FileNotFoundException; import java.io.IOException; @@ -83,6 +84,57 @@ public ExceptionStatus getStatus() { return mStatus; } + /** + * @return the Thrift representation of this exception + */ + public AlluxioTException toThrift() { + return new AlluxioTException(getMessage(), ExceptionStatus.toThrift(mStatus)); + } + + /** + * Converts an Alluxio exception from Thrift representation to native representation. + * + * @param e the Alluxio Thrift exception + * @return the native Alluxio exception + */ + public static AlluxioStatusException fromThrift(AlluxioTException e) { + String m = e.getMessage(); + switch (e.getStatus()) { + case CANCELED: + return new CanceledException(m); + case INVALID_ARGUMENT: + return new InvalidArgumentException(m); + case DEADLINE_EXCEEDED: + return new DeadlineExceededException(m); + case NOT_FOUND: + return new NotFoundException(m); + case ALREADY_EXISTS: + return new AlreadyExistsException(m); + case PERMISSION_DENIED: + return new PermissionDeniedException(m); + case UNAUTHENTICATED: + return new UnauthenticatedException(m); + case RESOURCE_EXHAUSTED: + return new ResourceExhaustedException(m); + case FAILED_PRECONDITION: + return new FailedPreconditionException(m); + case ABORTED: + return new AbortedException(m); + case OUT_OF_RANGE: + return new OutOfRangeException(m); + case UNIMPLEMENTED: + return new UnimplementedException(m); + case INTERNAL: + return new InternalException(m); + case UNAVAILABLE: + return new UnavailableException(m); + case DATA_LOSS: + return new DataLossException(m); + default: + return new UnknownException(m); + } + } + /** * Converts checked Alluxio exceptions to Alluxio status exceptions. * diff --git a/core/common/src/main/java/alluxio/thrift/AlluxioTException.java b/core/common/src/main/java/alluxio/thrift/AlluxioTException.java index b2967915b6be..fea7c69a5ebd 100644 --- a/core/common/src/main/java/alluxio/thrift/AlluxioTException.java +++ b/core/common/src/main/java/alluxio/thrift/AlluxioTException.java @@ -38,9 +38,8 @@ public class AlluxioTException extends TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("AlluxioTException"); - private static final org.apache.thrift.protocol.TField TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("type", org.apache.thrift.protocol.TType.STRING, (short)1); private static final org.apache.thrift.protocol.TField MESSAGE_FIELD_DESC = new org.apache.thrift.protocol.TField("message", org.apache.thrift.protocol.TType.STRING, (short)2); - private static final org.apache.thrift.protocol.TField CLASS_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("className", org.apache.thrift.protocol.TType.STRING, (short)3); + private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.I32, (short)4); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { @@ -48,15 +47,17 @@ public class AlluxioTException extends TException implements org.apache.thrift.T schemes.put(TupleScheme.class, new AlluxioTExceptionTupleSchemeFactory()); } - private String type; // required private String message; // required - private String className; // required + private TExceptionStatus status; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { - TYPE((short)1, "type"), MESSAGE((short)2, "message"), - CLASS_NAME((short)3, "className"); + /** + * + * @see TExceptionStatus + */ + STATUS((short)4, "status"); private static final Map byName = new HashMap(); @@ -71,12 +72,10 @@ public enum _Fields implements org.apache.thrift.TFieldIdEnum { */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { - case 1: // TYPE - return TYPE; case 2: // MESSAGE return MESSAGE; - case 3: // CLASS_NAME - return CLASS_NAME; + case 4: // STATUS + return STATUS; default: return null; } @@ -120,12 +119,10 @@ public String getFieldName() { public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.TYPE, new org.apache.thrift.meta_data.FieldMetaData("type", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.MESSAGE, new org.apache.thrift.meta_data.FieldMetaData("message", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); - tmpMap.put(_Fields.CLASS_NAME, new org.apache.thrift.meta_data.FieldMetaData("className", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, TExceptionStatus.class))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(AlluxioTException.class, metaDataMap); } @@ -134,28 +131,23 @@ public AlluxioTException() { } public AlluxioTException( - String type, String message, - String className) + TExceptionStatus status) { this(); - this.type = type; this.message = message; - this.className = className; + this.status = status; } /** * Performs a deep copy on other. */ public AlluxioTException(AlluxioTException other) { - if (other.isSetType()) { - this.type = other.type; - } if (other.isSetMessage()) { this.message = other.message; } - if (other.isSetClassName()) { - this.className = other.className; + if (other.isSetStatus()) { + this.status = other.status; } } @@ -165,33 +157,8 @@ public AlluxioTException deepCopy() { @Override public void clear() { - this.type = null; this.message = null; - this.className = null; - } - - public String getType() { - return this.type; - } - - public AlluxioTException setType(String type) { - this.type = type; - return this; - } - - public void unsetType() { - this.type = null; - } - - /** Returns true if field type is set (has been assigned a value) and false otherwise */ - public boolean isSetType() { - return this.type != null; - } - - public void setTypeIsSet(boolean value) { - if (!value) { - this.type = null; - } + this.status = null; } public String getMessage() { @@ -218,40 +185,40 @@ public void setMessageIsSet(boolean value) { } } - public String getClassName() { - return this.className; + /** + * + * @see TExceptionStatus + */ + public TExceptionStatus getStatus() { + return this.status; } - public AlluxioTException setClassName(String className) { - this.className = className; + /** + * + * @see TExceptionStatus + */ + public AlluxioTException setStatus(TExceptionStatus status) { + this.status = status; return this; } - public void unsetClassName() { - this.className = null; + public void unsetStatus() { + this.status = null; } - /** Returns true if field className is set (has been assigned a value) and false otherwise */ - public boolean isSetClassName() { - return this.className != null; + /** Returns true if field status is set (has been assigned a value) and false otherwise */ + public boolean isSetStatus() { + return this.status != null; } - public void setClassNameIsSet(boolean value) { + public void setStatusIsSet(boolean value) { if (!value) { - this.className = null; + this.status = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { - case TYPE: - if (value == null) { - unsetType(); - } else { - setType((String)value); - } - break; - case MESSAGE: if (value == null) { unsetMessage(); @@ -260,11 +227,11 @@ public void setFieldValue(_Fields field, Object value) { } break; - case CLASS_NAME: + case STATUS: if (value == null) { - unsetClassName(); + unsetStatus(); } else { - setClassName((String)value); + setStatus((TExceptionStatus)value); } break; @@ -273,14 +240,11 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { - case TYPE: - return getType(); - case MESSAGE: return getMessage(); - case CLASS_NAME: - return getClassName(); + case STATUS: + return getStatus(); } throw new IllegalStateException(); @@ -293,12 +257,10 @@ public boolean isSet(_Fields field) { } switch (field) { - case TYPE: - return isSetType(); case MESSAGE: return isSetMessage(); - case CLASS_NAME: - return isSetClassName(); + case STATUS: + return isSetStatus(); } throw new IllegalStateException(); } @@ -316,15 +278,6 @@ public boolean equals(AlluxioTException that) { if (that == null) return false; - boolean this_present_type = true && this.isSetType(); - boolean that_present_type = true && that.isSetType(); - if (this_present_type || that_present_type) { - if (!(this_present_type && that_present_type)) - return false; - if (!this.type.equals(that.type)) - return false; - } - boolean this_present_message = true && this.isSetMessage(); boolean that_present_message = true && that.isSetMessage(); if (this_present_message || that_present_message) { @@ -334,12 +287,12 @@ public boolean equals(AlluxioTException that) { return false; } - boolean this_present_className = true && this.isSetClassName(); - boolean that_present_className = true && that.isSetClassName(); - if (this_present_className || that_present_className) { - if (!(this_present_className && that_present_className)) + boolean this_present_status = true && this.isSetStatus(); + boolean that_present_status = true && that.isSetStatus(); + if (this_present_status || that_present_status) { + if (!(this_present_status && that_present_status)) return false; - if (!this.className.equals(that.className)) + if (!this.status.equals(that.status)) return false; } @@ -350,20 +303,15 @@ public boolean equals(AlluxioTException that) { public int hashCode() { List list = new ArrayList(); - boolean present_type = true && (isSetType()); - list.add(present_type); - if (present_type) - list.add(type); - boolean present_message = true && (isSetMessage()); list.add(present_message); if (present_message) list.add(message); - boolean present_className = true && (isSetClassName()); - list.add(present_className); - if (present_className) - list.add(className); + boolean present_status = true && (isSetStatus()); + list.add(present_status); + if (present_status) + list.add(status.getValue()); return list.hashCode(); } @@ -376,16 +324,6 @@ public int compareTo(AlluxioTException other) { int lastComparison = 0; - lastComparison = Boolean.valueOf(isSetType()).compareTo(other.isSetType()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetType()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.type, other.type); - if (lastComparison != 0) { - return lastComparison; - } - } lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage()); if (lastComparison != 0) { return lastComparison; @@ -396,12 +334,12 @@ public int compareTo(AlluxioTException other) { return lastComparison; } } - lastComparison = Boolean.valueOf(isSetClassName()).compareTo(other.isSetClassName()); + lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); if (lastComparison != 0) { return lastComparison; } - if (isSetClassName()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.className, other.className); + if (isSetStatus()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); if (lastComparison != 0) { return lastComparison; } @@ -426,14 +364,6 @@ public String toString() { StringBuilder sb = new StringBuilder("AlluxioTException("); boolean first = true; - sb.append("type:"); - if (this.type == null) { - sb.append("null"); - } else { - sb.append(this.type); - } - first = false; - if (!first) sb.append(", "); sb.append("message:"); if (this.message == null) { sb.append("null"); @@ -442,11 +372,11 @@ public String toString() { } first = false; if (!first) sb.append(", "); - sb.append("className:"); - if (this.className == null) { + sb.append("status:"); + if (this.status == null) { sb.append("null"); } else { - sb.append(this.className); + sb.append(this.status); } first = false; sb.append(")"); @@ -492,14 +422,6 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, AlluxioTException s break; } switch (schemeField.id) { - case 1: // TYPE - if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { - struct.type = iprot.readString(); - struct.setTypeIsSet(true); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); - } - break; case 2: // MESSAGE if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.message = iprot.readString(); @@ -508,10 +430,10 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, AlluxioTException s org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; - case 3: // CLASS_NAME - if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { - struct.className = iprot.readString(); - struct.setClassNameIsSet(true); + case 4: // STATUS + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.status = alluxio.thrift.TExceptionStatus.findByValue(iprot.readI32()); + struct.setStatusIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -531,19 +453,14 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, AlluxioTException struct.validate(); oprot.writeStructBegin(STRUCT_DESC); - if (struct.type != null) { - oprot.writeFieldBegin(TYPE_FIELD_DESC); - oprot.writeString(struct.type); - oprot.writeFieldEnd(); - } if (struct.message != null) { oprot.writeFieldBegin(MESSAGE_FIELD_DESC); oprot.writeString(struct.message); oprot.writeFieldEnd(); } - if (struct.className != null) { - oprot.writeFieldBegin(CLASS_NAME_FIELD_DESC); - oprot.writeString(struct.className); + if (struct.status != null) { + oprot.writeFieldBegin(STATUS_FIELD_DESC); + oprot.writeI32(struct.status.getValue()); oprot.writeFieldEnd(); } oprot.writeFieldStop(); @@ -564,42 +481,32 @@ private static class AlluxioTExceptionTupleScheme extends TupleScheme the return type of the callable * @return the return value from calling the callable - * @throws AlluxioTException if the callable throws an Alluxio or runtime exception + * @throws AlluxioTException if the callable throws an exception */ public static T call(Logger logger, RpcCallable callable) throws AlluxioTException { try { return callable.call(); } catch (AlluxioException e) { logger.debug("{}, Error={}", callable, e.getMessage()); - throw e.toThrift(); - } catch (Exception e) { + throw AlluxioStatusException.fromAlluxioException(e); + } catch (RuntimeException e) { logger.error("{}", callable, e); - throw new UnexpectedAlluxioException(e).toThrift(); + throw AlluxioStatusException.fromRuntimeException(e); } } @@ -60,14 +59,14 @@ public static T call(Logger logger, RpcCallableThrowsIOException callable return callable.call(); } catch (AlluxioException e) { logger.debug("{}, Error={}", callable, e.getMessage()); - throw e.toThrift(); + throw AlluxioStatusException.fromAlluxioException(e); } catch (IOException e) { logger.warn("{}, Error={}", callable, e.getMessage()); logger.debug("{}", callable, e); - throw new UnavailableException(e.getMessage()); - } catch (Exception e) { + throw AlluxioStatusException.fromIOException(e); + } catch (RuntimeException e) { logger.error("{}", callable, e); - throw new UnexpectedAlluxioException(e).toThrift(); + throw AlluxioStatusException.fromRuntimeException(e); } }