http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java deleted file mode 100644 index c0829fa..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java +++ /dev/null @@ -1,775 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.ipc.ProtobufHelper; -import org.apache.hadoop.ipc.ProtocolTranslator; -import org.apache.hadoop.ozone.om.helpers.OmBucketArgs; -import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; -import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; -import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; -import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; -import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; -import org.apache.hadoop.ozone.om.helpers.OpenKeySession; -import org.apache.hadoop.ozone.om.helpers.ServiceInfo; -import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol; -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.CommitKeyRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CommitKeyResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.BucketArgs; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.BucketInfo; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CreateBucketRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CreateBucketResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.InfoBucketRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.InfoBucketResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.SetBucketPropertyRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.SetBucketPropertyResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.DeleteBucketRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.DeleteBucketResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CreateVolumeRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CreateVolumeResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.LocateKeyRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.LocateKeyResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.RenameKeyRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.RenameKeyResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.KeyArgs; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.SetVolumePropertyRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.SetVolumePropertyResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.DeleteVolumeRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.DeleteVolumeResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.InfoVolumeRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.InfoVolumeResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CheckVolumeAccessRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.CheckVolumeAccessResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListBucketsRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListBucketsResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListKeysRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListKeysResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.VolumeInfo; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.Status; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.OzoneAclInfo; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListVolumeRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ListVolumeResponse; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ServiceListRequest; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.ServiceListResponse; - -import java.io.Closeable; -import java.io.IOException; -import java.util.List; -import java.util.ArrayList; -import java.util.stream.Collectors; - -/** - * The client side implementation of OzoneManagerProtocol. - */ - [email protected] -public final class OzoneManagerProtocolClientSideTranslatorPB - implements OzoneManagerProtocol, ProtocolTranslator, Closeable { - - /** - * RpcController is not used and hence is set to null. - */ - private static final RpcController NULL_RPC_CONTROLLER = null; - - private final OzoneManagerProtocolPB rpcProxy; - - /** - * Constructor for KeySpaceManger Client. - * @param rpcProxy - */ - public OzoneManagerProtocolClientSideTranslatorPB( - OzoneManagerProtocolPB rpcProxy) { - this.rpcProxy = rpcProxy; - } - - /** - * Closes this stream and releases any system resources associated - * with it. If the stream is already closed then invoking this - * method has no effect. - * <p> - * <p> As noted in {@link AutoCloseable#close()}, cases where the - * close may fail require careful attention. It is strongly advised - * to relinquish the underlying resources and to internally - * <em>mark</em> the {@code Closeable} as closed, prior to throwing - * the {@code IOException}. - * - * @throws IOException if an I/O error occurs - */ - @Override - public void close() throws IOException { - - } - - /** - * Creates a volume. - * - * @param args - Arguments to create Volume. - * @throws IOException - */ - @Override - public void createVolume(OmVolumeArgs args) throws IOException { - CreateVolumeRequest.Builder req = - CreateVolumeRequest.newBuilder(); - 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); - } - - if (resp.getStatus() != Status.OK) { - throw new - IOException("Volume creation failed, error:" + resp.getStatus()); - } - } - - /** - * Changes the owner of a volume. - * - * @param volume - Name of the volume. - * @param owner - Name of the owner. - * @throws IOException - */ - @Override - public void setOwner(String volume, String owner) throws IOException { - 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); - } - if (resp.getStatus() != Status.OK) { - throw new - IOException("Volume owner change failed, error:" + resp.getStatus()); - } - } - - /** - * Changes the Quota on a volume. - * - * @param volume - Name of the volume. - * @param quota - Quota in bytes. - * @throws IOException - */ - @Override - public void setQuota(String volume, long quota) throws IOException { - 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); - } - if (resp.getStatus() != Status.OK) { - throw new - IOException("Volume quota change failed, error:" + resp.getStatus()); - } - } - - /** - * Checks if the specified user can access this volume. - * - * @param volume - volume - * @param userAcl - user acls which needs to be checked for access - * @return true if the user has required access for the volume, - * false otherwise - * @throws IOException - */ - @Override - public boolean checkVolumeAccess(String volume, OzoneAclInfo userAcl) throws - IOException { - 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); - } - - if (resp.getStatus() == Status.ACCESS_DENIED) { - return false; - } else if (resp.getStatus() == Status.OK) { - return true; - } else { - throw new - IOException("Check Volume Access failed, error:" + resp.getStatus()); - } - } - - /** - * Gets the volume information. - * - * @param volume - Volume name. - * @return OmVolumeArgs or exception is thrown. - * @throws IOException - */ - @Override - 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); - } - if (resp.getStatus() != Status.OK) { - throw new - IOException("Info Volume failed, error:" + resp.getStatus()); - } - return OmVolumeArgs.getFromProtobuf(resp.getVolumeInfo()); - } - - /** - * Deletes an existing empty volume. - * - * @param volume - Name of the volume. - * @throws IOException - */ - @Override - 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); - } - if (resp.getStatus() != Status.OK) { - throw new - IOException("Delete Volume failed, error:" + resp.getStatus()); - } - } - - /** - * Lists volume owned by a specific user. - * - * @param userName - user name - * @param prefix - Filter prefix -- Return only entries that match this. - * @param prevKey - Previous key -- List starts from the next from the - * prevkey - * @param maxKeys - Max number of keys to return. - * @return List of Volumes. - * @throws IOException - */ - @Override - public List<OmVolumeArgs> listVolumeByUser(String userName, String prefix, - String prevKey, int maxKeys) - throws IOException { - ListVolumeRequest.Builder builder = ListVolumeRequest.newBuilder(); - if (!Strings.isNullOrEmpty(prefix)) { - builder.setPrefix(prefix); - } - if (!Strings.isNullOrEmpty(prevKey)) { - builder.setPrevKey(prevKey); - } - builder.setMaxKeys(maxKeys); - builder.setUserName(userName); - builder.setScope(ListVolumeRequest.Scope.VOLUMES_BY_USER); - return listVolume(builder.build()); - } - - /** - * Lists volume all volumes in the cluster. - * - * @param prefix - Filter prefix -- Return only entries that match this. - * @param prevKey - Previous key -- List starts from the next from the - * prevkey - * @param maxKeys - Max number of keys to return. - * @return List of Volumes. - * @throws IOException - */ - @Override - public List<OmVolumeArgs> listAllVolumes(String prefix, String prevKey, - int maxKeys) throws IOException { - ListVolumeRequest.Builder builder = ListVolumeRequest.newBuilder(); - if (!Strings.isNullOrEmpty(prefix)) { - builder.setPrefix(prefix); - } - if (!Strings.isNullOrEmpty(prevKey)) { - builder.setPrevKey(prevKey); - } - builder.setMaxKeys(maxKeys); - builder.setScope(ListVolumeRequest.Scope.VOLUMES_BY_CLUSTER); - return listVolume(builder.build()); - } - - 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); - } - - 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()); - } - - /** - * Creates a bucket. - * - * @param bucketInfo - BucketInfo to create bucket. - * @throws IOException - */ - @Override - public void createBucket(OmBucketInfo bucketInfo) throws IOException { - CreateBucketRequest.Builder req = - CreateBucketRequest.newBuilder(); - 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); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Bucket creation failed, error: " - + resp.getStatus()); - } - } - - /** - * Gets the bucket information. - * - * @param volume - Volume name. - * @param bucket - Bucket name. - * @return OmBucketInfo or exception is thrown. - * @throws IOException - */ - @Override - public OmBucketInfo getBucketInfo(String volume, String bucket) - throws IOException { - InfoBucketRequest.Builder req = - InfoBucketRequest.newBuilder(); - 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); - } - if (resp.getStatus() == Status.OK) { - return OmBucketInfo.getFromProtobuf(resp.getBucketInfo()); - } else { - throw new IOException("Info Bucket failed, error: " - + resp.getStatus()); - } - } - - /** - * Sets bucket property from args. - * @param args - BucketArgs. - * @throws IOException - */ - @Override - public void setBucketProperty(OmBucketArgs args) - throws IOException { - SetBucketPropertyRequest.Builder req = - 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); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Setting bucket property failed, error: " - + resp.getStatus()); - } - } - - /** - * List buckets in a volume. - * - * @param volumeName - * @param startKey - * @param prefix - * @param count - * @return - * @throws IOException - */ - @Override - public List<OmBucketInfo> listBuckets(String volumeName, - String startKey, String prefix, int count) throws IOException { - List<OmBucketInfo> buckets = new ArrayList<>(); - ListBucketsRequest.Builder reqBuilder = ListBucketsRequest.newBuilder(); - reqBuilder.setVolumeName(volumeName); - reqBuilder.setCount(count); - if (startKey != null) { - reqBuilder.setStartKey(startKey); - } - if (prefix != null) { - 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); - } - - if (resp.getStatus() == Status.OK) { - buckets.addAll( - resp.getBucketInfoList().stream() - .map(OmBucketInfo::getFromProtobuf) - .collect(Collectors.toList())); - return buckets; - } else { - throw new IOException("List Buckets failed, error: " - + resp.getStatus()); - } - } - - /** - * Create a new open session of the key, then use the returned meta info to - * talk to data node to actually write the key. - * @param args the args for the key to be allocated - * @return a handler to the key, returned client - * @throws IOException - */ - @Override - public OpenKeySession openKey(OmKeyArgs args) throws IOException { - LocateKeyRequest.Builder req = LocateKeyRequest.newBuilder(); - KeyArgs.Builder keyArgs = KeyArgs.newBuilder() - .setVolumeName(args.getVolumeName()) - .setBucketName(args.getBucketName()) - .setFactor(args.getFactor()) - .setType(args.getType()) - .setKeyName(args.getKeyName()); - if (args.getDataSize() > 0) { - keyArgs.setDataSize(args.getDataSize()); - } - req.setKeyArgs(keyArgs.build()); - - final LocateKeyResponse resp; - try { - resp = rpcProxy.createKey(NULL_RPC_CONTROLLER, req.build()); - } catch (ServiceException e) { - throw ProtobufHelper.getRemoteException(e); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Create key failed, error:" + resp.getStatus()); - } - return new OpenKeySession(resp.getID(), - OmKeyInfo.getFromProtobuf(resp.getKeyInfo()), resp.getOpenVersion()); - } - - @Override - public OmKeyLocationInfo allocateBlock(OmKeyArgs args, long clientID) - throws IOException { - AllocateBlockRequest.Builder req = AllocateBlockRequest.newBuilder(); - KeyArgs keyArgs = KeyArgs.newBuilder() - .setVolumeName(args.getVolumeName()) - .setBucketName(args.getBucketName()) - .setKeyName(args.getKeyName()) - .setDataSize(args.getDataSize()).build(); - req.setKeyArgs(keyArgs); - req.setClientID(clientID); - - 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()); - } - return OmKeyLocationInfo.getFromProtobuf(resp.getKeyLocation()); - } - - @Override - public void commitKey(OmKeyArgs args, long clientID) - throws IOException { - CommitKeyRequest.Builder req = CommitKeyRequest.newBuilder(); - List<OmKeyLocationInfo> locationInfoList = args.getLocationInfoList(); - Preconditions.checkNotNull(locationInfoList); - KeyArgs keyArgs = KeyArgs.newBuilder() - .setVolumeName(args.getVolumeName()) - .setBucketName(args.getBucketName()) - .setKeyName(args.getKeyName()) - .setDataSize(args.getDataSize()) - .addAllKeyLocations( - locationInfoList.stream().map(OmKeyLocationInfo::getProtobuf) - .collect(Collectors.toList())).build(); - req.setKeyArgs(keyArgs); - req.setClientID(clientID); - - 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()); - } - } - - - @Override - public OmKeyInfo lookupKey(OmKeyArgs args) throws IOException { - LocateKeyRequest.Builder req = LocateKeyRequest.newBuilder(); - KeyArgs keyArgs = KeyArgs.newBuilder() - .setVolumeName(args.getVolumeName()) - .setBucketName(args.getBucketName()) - .setKeyName(args.getKeyName()) - .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); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Lookup key failed, error:" + - resp.getStatus()); - } - return OmKeyInfo.getFromProtobuf(resp.getKeyInfo()); - } - - @Override - public void renameKey(OmKeyArgs args, String toKeyName) throws IOException { - RenameKeyRequest.Builder req = RenameKeyRequest.newBuilder(); - KeyArgs keyArgs = KeyArgs.newBuilder() - .setVolumeName(args.getVolumeName()) - .setBucketName(args.getBucketName()) - .setKeyName(args.getKeyName()) - .setDataSize(args.getDataSize()).build(); - 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); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Rename key failed, error:" + - resp.getStatus()); - } - } - - /** - * Deletes an existing key. - * - * @param args the args of the key. - * @throws IOException - */ - @Override - public void deleteKey(OmKeyArgs args) throws IOException { - LocateKeyRequest.Builder req = LocateKeyRequest.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); - } - if (resp.getStatus() != Status.OK) { - throw new IOException("Delete key failed, error:" + - resp.getStatus()); - } - } - - /** - * Deletes an existing empty bucket from volume. - * @param volume - Name of the volume. - * @param bucket - Name of the bucket. - * @throws IOException - */ - public void deleteBucket(String volume, String bucket) throws IOException { - 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); - } - if (resp.getStatus() != Status.OK) { - throw new - IOException("Delete Bucket failed, error:" + resp.getStatus()); - } - } - - /** - * List keys in a bucket. - */ - @Override - public List<OmKeyInfo> listKeys(String volumeName, String bucketName, - String startKey, String prefix, int maxKeys) throws IOException { - List<OmKeyInfo> keys = new ArrayList<>(); - ListKeysRequest.Builder reqBuilder = ListKeysRequest.newBuilder(); - reqBuilder.setVolumeName(volumeName); - reqBuilder.setBucketName(bucketName); - reqBuilder.setCount(maxKeys); - - if (startKey != null) { - reqBuilder.setStartKey(startKey); - } - - if (prefix != null) { - 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); - } - - if (resp.getStatus() == Status.OK) { - keys.addAll( - resp.getKeyInfoList().stream() - .map(OmKeyInfo::getFromProtobuf) - .collect(Collectors.toList())); - return keys; - } else { - throw new IOException("List Keys failed, error: " - + resp.getStatus()); - } - } - - @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()); - } - } - - /** - * Return the proxy object underlying this protocol translator. - * - * @return the proxy object underlying this protocol translator. - */ - @Override - public Object getUnderlyingProxyObject() { - return null; - } -}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolPB.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolPB.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolPB.java deleted file mode 100644 index e0879d6..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolPB.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.om.protocolPB; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.ipc.ProtocolInfo; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.OzoneManagerService; - -/** - * Protocol used to communicate with OM. - */ -@ProtocolInfo(protocolName = - "org.apache.hadoop.ozone.protocol.OzoneManagerProtocol", - protocolVersion = 1) [email protected] -public interface OzoneManagerProtocolPB - extends OzoneManagerService.BlockingInterface { -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/package-info.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/package-info.java deleted file mode 100644 index d595edf..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.om.protocolPB; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/package-info.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/package-info.java deleted file mode 100644 index 69d94b6..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone; - -/** - * Classes related to ozone REST interface. - */ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java deleted file mode 100644 index d57d32e..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OMPBHelper.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.protocolPB; - -import org.apache.hadoop.ozone.OzoneAcl; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.OzoneAclInfo; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.OzoneAclInfo.OzoneAclType; -import org.apache.hadoop.ozone.protocol.proto - .OzoneManagerProtocolProtos.OzoneAclInfo.OzoneAclRights; - -/** - * Utilities for converting protobuf classes. - */ -public final class OMPBHelper { - - private OMPBHelper() { - /** Hidden constructor */ - } - - /** - * Converts OzoneAcl into protobuf's OzoneAclInfo. - * @return OzoneAclInfo - */ - public static OzoneAclInfo convertOzoneAcl(OzoneAcl acl) { - OzoneAclInfo.OzoneAclType aclType; - switch(acl.getType()) { - case USER: - aclType = OzoneAclType.USER; - break; - case GROUP: - aclType = OzoneAclType.GROUP; - break; - case WORLD: - aclType = OzoneAclType.WORLD; - break; - default: - throw new IllegalArgumentException("ACL type is not recognized"); - } - OzoneAclInfo.OzoneAclRights aclRights; - switch(acl.getRights()) { - case READ: - aclRights = OzoneAclRights.READ; - break; - case WRITE: - aclRights = OzoneAclRights.WRITE; - break; - case READ_WRITE: - aclRights = OzoneAclRights.READ_WRITE; - break; - default: - throw new IllegalArgumentException("ACL right is not recognized"); - } - - return OzoneAclInfo.newBuilder().setType(aclType) - .setName(acl.getName()) - .setRights(aclRights) - .build(); - } - - /** - * Converts protobuf's OzoneAclInfo into OzoneAcl. - * @return OzoneAcl - */ - public static OzoneAcl convertOzoneAcl(OzoneAclInfo aclInfo) { - OzoneAcl.OzoneACLType aclType; - switch(aclInfo.getType()) { - case USER: - aclType = OzoneAcl.OzoneACLType.USER; - break; - case GROUP: - aclType = OzoneAcl.OzoneACLType.GROUP; - break; - case WORLD: - aclType = OzoneAcl.OzoneACLType.WORLD; - break; - default: - throw new IllegalArgumentException("ACL type is not recognized"); - } - OzoneAcl.OzoneACLRights aclRights; - switch(aclInfo.getRights()) { - case READ: - aclRights = OzoneAcl.OzoneACLRights.READ; - break; - case WRITE: - aclRights = OzoneAcl.OzoneACLRights.WRITE; - break; - case READ_WRITE: - aclRights = OzoneAcl.OzoneACLRights.READ_WRITE; - break; - default: - throw new IllegalArgumentException("ACL right is not recognized"); - } - - return new OzoneAcl(aclType, aclInfo.getName(), aclRights); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OzonePBHelper.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OzonePBHelper.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OzonePBHelper.java deleted file mode 100644 index 8361bac..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/OzonePBHelper.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.protocolPB; - -/** - * Helper class for converting protobuf objects. - */ -public final class OzonePBHelper { - - private OzonePBHelper() { - /** Hidden constructor */ - } - - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/package-info.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/package-info.java deleted file mode 100644 index 860386d..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/protocolPB/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.protocolPB; - -/** - * This package contains classes for the Protocol Buffers binding of Ozone - * protocols. - */ http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/util/OzoneVersionInfo.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/util/OzoneVersionInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/util/OzoneVersionInfo.java deleted file mode 100644 index d476748..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/util/OzoneVersionInfo.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.util; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.classification.InterfaceStability; -import org.apache.hadoop.io.IOUtils; -import org.apache.hadoop.util.ClassUtil; -import org.apache.hadoop.util.ThreadUtil; -import org.apache.hadoop.utils.HddsVersionInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * This class returns build information about Hadoop components. - */ [email protected] [email protected] -public class OzoneVersionInfo { - private static final Logger LOG = LoggerFactory.getLogger(OzoneVersionInfo.class); - - private Properties info; - - protected OzoneVersionInfo(String component) { - info = new Properties(); - String versionInfoFile = component + "-version-info.properties"; - InputStream is = null; - try { - is = ThreadUtil.getResourceAsStream(OzoneVersionInfo.class.getClassLoader(), - versionInfoFile); - info.load(is); - } catch (IOException ex) { - LoggerFactory.getLogger(getClass()).warn("Could not read '" + - versionInfoFile + "', " + ex.toString(), ex); - } finally { - IOUtils.closeStream(is); - } - } - - protected String _getVersion() { - return info.getProperty("version", "Unknown"); - } - - protected String _getRelease() { - return info.getProperty("release", "Unknown"); - } - - protected String _getRevision() { - return info.getProperty("revision", "Unknown"); - } - - protected String _getBranch() { - return info.getProperty("branch", "Unknown"); - } - - protected String _getDate() { - return info.getProperty("date", "Unknown"); - } - - protected String _getUser() { - return info.getProperty("user", "Unknown"); - } - - protected String _getUrl() { - return info.getProperty("url", "Unknown"); - } - - protected String _getSrcChecksum() { - return info.getProperty("srcChecksum", "Unknown"); - } - - protected String _getBuildVersion(){ - return _getVersion() + - " from " + _getRevision() + - " by " + _getUser() + - " source checksum " + _getSrcChecksum(); - } - - protected String _getProtocVersion() { - return info.getProperty("protocVersion", "Unknown"); - } - - private static OzoneVersionInfo OZONE_VERSION_INFO = new OzoneVersionInfo("ozone"); - /** - * Get the Ozone version. - * @return the Ozone version string, eg. "0.6.3-dev" - */ - public static String getVersion() { - return OZONE_VERSION_INFO._getVersion(); - } - - /** - * Get the Ozone release name. - * @return the Ozone release string, eg. "Acadia" - */ - public static String getRelease() { - return OZONE_VERSION_INFO._getRelease(); - } - - /** - * Get the Git commit hash of the repository when compiled. - * @return the commit hash, eg. "18f64065d5db6208daf50b02c1b5ed4ee3ce547a" - */ - public static String getRevision() { - return OZONE_VERSION_INFO._getRevision(); - } - - /** - * Get the branch on which this originated. - * @return The branch name, e.g. "trunk" or "branches/branch-0.20" - */ - public static String getBranch() { - return OZONE_VERSION_INFO._getBranch(); - } - - /** - * The date that Ozone was compiled. - * @return the compilation date in unix date format - */ - public static String getDate() { - return OZONE_VERSION_INFO._getDate(); - } - - /** - * The user that compiled Ozone. - * @return the username of the user - */ - public static String getUser() { - return OZONE_VERSION_INFO._getUser(); - } - - /** - * Get the URL for the Ozone repository. - * @return the URL of the Ozone repository - */ - public static String getUrl() { - return OZONE_VERSION_INFO._getUrl(); - } - - /** - * Get the checksum of the source files from which Ozone was built. - * @return the checksum of the source files - */ - public static String getSrcChecksum() { - return OZONE_VERSION_INFO._getSrcChecksum(); - } - - /** - * Returns the buildVersion which includes version, - * revision, user and date. - * @return the buildVersion - */ - public static String getBuildVersion(){ - return OZONE_VERSION_INFO._getBuildVersion(); - } - - /** - * Returns the protoc version used for the build. - * @return the protoc version - */ - public static String getProtocVersion(){ - return OZONE_VERSION_INFO._getProtocVersion(); - } - - public static void main(String[] args) { - System.out.println( - " ////////////// \n" + - " //////////////////// \n" + - " //////// //////////////// \n" + - " ////// //////////////// \n" + - " ///// //////////////// / \n" + - " ///// //////// /// \n" + - " //// //////// ///// \n" + - " ///// //////////////// \n" + - " ///// //////////////// // \n" + - " //// /////////////// ///// \n" + - " ///// /////////////// //// \n" + - " ///// ////// ///// \n" + - " ////// ////// ///// \n" + - " /////////// //////// \n" + - " ////// //////////// \n" + - " /// ////////// \n" + - " / "+ getVersion() + "("+ getRelease() +")\n"); - System.out.println("Source code repository " + getUrl() + " -r " + - getRevision()); - System.out.println("Compiled by " + getUser() + " on " + getDate()); - System.out.println("Compiled with protoc " + getProtocVersion()); - System.out.println("From source with checksum " + getSrcChecksum() + "\n"); - LOG.debug("This command was run using " + - ClassUtil.findContainingJar(OzoneVersionInfo.class)); - HddsVersionInfo.main(args); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/BucketArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/BucketArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/BucketArgs.java deleted file mode 100644 index 0d5248d..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/BucketArgs.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.web.handlers; - -import org.apache.hadoop.fs.StorageType; -import org.apache.hadoop.ozone.OzoneAcl; -import org.apache.hadoop.ozone.OzoneConsts; - -import java.util.LinkedList; -import java.util.List; - -/** - * BucketArgs packages all bucket related arguments to - * file system calls. - */ -public class BucketArgs extends VolumeArgs { - private final String bucketName; - private List<OzoneAcl> addAcls; - private List<OzoneAcl> removeAcls; - private OzoneConsts.Versioning versioning; - private StorageType storageType; - - /** - * Constructor for BucketArgs. - * - * @param volumeName - volumeName - * @param bucketName - bucket Name - * @param userArgs - userArgs - */ - public BucketArgs(String volumeName, String bucketName, UserArgs userArgs) { - super(volumeName, userArgs); - this.bucketName = bucketName; - this.versioning = OzoneConsts.Versioning.NOT_DEFINED; - this.storageType = null; - } - - - /** - * Constructor for BucketArgs. - * - * @param bucketName - bucket Name - * @param volumeArgs - volume Args - */ - public BucketArgs(String bucketName, VolumeArgs volumeArgs) { - super(volumeArgs); - this.bucketName = bucketName; - this.versioning = OzoneConsts.Versioning.NOT_DEFINED; - this.storageType = null; - } - - /** - * Constructor for BucketArgs. - * - * @param args - Bucket Args - */ - public BucketArgs(BucketArgs args) { - this(args.getBucketName(), args); - this.setAddAcls(args.getAddAcls()); - this.setRemoveAcls(args.getRemoveAcls()); - } - - /** - * Returns the Bucket Name. - * - * @return Bucket Name - */ - public String getBucketName() { - return bucketName; - } - - /** - * Returns Additive ACLs for the Bucket if specified. - * - * @return acls - */ - public List<OzoneAcl> getAddAcls() { - return addAcls; - } - - /** - * Set Additive ACLs. - * - * @param acl - ACL - */ - public void setAddAcls(List<OzoneAcl> acl) { - this.addAcls = acl; - } - - /** - * Returns remove ACLs for the Bucket if specified. - * - * @return acls - */ - public List<OzoneAcl> getRemoveAcls() { - return removeAcls; - } - - /** - * Takes an ACL and sets the ACL object to ACL represented by the String. - * - * @param aclString - aclString - */ - public void addAcls(List<String> aclString) throws IllegalArgumentException { - if (aclString == null) { - throw new IllegalArgumentException("ACLs cannot be null"); - } - if (this.addAcls == null) { - this.addAcls = new LinkedList<>(); - } - for (String s : aclString) { - this.addAcls.add(OzoneAcl.parseAcl(s)); - } - } - - /** - * Takes an ACL and sets the ACL object to ACL represented by the String. - * - * @param aclString - aclString - */ - public void removeAcls(List<String> aclString) - throws IllegalArgumentException { - if (aclString == null) { - throw new IllegalArgumentException("ACLs cannot be null"); - } - if (this.removeAcls == null) { - this.removeAcls = new LinkedList<>(); - } - for (String s : aclString) { - this.removeAcls.add(OzoneAcl.parseAcl(s)); - } - } - - /** - * Set remove ACLs. - * - * @param acl - ACL - */ - public void setRemoveAcls(List<OzoneAcl> acl) { - this.removeAcls = acl; - } - - - /** - * Returns Versioning Info. - * - * @return versioning - */ - public OzoneConsts.Versioning getVersioning() { - return versioning; - } - - - /** - * SetVersioning Info. - * - * @param versioning - Enum value - */ - public void setVersioning(OzoneConsts.Versioning versioning) { - this.versioning = versioning; - } - - /** - * returns the current Storage Class. - * - * @return Storage Class - */ - public StorageType getStorageType() { - return storageType; - } - - /** - * Sets the Storage Class. - * - * @param storageType Set Storage Class - */ - public void setStorageType(StorageType storageType) { - this.storageType = storageType; - } - - /** - * returns - Volume/bucketName. - * - * @return String - */ - @Override - public String getResourceName() { - return getVolumeName() + "/" + getBucketName(); - } - - /** - * Returns User/Volume name which is the parent of this - * bucket. - * - * @return String - */ - public String getParentName() { - return getUserName() + "/" + getVolumeName(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/KeyArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/KeyArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/KeyArgs.java deleted file mode 100644 index 48a4cb4..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/KeyArgs.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.web.handlers; - -/** - * Class that packages all key Arguments. - */ -public class KeyArgs extends BucketArgs { - private String key; - private String hash; - private long size; - - /** - * Constructor for Key Args. - * - * @param volumeName - Volume Name - * @param bucketName - Bucket Name - * @param objectName - Key - */ - public KeyArgs(String volumeName, String bucketName, - String objectName, UserArgs args) { - super(volumeName, bucketName, args); - this.key = objectName; - } - - /** - * Constructor for Key Args. - * - * @param objectName - Key - * @param args - Bucket Args - */ - public KeyArgs(String objectName, BucketArgs args) { - super(args); - this.key = objectName; - } - - /** - * Get Key Name. - * - * @return String - */ - public String getKeyName() { - return this.key; - } - - /** - * Computed File hash. - * - * @return String - */ - public String getHash() { - return hash; - } - - /** - * Sets the hash String. - * - * @param hash String - */ - public void setHash(String hash) { - this.hash = hash; - } - - /** - * Returns the file size. - * - * @return long - file size - */ - public long getSize() { - return size; - } - - /** - * Set Size. - * - * @param size Size of the file - */ - public void setSize(long size) { - this.size = size; - } - - /** - * Returns the name of the resource. - * - * @return String - */ - @Override - public String getResourceName() { - return super.getResourceName() + "/" + getKeyName(); - } - - /** - * Parent name of this resource. - * - * @return String. - */ - @Override - public String getParentName() { - return super.getResourceName(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/ListArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/ListArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/ListArgs.java deleted file mode 100644 index 49ca4a4..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/ListArgs.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.web.handlers; - -/** - * Supports listing keys with pagination. - */ -public class ListArgs<T extends UserArgs> { - private String prevKey; - private String prefix; - private int maxKeys; - private boolean rootScan; - private T args; - - /** - * Constructor for ListArgs. - * - * @param args - BucketArgs - * @param prefix Prefix to start Query from - * @param maxKeys Max result set - * @param prevKey - Page token - */ - public ListArgs(T args, String prefix, int maxKeys, - String prevKey) { - setArgs(args); - setPrefix(prefix); - setMaxKeys(maxKeys); - setPrevKey(prevKey); - } - - /** - * Copy Constructor for ListArgs. - * - * @param args - List Args - */ - public ListArgs(T args, ListArgs listArgs) { - this(args, listArgs.getPrefix(), listArgs.getMaxKeys(), - listArgs.getPrevKey()); - } - - /** - * Returns page token. - * - * @return String - */ - public String getPrevKey() { - return prevKey; - } - - /** - * Sets page token. - * - * @param prevKey - Page token - */ - public void setPrevKey(String prevKey) { - this.prevKey = prevKey; - } - - /** - * Gets max keys. - * - * @return int - */ - public int getMaxKeys() { - return maxKeys; - } - - /** - * Sets max keys. - * - * @param maxKeys - Maximum keys to return - */ - public void setMaxKeys(int maxKeys) { - this.maxKeys = maxKeys; - } - - /** - * Gets prefix. - * - * @return String - */ - public String getPrefix() { - return prefix; - } - - /** - * Sets prefix. - * - * @param prefix - The prefix that we are looking for - */ - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - /** - * Gets args. - * @return T - */ - public T getArgs() { - return args; - } - - /** - * Sets args. - * @param args T - */ - public void setArgs(T args) { - this.args = args; - } - - /** - * Checks if we are doing a rootScan. - * @return - RootScan. - */ - public boolean isRootScan() { - return rootScan; - } - - /** - * Sets the RootScan property. - * @param rootScan - Boolean. - */ - public void setRootScan(boolean rootScan) { - this.rootScan = rootScan; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/UserArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/UserArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/UserArgs.java deleted file mode 100644 index 8a75928..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/UserArgs.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.web.handlers; - -import org.apache.hadoop.classification.InterfaceAudience; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.UriInfo; -import java.util.Arrays; - -/** - * UserArgs is used to package caller info - * and pass it down to file system. - */ [email protected] -public class UserArgs { - private String userName; - private final String requestID; - private final String hostName; - private final UriInfo uri; - private final Request request; - private final HttpHeaders headers; - private String[] groups; - - - /** - * Constructs user args. - * - * @param userName - User name - * @param requestID - Request ID - * @param hostName - Host Name - * @param req - Request - * @param info - Uri Info - * @param httpHeaders - http headers - */ - public UserArgs(String userName, String requestID, String hostName, - Request req, UriInfo info, HttpHeaders httpHeaders) { - this.hostName = hostName; - this.userName = userName; - this.requestID = requestID; - this.uri = info; - this.request = req; - this.headers = httpHeaders; - } - - /** - * Constructs user args when we don't know the user name yet. - * - * @param requestID _ Request ID - * @param hostName - Host Name - * @param req - Request - * @param info - UriInfo - * @param httpHeaders - http headers - */ - public UserArgs(String requestID, String hostName, Request req, UriInfo info, - HttpHeaders httpHeaders) { - this.hostName = hostName; - this.requestID = requestID; - this.uri = info; - this.request = req; - this.headers = httpHeaders; - } - - /** - * Returns hostname. - * - * @return String - */ - public String getHostName() { - return hostName; - } - - /** - * Returns RequestID. - * - * @return Long - */ - public String getRequestID() { - return requestID; - } - - /** - * Returns User Name. - * - * @return String - */ - public String getUserName() { - return userName; - } - - /** - * Sets the user name. - * - * @param userName Name of the user - */ - public void setUserName(String userName) { - this.userName = userName; - } - - /** - * Returns list of groups. - * - * @return String[] - */ - public String[] getGroups() { - return groups != null ? - Arrays.copyOf(groups, groups.length) : null; - } - - /** - * Sets the group list. - * - * @param groups list of groups - */ - public void setGroups(String[] groups) { - if (groups != null) { - this.groups = Arrays.copyOf(groups, groups.length); - } - } - - /** - * Returns the resource Name. - * - * @return String Resource. - */ - public String getResourceName() { - return getUserName(); - } - - /** - * Returns Http Headers for this call. - * - * @return httpHeaders - */ - public HttpHeaders getHeaders() { - return headers; - } - - /** - * Returns Request Object. - * - * @return Request - */ - public Request getRequest() { - return request; - } - - /** - * Returns UriInfo. - * - * @return UriInfo - */ - public UriInfo getUri() { - return uri; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/VolumeArgs.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/VolumeArgs.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/VolumeArgs.java deleted file mode 100644 index 1d67c67..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/VolumeArgs.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.web.handlers; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.ozone.web.request.OzoneQuota; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Request; -import javax.ws.rs.core.UriInfo; - -/** - * VolumeArgs is used to package all volume - * related arguments in the call to underlying - * file system. - */ [email protected] -public class VolumeArgs extends UserArgs { - private String adminName; - private final String volumeName; - private OzoneQuota quota; - - /** - * Returns Quota Information. - * - * @return Quota - */ - public OzoneQuota getQuota() { - return quota; - } - - /** - * Returns volume name. - * - * @return String - */ - public String getVolumeName() { - return volumeName; - } - - /** - * Constructs volume Args. - * - * @param userName - User name - * @param volumeName - volume Name - * @param requestID _ Request ID - * @param hostName - Host Name - * @param request - Http Request - * @param info - URI info - * @param headers - http headers - * @param groups - list of groups allowed to access the volume - */ - public VolumeArgs(String userName, String volumeName, String requestID, - String hostName, Request request, UriInfo info, - HttpHeaders headers, String[] groups) { - super(userName, requestID, hostName, request, info, headers); - super.setGroups(groups); - this.volumeName = volumeName; - } - - /** - * Constructs volume Args. - * - * @param volumeName - volume Name - * @param userArgs - userArgs - */ - public VolumeArgs(String volumeName, UserArgs userArgs) { - this(userArgs.getUserName(), volumeName, userArgs.getRequestID(), - userArgs.getHostName(), userArgs.getRequest(), userArgs.getUri(), - userArgs.getHeaders(), userArgs.getGroups()); - } - - /** - * Creates VolumeArgs from another VolumeArgs. - */ - public VolumeArgs(VolumeArgs volArgs) { - this(volArgs.getVolumeName(), volArgs); - } - - /** - * Sets Quota information. - * - * @param quota - Quota Sting - * @throws IllegalArgumentException - */ - public void setQuota(String quota) throws IllegalArgumentException { - this.quota = OzoneQuota.parseQuota(quota); - } - - /** - * Sets quota information. - * - * @param quota - OzoneQuota - */ - public void setQuota(OzoneQuota quota) { - this.quota = quota; - } - - /** - * Gets admin Name. - * - * @return - Admin Name - */ - public String getAdminName() { - return adminName; - } - - /** - * Sets Admin Name. - * - * @param adminName - Admin Name - */ - public void setAdminName(String adminName) { - this.adminName = adminName; - } - - /** - * Returns UserName/VolumeName. - * - * @return String - */ - @Override - public String getResourceName() { - return super.getResourceName() + "/" + getVolumeName(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/package-info.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/package-info.java deleted file mode 100644 index a66a773..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/handlers/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.web.handlers; - -/** - * REST handler value classes. - */ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/OzoneQuota.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/OzoneQuota.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/OzoneQuota.java deleted file mode 100644 index 9619ebd..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/OzoneQuota.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.ozone.web.request; - -import org.apache.hadoop.classification.InterfaceAudience; -import org.apache.hadoop.ozone.OzoneConsts; -import org.apache.hadoop.ozone.client.rest.headers.Header; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * represents an OzoneQuota Object that can be applied to - * a storage volume. - */ [email protected] -public class OzoneQuota { - - private Units unit; - private int size; - - /** Quota Units.*/ - public enum Units {UNDEFINED, BYTES, MB, GB, TB} - - /** - * Returns size. - * - * @return int - */ - public int getSize() { - return size; - } - - /** - * Returns Units. - * - * @return Unit in MB, GB or TB - */ - public Units getUnit() { - return unit; - } - - /** - * Constructs a default Quota object. - */ - public OzoneQuota() { - this.size = 0; - this.unit = Units.UNDEFINED; - } - - /** - * Constructor for Ozone Quota. - * - * @param size - Integer Size - * @param unit MB, GB or TB - */ - public OzoneQuota(int size, Units unit) { - this.size = size; - this.unit = unit; - } - - /** - * Formats a quota as a string. - * - * @param quota the quota to format - * @return string representation of quota - */ - public static String formatQuota(OzoneQuota quota) { - return String.valueOf(quota.size) + quota.unit; - } - - /** - * Parses a user provided string and returns the - * Quota Object. - * - * @param quotaString Quota String - * - * @return OzoneQuota object - * - * @throws IllegalArgumentException - */ - public static OzoneQuota parseQuota(String quotaString) - throws IllegalArgumentException { - - if ((quotaString == null) || (quotaString.isEmpty())) { - throw new IllegalArgumentException( - "Quota string cannot be null or empty."); - } - - if (isRemove(quotaString)) { - throw new IllegalArgumentException("Remove is invalid in this context."); - } - - String uppercase = quotaString.toUpperCase().replaceAll("\\s+", ""); - String size = ""; - int nSize; - Units currUnit = Units.MB; - Boolean found = false; - if (uppercase.endsWith(Header.OZONE_QUOTA_MB)) { - size = uppercase - .substring(0, uppercase.length() - Header.OZONE_QUOTA_MB.length()); - currUnit = Units.MB; - found = true; - } - - if (uppercase.endsWith(Header.OZONE_QUOTA_GB)) { - size = uppercase - .substring(0, uppercase.length() - Header.OZONE_QUOTA_GB.length()); - currUnit = Units.GB; - found = true; - } - - if (uppercase.endsWith(Header.OZONE_QUOTA_TB)) { - size = uppercase - .substring(0, uppercase.length() - Header.OZONE_QUOTA_TB.length()); - currUnit = Units.TB; - found = true; - } - - if (uppercase.endsWith(Header.OZONE_QUOTA_BYTES)) { - size = uppercase - .substring(0, uppercase.length() - Header.OZONE_QUOTA_BYTES.length()); - currUnit = Units.BYTES; - found = true; - } - - if (!found) { - throw new IllegalArgumentException( - "Quota unit not recognized. Supported values are BYTES, MB, GB and " + - "TB."); - } - - nSize = Integer.parseInt(size); - if (nSize < 0) { - throw new IllegalArgumentException("Quota cannot be negative."); - } - - return new OzoneQuota(nSize, currUnit); - } - - - /** - * Checks if Quota String is just as remove operation. - * - * @param quotaString User provided quota String - * - * @return True if it is Remove, false otherwise - */ - public static boolean isRemove(String quotaString) { - - return (quotaString != null) && - (quotaString.compareToIgnoreCase(Header.OZONE_QUOTA_REMOVE) == 0); - } - - /** - * Returns size in Bytes or -1 if there is no Quota. - */ - @JsonIgnore - public long sizeInBytes() { - switch (this.unit) { - case BYTES: - return this.getSize(); - case MB: - return this.getSize() * OzoneConsts.MB; - case GB: - return this.getSize() * OzoneConsts.GB; - case TB: - return this.getSize() * OzoneConsts.TB; - case UNDEFINED: - default: - return -1; - } - } - - /** - * Returns OzoneQuota corresponding to size in bytes. - * - * @param sizeInBytes size in bytes to be converted - * - * @return OzoneQuota object - */ - public static OzoneQuota getOzoneQuota(long sizeInBytes) { - long size; - Units unit; - if (sizeInBytes % OzoneConsts.TB == 0) { - size = sizeInBytes / OzoneConsts.TB; - unit = Units.TB; - } else if (sizeInBytes % OzoneConsts.GB == 0) { - size = sizeInBytes / OzoneConsts.GB; - unit = Units.GB; - } else if (sizeInBytes % OzoneConsts.MB == 0) { - size = sizeInBytes / OzoneConsts.MB; - unit = Units.MB; - } else { - size = sizeInBytes; - unit = Units.BYTES; - } - return new OzoneQuota((int)size, unit); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/package-info.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/package-info.java deleted file mode 100644 index 4fbc18f..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/request/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Netty-based HTTP server implementation for Ozone. - */ -package org.apache.hadoop.ozone.web.request; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/2c392da8/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/response/BucketInfo.java ---------------------------------------------------------------------- diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/response/BucketInfo.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/response/BucketInfo.java deleted file mode 100644 index e66cd20..0000000 --- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/web/response/BucketInfo.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.ozone.web.response; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import org.apache.hadoop.fs.StorageType; -import org.apache.hadoop.ozone.OzoneConsts; -import org.apache.hadoop.ozone.OzoneAcl; -import org.apache.hadoop.ozone.web.utils.JsonUtils; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.PropertyAccessor; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.ser.FilterProvider; -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import com.google.common.base.Preconditions; - -/** - * BucketInfo class, this is used as response class to send - * Json info about a bucket back to a client. - */ -public class BucketInfo implements Comparable<BucketInfo> { - static final String BUCKET_INFO = "BUCKET_INFO_FILTER"; - private static final ObjectReader READER = - new ObjectMapper().readerFor(BucketInfo.class); - private static final ObjectWriter WRITER; - - static { - ObjectMapper mapper = new ObjectMapper(); - String[] ignorableFieldNames = {"bytesUsed", "keyCount"}; - - FilterProvider filters = new SimpleFilterProvider().addFilter(BUCKET_INFO, - SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames)); - mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); - mapper.addMixIn(Object.class, MixIn.class); - - mapper.setFilterProvider(filters); - WRITER = mapper.writerWithDefaultPrettyPrinter(); - } - - private String volumeName; - private String bucketName; - private String createdOn; - private List<OzoneAcl> acls; - private OzoneConsts.Versioning versioning; - private StorageType storageType; - private long bytesUsed; - private long keyCount; - - /** - * Constructor for BucketInfo. - * - * @param volumeName - * @param bucketName - */ - public BucketInfo(String volumeName, String bucketName) { - this.volumeName = volumeName; - this.bucketName = bucketName; - } - - - /** - * Default constructor for BucketInfo. - */ - public BucketInfo() { - acls = new LinkedList<OzoneAcl>(); - } - - /** - * Parse a JSON string into BucketInfo Object. - * - * @param jsonString - Json String - * - * @return - BucketInfo - * - * @throws IOException - */ - public static BucketInfo parse(String jsonString) throws IOException { - return READER.readValue(jsonString); - } - - /** - * Returns a List of ACL on the Bucket. - * - * @return List of Acls - */ - public List<OzoneAcl> getAcls() { - return acls; - } - - /** - * Sets ACls. - * - * @param acls - Acls list - */ - public void setAcls(List<OzoneAcl> acls) { - this.acls = acls; - } - - /** - * Returns Storage Type info. - * - * @return Storage Type of the bucket - */ - public StorageType getStorageType() { - return storageType; - } - - /** - * Sets the Storage Type. - * - * @param storageType - Storage Type - */ - public void setStorageType(StorageType storageType) { - this.storageType = storageType; - } - - /** - * Returns versioning. - * - * @return versioning Enum - */ - public OzoneConsts.Versioning getVersioning() { - return versioning; - } - - /** - * Sets Versioning. - * - * @param versioning - */ - public void setVersioning(OzoneConsts.Versioning versioning) { - this.versioning = versioning; - } - - - /** - * Gets bucket Name. - * - * @return String - */ - public String getBucketName() { - return bucketName; - } - - /** - * Sets bucket Name. - * - * @param bucketName - Name of the bucket - */ - public void setBucketName(String bucketName) { - this.bucketName = bucketName; - } - - /** - * Sets creation time of the bucket. - * - * @param creationTime - Date String - */ - public void setCreatedOn(String creationTime) { - this.createdOn = creationTime; - } - - /** - * Returns creation time. - * - * @return creation time of bucket. - */ - public String getCreatedOn() { - return createdOn; - } - - /** - * Returns a JSON string of this object. - * After stripping out bytesUsed and keyCount - * - * @return String - */ - public String toJsonString() throws IOException { - return WRITER.writeValueAsString(this); - } - - /** - * Returns the Object as a Json String. - * - * The reason why both toJSONString exists and toDBString exists - * is because toJSONString supports an external facing contract with - * REST clients. However server internally would want to add more - * fields to this class. The distinction helps in serializing all - * fields vs. only fields that are part of REST protocol. - */ - public String toDBString() throws IOException { - return JsonUtils.toJsonString(this); - } - - /** - * Returns Volume Name. - * - * @return String volume name - */ - public String getVolumeName() { - return volumeName; - } - - /** - * Sets the Volume Name of the bucket. - * - * @param volumeName - volumeName - */ - public void setVolumeName(String volumeName) { - this.volumeName = volumeName; - } - - /** - * Compares this object with the specified object for order. Returns a - * negative integer, zero, or a positive integer as this object is less - * than, equal to, or greater than the specified object. - * - * Please note : BucketInfo compare functions are used only within the - * context of a volume, hence volume name is purposefully ignored in - * compareTo, equal and hashcode functions of this class. - */ - @Override - public int compareTo(BucketInfo o) { - Preconditions.checkState(o.getVolumeName().equals(this.getVolumeName())); - return this.bucketName.compareTo(o.getBucketName()); - } - - /** - * Checks if two bucketInfo's are equal. - * @param o Object BucketInfo - * @return True or False - */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof BucketInfo)) { - return false; - } - - BucketInfo that = (BucketInfo) o; - Preconditions.checkState(that.getVolumeName().equals(this.getVolumeName())); - return bucketName.equals(that.bucketName); - - } - - /** - * Hash Code for this object. - * @return int - */ - @Override - public int hashCode() { - return bucketName.hashCode(); - } - - /** - * Get the number of bytes used by this bucket. - * - * @return long - */ - public long getBytesUsed() { - return bytesUsed; - } - - /** - * Set bytes Used. - * - * @param bytesUsed - bytesUsed - */ - public void setBytesUsed(long bytesUsed) { - this.bytesUsed = bytesUsed; - } - - /** - * Get Key Count inside this bucket. - * - * @return - KeyCount - */ - public long getKeyCount() { - return keyCount; - } - - /** - * Set Key Count inside this bucket. - * - * @param keyCount - Sets the Key Count - */ - public void setKeyCount(long keyCount) { - this.keyCount = keyCount; - } - - /** - * This class allows us to create custom filters - * for the Json serialization. - */ - @JsonFilter(BUCKET_INFO) - class MixIn { - - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
