|
@@ -41,7 +41,7 @@ import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
|
|
|
import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
|
|
|
import org.apache.hadoop.ozone.om.helpers.ServiceInfo;
|
|
|
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
|
|
|
-import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
|
|
|
+import org.apache.hadoop.ozone.om.exceptions.OMException;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.AllocateBlockRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
@@ -189,6 +189,12 @@ import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.CancelDelegationTokenResponseProto;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
|
|
|
+import static org.apache.hadoop.ozone.om.exceptions.OMException.*;
|
|
|
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.TOKEN_ERROR_OTHER;
|
|
|
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.UNKNOWN;
|
|
|
+import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status.OK;
|
|
|
+import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Status.ACCESS_DENIED;
|
|
|
+
|
|
|
/**
|
|
|
* The client side implementation of OzoneManagerProtocol.
|
|
|
*/
|
|
@@ -288,7 +294,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
CreateVolumeResponse resp = submitRequest(omRequest)
|
|
|
.getCreateVolumeResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Volume creation failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -314,7 +320,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetVolumePropertyResponse resp = submitRequest(omRequest)
|
|
|
.getSetVolumePropertyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Volume owner change failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -340,7 +346,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetVolumePropertyResponse resp = submitRequest(omRequest)
|
|
|
.getSetVolumePropertyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Volume quota change failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -369,9 +375,9 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
CheckVolumeAccessResponse resp = submitRequest(omRequest)
|
|
|
.getCheckVolumeAccessResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.ACCESS_DENIED) {
|
|
|
+ if (resp.getStatus() == ACCESS_DENIED) {
|
|
|
return false;
|
|
|
- } else if (resp.getStatus() == Status.OK) {
|
|
|
+ } else if (resp.getStatus() == OK) {
|
|
|
return true;
|
|
|
} else {
|
|
|
throw new
|
|
@@ -397,7 +403,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
InfoVolumeResponse resp = submitRequest(omRequest).getInfoVolumeResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Info Volume failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -422,7 +428,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
DeleteVolumeResponse resp = submitRequest(omRequest)
|
|
|
.getDeleteVolumeResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Delete Volume failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -490,7 +496,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
ListVolumeResponse resp = submitRequest(omRequest).getListVolumeResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("List volume failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
@@ -520,7 +526,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
CreateBucketResponse resp = submitRequest(omRequest)
|
|
|
.getCreateBucketResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Bucket creation failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
@@ -548,7 +554,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
InfoBucketResponse resp = submitRequest(omRequest).getInfoBucketResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
return OmBucketInfo.getFromProtobuf(resp.getBucketInfo());
|
|
|
} else {
|
|
|
throw new IOException("Info Bucket failed, error: "
|
|
@@ -576,7 +582,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetBucketPropertyResponse resp = submitRequest(omRequest)
|
|
|
.getSetBucketPropertyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Setting bucket property failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
@@ -614,7 +620,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
ListBucketsResponse resp = submitRequest(omRequest)
|
|
|
.getListBucketsResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
buckets.addAll(
|
|
|
resp.getBucketInfoList().stream()
|
|
|
.map(OmBucketInfo::getFromProtobuf)
|
|
@@ -677,7 +683,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
CreateKeyResponse resp = submitRequest(omRequest).getCreateKeyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Create key failed, error:" + resp.getStatus());
|
|
|
}
|
|
|
return new OpenKeySession(resp.getID(),
|
|
@@ -703,7 +709,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
AllocateBlockResponse resp = submitRequest(omRequest)
|
|
|
.getAllocateBlockResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Allocate block failed, error:" +
|
|
|
resp.getStatus());
|
|
|
}
|
|
@@ -733,7 +739,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
CommitKeyResponse resp = submitRequest(omRequest).getCommitKeyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Commit key failed, error:" +
|
|
|
resp.getStatus());
|
|
|
}
|
|
@@ -756,7 +762,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
LookupKeyResponse resp = submitRequest(omRequest).getLookupKeyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Lookup key failed, error:" +
|
|
|
resp.getStatus());
|
|
|
}
|
|
@@ -780,7 +786,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
RenameKeyResponse resp = submitRequest(omRequest).getRenameKeyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Rename key failed, error:" +
|
|
|
resp.getStatus());
|
|
|
}
|
|
@@ -807,7 +813,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
DeleteKeyResponse resp = submitRequest(omRequest).getDeleteKeyResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Delete key failed, error:" +
|
|
|
resp.getStatus());
|
|
|
}
|
|
@@ -831,7 +837,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
DeleteBucketResponse resp = submitRequest(omRequest)
|
|
|
.getDeleteBucketResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new
|
|
|
IOException("Delete Bucket failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -865,7 +871,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
ListKeysResponse resp = submitRequest(omRequest).getListKeysResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
keys.addAll(
|
|
|
resp.getKeyInfoList().stream()
|
|
|
.map(OmKeyInfo::getFromProtobuf)
|
|
@@ -892,7 +898,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3CreateBucketResponse resp = submitRequest(omRequest)
|
|
|
.getCreateS3BucketResponse();
|
|
|
|
|
|
- if(resp.getStatus() != Status.OK) {
|
|
|
+ if(resp.getStatus() != OK) {
|
|
|
throw new IOException("Creating S3 bucket failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
@@ -912,7 +918,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3DeleteBucketResponse resp = submitRequest(omRequest)
|
|
|
.getDeleteS3BucketResponse();
|
|
|
|
|
|
- if(resp.getStatus() != Status.OK) {
|
|
|
+ if(resp.getStatus() != OK) {
|
|
|
throw new IOException("Creating S3 bucket failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
@@ -933,7 +939,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3BucketInfoResponse resp = submitRequest(omRequest)
|
|
|
.getInfoS3BucketResponse();
|
|
|
|
|
|
- if(resp.getStatus() != Status.OK) {
|
|
|
+ if(resp.getStatus() != OK) {
|
|
|
throw new IOException("GetOzoneBucketMapping failed, error:" + resp
|
|
|
.getStatus());
|
|
|
}
|
|
@@ -963,7 +969,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3ListBucketsResponse resp = submitRequest(omRequest)
|
|
|
.getListS3BucketsResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
buckets.addAll(
|
|
|
resp.getBucketInfoList().stream()
|
|
|
.map(OmBucketInfo::getFromProtobuf)
|
|
@@ -986,7 +992,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
final GetS3SecretResponse resp = submitRequest(omRequest)
|
|
|
.getGetS3SecretResponse();
|
|
|
|
|
|
- if(resp.getStatus() != Status.OK) {
|
|
|
+ if(resp.getStatus() != OK) {
|
|
|
throw new IOException("Fetch S3 Secret failed, error: " +
|
|
|
resp.getStatus());
|
|
|
} else {
|
|
@@ -1022,7 +1028,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
MultipartInfoInitiateResponse resp = submitRequest(omRequest)
|
|
|
.getInitiateMultiPartUploadResponse();
|
|
|
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
+ if (resp.getStatus() != OK) {
|
|
|
throw new IOException("Initiate Multipart upload failed, error:" + resp
|
|
|
.getStatus());
|
|
|
}
|
|
@@ -1064,7 +1070,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
MultipartCommitUploadPartResponse response = submitRequest(omRequest)
|
|
|
.getCommitMultiPartUploadResponse();
|
|
|
|
|
|
- if (response.getStatus() != Status.OK) {
|
|
|
+ if (response.getStatus() != OK) {
|
|
|
throw new IOException("Commit multipart upload part key failed, error:"
|
|
|
+ response.getStatus());
|
|
|
}
|
|
@@ -1099,7 +1105,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
MultipartUploadCompleteResponse response = submitRequest(omRequest)
|
|
|
.getCompleteMultiPartUploadResponse();
|
|
|
|
|
|
- if (response.getStatus() != Status.OK) {
|
|
|
+ if (response.getStatus() != OK) {
|
|
|
throw new IOException("Complete multipart upload failed, error:" +
|
|
|
response.getStatus());
|
|
|
}
|
|
@@ -1130,7 +1136,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
MultipartUploadAbortResponse response =
|
|
|
submitRequest(omRequest).getAbortMultiPartUploadResponse();
|
|
|
|
|
|
- if (response.getStatus() != Status.OK) {
|
|
|
+ if (response.getStatus() != OK) {
|
|
|
throw new IOException("Abort multipart upload failed, error:" +
|
|
|
response.getStatus());
|
|
|
}
|
|
@@ -1147,7 +1153,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
final ServiceListResponse resp = submitRequest(omRequest)
|
|
|
.getServiceListResponse();
|
|
|
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
return resp.getServiceInfoList().stream()
|
|
|
.map(ServiceInfo::getFromProtobuf)
|
|
|
.collect(Collectors.toList());
|
|
@@ -1162,11 +1168,11 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
*
|
|
|
* @param renewer the designated renewer for the token
|
|
|
* @return Token<OzoneDelegationTokenSelector>
|
|
|
- * @throws IOException
|
|
|
+ * @throws OMException
|
|
|
*/
|
|
|
@Override
|
|
|
public Token<OzoneTokenIdentifier> getDelegationToken(Text renewer)
|
|
|
- throws IOException {
|
|
|
+ throws OMException {
|
|
|
GetDelegationTokenRequestProto req = GetDelegationTokenRequestProto
|
|
|
.newBuilder()
|
|
|
.setRenewer(renewer == null ? "" : renewer.toString())
|
|
@@ -1176,15 +1182,23 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setGetDelegationTokenRequest(req)
|
|
|
.build();
|
|
|
|
|
|
- final GetDelegationTokenResponseProto resp = submitRequest(omRequest)
|
|
|
- .getGetDelegationTokenResponse();
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
- return resp.getResponse().hasToken() ?
|
|
|
- OMPBHelper.convertToDelegationToken(resp.getResponse().getToken())
|
|
|
- : null;
|
|
|
- } else {
|
|
|
- throw new IOException("Get Delegation Token failed, error : " + resp
|
|
|
- .getStatus());
|
|
|
+ final GetDelegationTokenResponseProto resp;
|
|
|
+ try {
|
|
|
+ resp = submitRequest(omRequest).getGetDelegationTokenResponse();
|
|
|
+
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
+ return resp.getResponse().hasToken() ?
|
|
|
+ OMPBHelper.convertToDelegationToken(resp.getResponse().getToken())
|
|
|
+ : null;
|
|
|
+ }
|
|
|
+ throw new OMException("Get delegation token failed with response:"
|
|
|
+ + resp.getStatus(), toResultStatus(resp.getStatus()));
|
|
|
+ } catch (IOException e) {
|
|
|
+ if(e instanceof OMException) {
|
|
|
+ throw (OMException)e;
|
|
|
+ }
|
|
|
+ throw new OMException("Get delegation token failed.", e,
|
|
|
+ TOKEN_ERROR_OTHER);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1193,11 +1207,10 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
*
|
|
|
* @param token delegation token obtained earlier
|
|
|
* @return the new expiration time
|
|
|
- * @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
public long renewDelegationToken(Token<OzoneTokenIdentifier> token)
|
|
|
- throws IOException {
|
|
|
+ throws OMException {
|
|
|
RenewDelegationTokenRequestProto req =
|
|
|
RenewDelegationTokenRequestProto.newBuilder().
|
|
|
setToken(OMPBHelper.convertToTokenProto(token)).
|
|
@@ -1207,13 +1220,21 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setRenewDelegationTokenRequest(req)
|
|
|
.build();
|
|
|
|
|
|
- final RenewDelegationTokenResponseProto resp = submitRequest(omRequest)
|
|
|
- .getRenewDelegationTokenResponse();
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
- return resp.getResponse().getNewExpiryTime();
|
|
|
- } else {
|
|
|
- throw new IOException("Renew Delegation Token failed, error : " + resp
|
|
|
- .getStatus());
|
|
|
+ final RenewDelegationTokenResponseProto resp;
|
|
|
+ try {
|
|
|
+ resp = submitRequest(omRequest)
|
|
|
+ .getRenewDelegationTokenResponse();
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
+ return resp.getResponse().getNewExpiryTime();
|
|
|
+ }
|
|
|
+ throw new OMException("Renew delegation token failed with response:"
|
|
|
+ + resp.getStatus(), toResultStatus(resp.getStatus()));
|
|
|
+ } catch (IOException e) {
|
|
|
+ if(e instanceof OMException) {
|
|
|
+ throw (OMException)e;
|
|
|
+ }
|
|
|
+ throw new OMException("Renew delegation token failed.", e,
|
|
|
+ TOKEN_ERROR_OTHER);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1221,11 +1242,10 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
* Cancel an existing delegation token.
|
|
|
*
|
|
|
* @param token delegation token
|
|
|
- * @throws IOException
|
|
|
*/
|
|
|
@Override
|
|
|
public void cancelDelegationToken(Token<OzoneTokenIdentifier> token)
|
|
|
- throws IOException {
|
|
|
+ throws OMException {
|
|
|
CancelDelegationTokenRequestProto req = CancelDelegationTokenRequestProto
|
|
|
.newBuilder()
|
|
|
.setToken(OMPBHelper.convertToTokenProto(token))
|
|
@@ -1235,11 +1255,40 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setCancelDelegationTokenRequest(req)
|
|
|
.build();
|
|
|
|
|
|
- final CancelDelegationTokenResponseProto resp = submitRequest(omRequest)
|
|
|
- .getCancelDelegationTokenResponse();
|
|
|
- if (resp.getStatus() != Status.OK) {
|
|
|
- throw new IOException("Cancel Delegation Token failed, error : " + resp
|
|
|
- .getStatus());
|
|
|
+ final CancelDelegationTokenResponseProto resp;
|
|
|
+ try {
|
|
|
+ resp = submitRequest(omRequest).getCancelDelegationTokenResponse();
|
|
|
+ if (resp.getStatus() == OK) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ throw new OMException("Cancel delegation token failed with response:"
|
|
|
+ + resp.getStatus(), toResultStatus(resp.getStatus()));
|
|
|
+ } catch (IOException e) {
|
|
|
+ if(e instanceof OMException) {
|
|
|
+ throw (OMException)e;
|
|
|
+ }
|
|
|
+ throw new OMException("Cancel delegation token failed.", e,
|
|
|
+ TOKEN_ERROR_OTHER);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Converts proto status to OMException result code.
|
|
|
+ *
|
|
|
+ * @param status Proto status received from rpc call.
|
|
|
+ */
|
|
|
+ public ResultCodes toResultStatus(Status status) {
|
|
|
+ switch (status) {
|
|
|
+ case INVALID_AUTH_METHOD:
|
|
|
+ return ResultCodes.INVALID_AUTH_METHOD;
|
|
|
+ case INVALID_TOKEN:
|
|
|
+ return ResultCodes.INVALID_TOKEN;
|
|
|
+ case TOKEN_EXPIRED:
|
|
|
+ return ResultCodes.TOKEN_EXPIRED;
|
|
|
+ case TOKEN_ERROR_OTHER:
|
|
|
+ return TOKEN_ERROR_OTHER;
|
|
|
+ default:
|
|
|
+ return UNKNOWN;
|
|
|
}
|
|
|
}
|
|
|
}
|