|
@@ -19,9 +19,9 @@ package org.apache.hadoop.ozone.om.protocolPB;
|
|
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
import com.google.common.base.Strings;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import com.google.protobuf.RpcController;
|
|
|
import com.google.protobuf.ServiceException;
|
|
|
+import java.util.ArrayList;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.ipc.ProtobufHelper;
|
|
|
import org.apache.hadoop.ipc.ProtocolTranslator;
|
|
@@ -40,10 +40,18 @@ import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.AllocateBlockRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.AllocateBlockResponse;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto
|
|
|
+ .OzoneManagerProtocolProtos.CreateKeyRequest;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto
|
|
|
+ .OzoneManagerProtocolProtos.CreateKeyResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.CommitKeyRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.CommitKeyResponse;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto
|
|
|
+ .OzoneManagerProtocolProtos.DeleteKeyRequest;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto
|
|
|
+ .OzoneManagerProtocolProtos.DeleteKeyResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.BucketArgs;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
@@ -69,9 +77,9 @@ import org.apache.hadoop.ozone.protocol.proto
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.CreateVolumeResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
- .OzoneManagerProtocolProtos.LocateKeyRequest;
|
|
|
+ .OzoneManagerProtocolProtos.LookupKeyRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
- .OzoneManagerProtocolProtos.LocateKeyResponse;
|
|
|
+ .OzoneManagerProtocolProtos.LookupKeyResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
|
.MultipartCommitUploadPartRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
@@ -125,9 +133,9 @@ import org.apache.hadoop.ozone.protocol.proto
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.ServiceListResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
- .OzoneManagerProtocolProtos.S3BucketRequest;
|
|
|
+ .OzoneManagerProtocolProtos.S3CreateBucketRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
- .OzoneManagerProtocolProtos.S3BucketResponse;
|
|
|
+ .OzoneManagerProtocolProtos.S3CreateBucketResponse;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
|
.OzoneManagerProtocolProtos.S3DeleteBucketRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto
|
|
@@ -140,14 +148,15 @@ import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
|
.S3ListBucketsRequest;
|
|
|
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
|
.S3ListBucketsResponse;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
|
+ .OMRequest;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos
|
|
|
+ .OMResponse;
|
|
|
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
|
|
|
|
|
|
import java.io.Closeable;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -164,14 +173,16 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
private static final RpcController NULL_RPC_CONTROLLER = null;
|
|
|
|
|
|
private final OzoneManagerProtocolPB rpcProxy;
|
|
|
+ private final String clientID;
|
|
|
|
|
|
/**
|
|
|
* Constructor for KeySpaceManger Client.
|
|
|
* @param rpcProxy
|
|
|
*/
|
|
|
public OzoneManagerProtocolClientSideTranslatorPB(
|
|
|
- OzoneManagerProtocolPB rpcProxy) {
|
|
|
+ OzoneManagerProtocolPB rpcProxy, String clientId) {
|
|
|
this.rpcProxy = rpcProxy;
|
|
|
+ this.clientID = clientId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -192,6 +203,41 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Return the proxy object underlying this protocol translator.
|
|
|
+ *
|
|
|
+ * @return the proxy object underlying this protocol translator.
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Object getUnderlyingProxyObject() {
|
|
|
+ return rpcProxy;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns a OMRequest builder with specified type.
|
|
|
+ * @param cmdType type of the request
|
|
|
+ */
|
|
|
+ private OMRequest.Builder createOMRequest(Type cmdType) {
|
|
|
+ return OMRequest.newBuilder()
|
|
|
+ .setCmdType(cmdType)
|
|
|
+ .setClientId(clientID);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Submits client request to OM server.
|
|
|
+ * @param omRequest client request
|
|
|
+ * @return response from OM
|
|
|
+ * @throws IOException thrown if any Protobuf service exception occurs
|
|
|
+ */
|
|
|
+ private OMResponse submitRequest(OMRequest omRequest)
|
|
|
+ throws IOException {
|
|
|
+ try {
|
|
|
+ return rpcProxy.submitRequest(NULL_RPC_CONTROLLER, omRequest);
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ throw ProtobufHelper.getRemoteException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Creates a volume.
|
|
|
*
|
|
@@ -205,13 +251,12 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
VolumeInfo volumeInfo = args.getProtobuf();
|
|
|
req.setVolumeInfo(volumeInfo);
|
|
|
|
|
|
- final CreateVolumeResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.createVolume(NULL_RPC_CONTROLLER,
|
|
|
- req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CreateVolume)
|
|
|
+ .setCreateVolumeRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CreateVolumeResponse resp = submitRequest(omRequest)
|
|
|
+ .getCreateVolumeResponse();
|
|
|
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
@@ -231,12 +276,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetVolumePropertyRequest.Builder req =
|
|
|
SetVolumePropertyRequest.newBuilder();
|
|
|
req.setVolumeName(volume).setOwnerName(owner);
|
|
|
- final SetVolumePropertyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.setVolumeProperty(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.SetVolumeProperty)
|
|
|
+ .setSetVolumePropertyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ SetVolumePropertyResponse resp = submitRequest(omRequest)
|
|
|
+ .getSetVolumePropertyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
|
IOException("Volume owner change failed, error:" + resp.getStatus());
|
|
@@ -255,12 +302,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetVolumePropertyRequest.Builder req =
|
|
|
SetVolumePropertyRequest.newBuilder();
|
|
|
req.setVolumeName(volume).setQuotaInBytes(quota);
|
|
|
- final SetVolumePropertyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.setVolumeProperty(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.SetVolumeProperty)
|
|
|
+ .setSetVolumePropertyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ SetVolumePropertyResponse resp = submitRequest(omRequest)
|
|
|
+ .getSetVolumePropertyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
|
IOException("Volume quota change failed, error:" + resp.getStatus());
|
|
@@ -282,12 +331,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
CheckVolumeAccessRequest.Builder req =
|
|
|
CheckVolumeAccessRequest.newBuilder();
|
|
|
req.setVolumeName(volume).setUserAcl(userAcl);
|
|
|
- final CheckVolumeAccessResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.checkVolumeAccess(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CheckVolumeAccess)
|
|
|
+ .setCheckVolumeAccessRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CheckVolumeAccessResponse resp = submitRequest(omRequest)
|
|
|
+ .getCheckVolumeAccessResponse();
|
|
|
|
|
|
if (resp.getStatus() == Status.ACCESS_DENIED) {
|
|
|
return false;
|
|
@@ -310,12 +360,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
public OmVolumeArgs getVolumeInfo(String volume) throws IOException {
|
|
|
InfoVolumeRequest.Builder req = InfoVolumeRequest.newBuilder();
|
|
|
req.setVolumeName(volume);
|
|
|
- final InfoVolumeResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.infoVolume(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.InfoVolume)
|
|
|
+ .setInfoVolumeRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ InfoVolumeResponse resp = submitRequest(omRequest).getInfoVolumeResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
|
IOException("Info Volume failed, error:" + resp.getStatus());
|
|
@@ -333,12 +384,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
public void deleteVolume(String volume) throws IOException {
|
|
|
DeleteVolumeRequest.Builder req = DeleteVolumeRequest.newBuilder();
|
|
|
req.setVolumeName(volume);
|
|
|
- final DeleteVolumeResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.deleteVolume(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.DeleteVolume)
|
|
|
+ .setDeleteVolumeRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ DeleteVolumeResponse resp = submitRequest(omRequest)
|
|
|
+ .getDeleteVolumeResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
|
IOException("Delete Volume failed, error:" + resp.getStatus());
|
|
@@ -400,24 +453,18 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
private List<OmVolumeArgs> listVolume(ListVolumeRequest request)
|
|
|
throws IOException {
|
|
|
- final ListVolumeResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.listVolumes(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.ListVolume)
|
|
|
+ .setListVolumeRequest(request)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ ListVolumeResponse resp = submitRequest(omRequest).getListVolumeResponse();
|
|
|
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("List volume failed, error: "
|
|
|
+ resp.getStatus());
|
|
|
}
|
|
|
|
|
|
- List<OmVolumeArgs> result = Lists.newArrayList();
|
|
|
- for (VolumeInfo volInfo : resp.getVolumeInfoList()) {
|
|
|
- OmVolumeArgs volArgs = OmVolumeArgs.getFromProtobuf(volInfo);
|
|
|
- result.add(volArgs);
|
|
|
- }
|
|
|
-
|
|
|
return resp.getVolumeInfoList().stream()
|
|
|
.map(item -> OmVolumeArgs.getFromProtobuf(item))
|
|
|
.collect(Collectors.toList());
|
|
@@ -436,13 +483,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
BucketInfo bucketInfoProtobuf = bucketInfo.getProtobuf();
|
|
|
req.setBucketInfo(bucketInfoProtobuf);
|
|
|
|
|
|
- final CreateBucketResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.createBucket(NULL_RPC_CONTROLLER,
|
|
|
- req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CreateBucket)
|
|
|
+ .setCreateBucketRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CreateBucketResponse resp = submitRequest(omRequest)
|
|
|
+ .getCreateBucketResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Bucket creation failed, error: "
|
|
|
+ resp.getStatus());
|
|
@@ -465,13 +512,12 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
req.setVolumeName(volume);
|
|
|
req.setBucketName(bucket);
|
|
|
|
|
|
- final InfoBucketResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.infoBucket(NULL_RPC_CONTROLLER,
|
|
|
- req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.InfoBucket)
|
|
|
+ .setInfoBucketRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ InfoBucketResponse resp = submitRequest(omRequest).getInfoBucketResponse();
|
|
|
+
|
|
|
if (resp.getStatus() == Status.OK) {
|
|
|
return OmBucketInfo.getFromProtobuf(resp.getBucketInfo());
|
|
|
} else {
|
|
@@ -492,13 +538,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
SetBucketPropertyRequest.newBuilder();
|
|
|
BucketArgs bucketArgs = args.getProtobuf();
|
|
|
req.setBucketArgs(bucketArgs);
|
|
|
- final SetBucketPropertyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.setBucketProperty(NULL_RPC_CONTROLLER,
|
|
|
- req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.SetBucketProperty)
|
|
|
+ .setSetBucketPropertyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ SetBucketPropertyResponse resp = submitRequest(omRequest)
|
|
|
+ .getSetBucketPropertyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Setting bucket property failed, error: "
|
|
|
+ resp.getStatus());
|
|
@@ -529,12 +576,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
reqBuilder.setPrefix(prefix);
|
|
|
}
|
|
|
ListBucketsRequest request = reqBuilder.build();
|
|
|
- final ListBucketsResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.listBuckets(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.ListBuckets)
|
|
|
+ .setListBucketsRequest(request)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ ListBucketsResponse resp = submitRequest(omRequest)
|
|
|
+ .getListBucketsResponse();
|
|
|
|
|
|
if (resp.getStatus() == Status.OK) {
|
|
|
buckets.addAll(
|
|
@@ -557,7 +605,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
*/
|
|
|
@Override
|
|
|
public OpenKeySession openKey(OmKeyArgs args) throws IOException {
|
|
|
- LocateKeyRequest.Builder req = LocateKeyRequest.newBuilder();
|
|
|
+ CreateKeyRequest.Builder req = CreateKeyRequest.newBuilder();
|
|
|
KeyArgs.Builder keyArgs = KeyArgs.newBuilder()
|
|
|
.setVolumeName(args.getVolumeName())
|
|
|
.setBucketName(args.getBucketName())
|
|
@@ -584,12 +632,12 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
req.setKeyArgs(keyArgs.build());
|
|
|
|
|
|
- final LocateKeyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.createKey(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CreateKey)
|
|
|
+ .setCreateKeyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CreateKeyResponse resp = submitRequest(omRequest).getCreateKeyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Create key failed, error:" + resp.getStatus());
|
|
|
}
|
|
@@ -598,7 +646,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public OmKeyLocationInfo allocateBlock(OmKeyArgs args, long clientID)
|
|
|
+ public OmKeyLocationInfo allocateBlock(OmKeyArgs args, long clientId)
|
|
|
throws IOException {
|
|
|
AllocateBlockRequest.Builder req = AllocateBlockRequest.newBuilder();
|
|
|
KeyArgs keyArgs = KeyArgs.newBuilder()
|
|
@@ -607,14 +655,15 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setKeyName(args.getKeyName())
|
|
|
.setDataSize(args.getDataSize()).build();
|
|
|
req.setKeyArgs(keyArgs);
|
|
|
- req.setClientID(clientID);
|
|
|
+ req.setClientID(clientId);
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.AllocateBlock)
|
|
|
+ .setAllocateBlockRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ AllocateBlockResponse resp = submitRequest(omRequest)
|
|
|
+ .getAllocateBlockResponse();
|
|
|
|
|
|
- final AllocateBlockResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.allocateBlock(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Allocate block failed, error:" +
|
|
|
resp.getStatus());
|
|
@@ -623,7 +672,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void commitKey(OmKeyArgs args, long clientID)
|
|
|
+ public void commitKey(OmKeyArgs args, long clientId)
|
|
|
throws IOException {
|
|
|
CommitKeyRequest.Builder req = CommitKeyRequest.newBuilder();
|
|
|
List<OmKeyLocationInfo> locationInfoList = args.getLocationInfoList();
|
|
@@ -637,14 +686,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
locationInfoList.stream().map(OmKeyLocationInfo::getProtobuf)
|
|
|
.collect(Collectors.toList())).build();
|
|
|
req.setKeyArgs(keyArgs);
|
|
|
- req.setClientID(clientID);
|
|
|
+ req.setClientID(clientId);
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CommitKey)
|
|
|
+ .setCommitKeyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ CommitKeyResponse resp = submitRequest(omRequest).getCommitKeyResponse();
|
|
|
|
|
|
- final CommitKeyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.commitKey(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Commit key failed, error:" +
|
|
|
resp.getStatus());
|
|
@@ -654,7 +703,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
@Override
|
|
|
public OmKeyInfo lookupKey(OmKeyArgs args) throws IOException {
|
|
|
- LocateKeyRequest.Builder req = LocateKeyRequest.newBuilder();
|
|
|
+ LookupKeyRequest.Builder req = LookupKeyRequest.newBuilder();
|
|
|
KeyArgs keyArgs = KeyArgs.newBuilder()
|
|
|
.setVolumeName(args.getVolumeName())
|
|
|
.setBucketName(args.getBucketName())
|
|
@@ -662,12 +711,12 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setDataSize(args.getDataSize()).build();
|
|
|
req.setKeyArgs(keyArgs);
|
|
|
|
|
|
- final LocateKeyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.lookupKey(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.LookupKey)
|
|
|
+ .setLookupKeyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ LookupKeyResponse resp = submitRequest(omRequest).getLookupKeyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Lookup key failed, error:" +
|
|
|
resp.getStatus());
|
|
@@ -686,12 +735,12 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
req.setKeyArgs(keyArgs);
|
|
|
req.setToKeyName(toKeyName);
|
|
|
|
|
|
- final RenameKeyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.renameKey(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.RenameKey)
|
|
|
+ .setRenameKeyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ RenameKeyResponse resp = submitRequest(omRequest).getRenameKeyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Rename key failed, error:" +
|
|
|
resp.getStatus());
|
|
@@ -706,19 +755,19 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
*/
|
|
|
@Override
|
|
|
public void deleteKey(OmKeyArgs args) throws IOException {
|
|
|
- LocateKeyRequest.Builder req = LocateKeyRequest.newBuilder();
|
|
|
+ DeleteKeyRequest.Builder req = DeleteKeyRequest.newBuilder();
|
|
|
KeyArgs keyArgs = KeyArgs.newBuilder()
|
|
|
.setVolumeName(args.getVolumeName())
|
|
|
.setBucketName(args.getBucketName())
|
|
|
.setKeyName(args.getKeyName()).build();
|
|
|
req.setKeyArgs(keyArgs);
|
|
|
|
|
|
- final LocateKeyResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.deleteKey(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(Type.DeleteKey)
|
|
|
+ .setDeleteKeyRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ DeleteKeyResponse resp = submitRequest(omRequest).getDeleteKeyResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Delete key failed, error:" +
|
|
|
resp.getStatus());
|
|
@@ -735,12 +784,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
DeleteBucketRequest.Builder req = DeleteBucketRequest.newBuilder();
|
|
|
req.setVolumeName(volume);
|
|
|
req.setBucketName(bucket);
|
|
|
- final DeleteBucketResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.deleteBucket(NULL_RPC_CONTROLLER, req.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.DeleteBucket)
|
|
|
+ .setDeleteBucketRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ DeleteBucketResponse resp = submitRequest(omRequest)
|
|
|
+ .getDeleteBucketResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new
|
|
|
IOException("Delete Bucket failed, error:" + resp.getStatus());
|
|
@@ -767,13 +818,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
reqBuilder.setPrefix(prefix);
|
|
|
}
|
|
|
|
|
|
- ListKeysRequest request = reqBuilder.build();
|
|
|
- final ListKeysResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.listKeys(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ ListKeysRequest req = reqBuilder.build();
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.ListKeys)
|
|
|
+ .setListKeysRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ ListKeysResponse resp = submitRequest(omRequest).getListKeysResponse();
|
|
|
|
|
|
if (resp.getStatus() == Status.OK) {
|
|
|
keys.addAll(
|
|
@@ -787,39 +838,20 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ServiceInfo> getServiceList() throws IOException {
|
|
|
- ServiceListRequest request = ServiceListRequest.newBuilder().build();
|
|
|
- final ServiceListResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.getServiceList(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
-
|
|
|
- if (resp.getStatus() == Status.OK) {
|
|
|
- return resp.getServiceInfoList().stream()
|
|
|
- .map(ServiceInfo::getFromProtobuf)
|
|
|
- .collect(Collectors.toList());
|
|
|
- } else {
|
|
|
- throw new IOException("Getting service list failed, error: "
|
|
|
- + resp.getStatus());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void createS3Bucket(String userName, String s3BucketName)
|
|
|
throws IOException {
|
|
|
- S3BucketRequest request = S3BucketRequest.newBuilder()
|
|
|
+ S3CreateBucketRequest req = S3CreateBucketRequest.newBuilder()
|
|
|
.setUserName(userName)
|
|
|
.setS3Bucketname(s3BucketName)
|
|
|
.build();
|
|
|
- final S3BucketResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.createS3Bucket(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.CreateS3Bucket)
|
|
|
+ .setCreateS3BucketRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ S3CreateBucketResponse resp = submitRequest(omRequest)
|
|
|
+ .getCreateS3BucketResponse();
|
|
|
|
|
|
if(resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Creating S3 bucket failed, error: "
|
|
@@ -833,12 +865,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3DeleteBucketRequest request = S3DeleteBucketRequest.newBuilder()
|
|
|
.setS3BucketName(s3BucketName)
|
|
|
.build();
|
|
|
- final S3DeleteBucketResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.deleteS3Bucket(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.DeleteS3Bucket)
|
|
|
+ .setDeleteS3BucketRequest(request)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ S3DeleteBucketResponse resp = submitRequest(omRequest)
|
|
|
+ .getDeleteS3BucketResponse();
|
|
|
|
|
|
if(resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Creating S3 bucket failed, error: "
|
|
@@ -853,12 +886,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
S3BucketInfoRequest request = S3BucketInfoRequest.newBuilder()
|
|
|
.setS3BucketName(s3BucketName)
|
|
|
.build();
|
|
|
- final S3BucketInfoResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.getS3Bucketinfo(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.InfoS3Bucket)
|
|
|
+ .setInfoS3BucketRequest(request)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ S3BucketInfoResponse resp = submitRequest(omRequest)
|
|
|
+ .getInfoS3BucketResponse();
|
|
|
+
|
|
|
if(resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("GetOzoneBucketMapping failed, error:" + resp
|
|
|
.getStatus());
|
|
@@ -881,12 +916,13 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
reqBuilder.setPrefix(prefix);
|
|
|
}
|
|
|
S3ListBucketsRequest request = reqBuilder.build();
|
|
|
- final S3ListBucketsResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.listS3Buckets(NULL_RPC_CONTROLLER, request);
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.ListS3Buckets)
|
|
|
+ .setListS3BucketsRequest(request)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ S3ListBucketsResponse resp = submitRequest(omRequest)
|
|
|
+ .getListS3BucketsResponse();
|
|
|
|
|
|
if (resp.getStatus() == Status.OK) {
|
|
|
buckets.addAll(
|
|
@@ -900,16 +936,6 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return the proxy object underlying this protocol translator.
|
|
|
- *
|
|
|
- * @return the proxy object underlying this protocol translator.
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Object getUnderlyingProxyObject() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public OmMultipartInfo initiateMultipartUpload(OmKeyArgs omKeyArgs) throws
|
|
|
IOException {
|
|
@@ -925,13 +951,14 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setType(omKeyArgs.getType());
|
|
|
multipartInfoInitiateRequest.setKeyArgs(keyArgs.build());
|
|
|
|
|
|
- MultipartInfoInitiateResponse resp;
|
|
|
- try {
|
|
|
- resp = rpcProxy.initiateMultiPartUpload(NULL_RPC_CONTROLLER,
|
|
|
- multipartInfoInitiateRequest.build());
|
|
|
- } catch (ServiceException e) {
|
|
|
- throw ProtobufHelper.getRemoteException(e);
|
|
|
- }
|
|
|
+ OMRequest omRequest = createOMRequest(
|
|
|
+ Type.InitiateMultiPartUpload)
|
|
|
+ .setInitiateMultiPartUploadRequest(multipartInfoInitiateRequest.build())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ MultipartInfoInitiateResponse resp = submitRequest(omRequest)
|
|
|
+ .getInitiateMultiPartUploadResponse();
|
|
|
+
|
|
|
if (resp.getStatus() != Status.OK) {
|
|
|
throw new IOException("Initiate Multipart upload failed, error:" + resp
|
|
|
.getStatus());
|
|
@@ -942,7 +969,7 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
|
|
|
@Override
|
|
|
public OmMultipartCommitUploadPartInfo commitMultipartUploadPart(
|
|
|
- OmKeyArgs omKeyArgs, long clientID) throws IOException {
|
|
|
+ OmKeyArgs omKeyArgs, long clientId) throws IOException {
|
|
|
MultipartCommitUploadPartRequest.Builder multipartCommitUploadPartRequest
|
|
|
= MultipartCommitUploadPartRequest.newBuilder();
|
|
|
|
|
@@ -953,18 +980,17 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
.setMultipartUploadID(omKeyArgs.getMultipartUploadID())
|
|
|
.setIsMultipartKey(omKeyArgs.getIsMultipartKey())
|
|
|
.setMultipartNumber(omKeyArgs.getMultipartUploadPartNumber());
|
|
|
- multipartCommitUploadPartRequest.setClientID(clientID);
|
|
|
+ multipartCommitUploadPartRequest.setClientID(clientId);
|
|
|
multipartCommitUploadPartRequest.setKeyArgs(keyArgs.build());
|
|
|
|
|
|
- MultipartCommitUploadPartResponse response;
|
|
|
-
|
|
|
- try {
|
|
|
- response = rpcProxy.commitMultipartUploadPart(NULL_RPC_CONTROLLER,
|
|
|
- multipartCommitUploadPartRequest.build());
|
|
|
+ OMRequest omRequest = createOMRequest(
|
|
|
+ Type.CommitMultiPartUpload)
|
|
|
+ .setCommitMultiPartUploadRequest(multipartCommitUploadPartRequest
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
|
|
|
- } catch (ServiceException ex) {
|
|
|
- throw ProtobufHelper.getRemoteException(ex);
|
|
|
- }
|
|
|
+ MultipartCommitUploadPartResponse response = submitRequest(omRequest)
|
|
|
+ .getCommitMultiPartUploadResponse();
|
|
|
|
|
|
if (response.getStatus() != Status.OK) {
|
|
|
throw new IOException("Commit multipart upload part key failed, error:"
|
|
@@ -975,4 +1001,24 @@ public final class OzoneManagerProtocolClientSideTranslatorPB
|
|
|
OmMultipartCommitUploadPartInfo(response.getPartName());
|
|
|
return info;
|
|
|
}
|
|
|
+
|
|
|
+ public List<ServiceInfo> getServiceList() throws IOException {
|
|
|
+ ServiceListRequest req = ServiceListRequest.newBuilder().build();
|
|
|
+
|
|
|
+ OMRequest omRequest = createOMRequest(Type.ServiceList)
|
|
|
+ .setServiceListRequest(req)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ final ServiceListResponse resp = submitRequest(omRequest)
|
|
|
+ .getServiceListResponse();
|
|
|
+
|
|
|
+ if (resp.getStatus() == Status.OK) {
|
|
|
+ return resp.getServiceInfoList().stream()
|
|
|
+ .map(ServiceInfo::getFromProtobuf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ throw new IOException("Getting service list failed, error: "
|
|
|
+ + resp.getStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|