From 2a9652e69650973f6158b60ff131215827738db6 Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Fri, 25 May 2018 15:40:46 -0700 Subject: [PATCH] HDDS-113. Rest and Rpc Client should verify resource name using HddsClientUtils. Contributed by Lokesh Jain. --- .../hdds/scm/client/HddsClientUtils.java | 23 ++++++++ .../hadoop/ozone/client/ObjectStore.java | 9 ---- .../hadoop/ozone/client/OzoneBucket.java | 24 +-------- .../hadoop/ozone/client/OzoneVolume.java | 18 +------ .../hadoop/ozone/client/rest/RestClient.java | 52 +++++++------------ .../hadoop/ozone/client/rpc/RpcClient.java | 46 +++++++--------- 6 files changed, 64 insertions(+), 108 deletions(-) diff --git a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java index bc5f8d65b4..a6813ebf60 100644 --- a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java +++ b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java @@ -169,6 +169,29 @@ public static void verifyResourceName(String resName) } } + /** + * verifies that bucket / volume name is a valid DNS name. + * + * @param resourceNames Array of bucket / volume names to be verified. + */ + public static void verifyResourceName(String... resourceNames) { + for (String resourceName : resourceNames) { + HddsClientUtils.verifyResourceName(resourceName); + } + } + + /** + * Checks that object parameters passed as reference is not null. + * + * @param references Array of object references to be checked. + * @param + */ + public static void checkNotNull(T... references) { + for (T ref: references) { + Preconditions.checkNotNull(ref); + } + } + /** * Returns the cache value to be used for list calls. * @param conf Configuration object diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java index d8b30112d3..c5f0689818 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java @@ -63,8 +63,6 @@ public ObjectStore(Configuration conf, ClientProtocol proxy) { * @throws IOException */ public void createVolume(String volumeName) throws IOException { - Preconditions.checkNotNull(volumeName); - HddsClientUtils.verifyResourceName(volumeName); proxy.createVolume(volumeName); } @@ -76,9 +74,6 @@ public void createVolume(String volumeName) throws IOException { */ public void createVolume(String volumeName, VolumeArgs volumeArgs) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(volumeArgs); - HddsClientUtils.verifyResourceName(volumeName); proxy.createVolume(volumeName, volumeArgs); } @@ -89,8 +84,6 @@ public void createVolume(String volumeName, VolumeArgs volumeArgs) * @throws IOException */ public OzoneVolume getVolume(String volumeName) throws IOException { - Preconditions.checkNotNull(volumeName); - HddsClientUtils.verifyResourceName(volumeName); OzoneVolume volume = proxy.getVolumeDetails(volumeName); return volume; } @@ -150,8 +143,6 @@ public Iterator listVolumesByUser(String user, * @throws IOException */ public void deleteVolume(String volumeName) throws IOException { - Preconditions.checkNotNull(volumeName); - HddsClientUtils.verifyResourceName(volumeName); proxy.deleteVolume(volumeName); } diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java index 5df025492e..2f3cff6c36 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java @@ -104,6 +104,7 @@ public OzoneBucket(Configuration conf, ClientProtocol proxy, String volumeName, String bucketName, List acls, StorageType storageType, Boolean versioning, long creationTime) { + Preconditions.checkNotNull(proxy, "Client proxy is not set."); this.proxy = proxy; this.volumeName = volumeName; this.name = bucketName; @@ -180,8 +181,6 @@ public long getCreationTime() { * @throws IOException */ public void addAcls(List addAcls) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(addAcls); proxy.addBucketAcls(volumeName, name, addAcls); addAcls.stream().filter(acl -> !acls.contains(acl)).forEach( acls::add); @@ -193,8 +192,6 @@ public void addAcls(List addAcls) throws IOException { * @throws IOException */ public void removeAcls(List removeAcls) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(removeAcls); proxy.removeBucketAcls(volumeName, name, removeAcls); acls.removeAll(removeAcls); } @@ -205,8 +202,6 @@ public void removeAcls(List removeAcls) throws IOException { * @throws IOException */ public void setStorageType(StorageType newStorageType) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(newStorageType); proxy.setBucketStorageType(volumeName, name, newStorageType); storageType = newStorageType; } @@ -217,8 +212,6 @@ public void setStorageType(StorageType newStorageType) throws IOException { * @throws IOException */ public void setVersioning(Boolean newVersioning) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(newVersioning); proxy.setBucketVersioning(volumeName, name, newVersioning); versioning = newVersioning; } @@ -233,8 +226,6 @@ public void setVersioning(Boolean newVersioning) throws IOException { */ public OzoneOutputStream createKey(String key, long size) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(key); return createKey(key, size, defaultReplicationType, defaultReplication); } @@ -251,10 +242,6 @@ public OzoneOutputStream createKey(String key, long size, ReplicationType type, ReplicationFactor factor) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(key); - Preconditions.checkNotNull(type); - Preconditions.checkNotNull(factor); return proxy.createKey(volumeName, name, key, size, type, factor); } @@ -265,8 +252,6 @@ public OzoneOutputStream createKey(String key, long size, * @throws IOException */ public OzoneInputStream readKey(String key) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(key); return proxy.getKey(volumeName, name, key); } @@ -277,8 +262,6 @@ public OzoneInputStream readKey(String key) throws IOException { * @throws IOException */ public OzoneKey getKey(String key) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(key); return proxy.getKeyDetails(volumeName, name, key); } @@ -314,16 +297,11 @@ public Iterator listKeys(String keyPrefix, String prevKey) { * @throws IOException */ public void deleteKey(String key) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(key); proxy.deleteKey(volumeName, name, key); } public void renameKey(String fromKeyName, String toKeyName) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(fromKeyName); - Preconditions.checkNotNull(toKeyName); proxy.renameKey(volumeName, name, fromKeyName, toKeyName); } diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java index 4601f1aa40..77f882acff 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java @@ -83,6 +83,7 @@ public class OzoneVolume { public OzoneVolume(Configuration conf, ClientProtocol proxy, String name, String admin, String owner, long quotaInBytes, long creationTime, List acls) { + Preconditions.checkNotNull(proxy, "Client proxy is not set."); this.proxy = proxy; this.name = name; this.admin = admin; @@ -153,8 +154,6 @@ public List getAcls() { * @throws IOException */ public void setOwner(String owner) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(owner); proxy.setVolumeOwner(name, owner); this.owner = owner; } @@ -165,8 +164,6 @@ public void setOwner(String owner) throws IOException { * @throws IOException */ public void setQuota(OzoneQuota quota) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(quota); proxy.setVolumeQuota(name, quota); this.quotaInBytes = quota.sizeInBytes(); } @@ -178,9 +175,6 @@ public void setQuota(OzoneQuota quota) throws IOException { */ public void createBucket(String bucketName) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(bucketName); - HddsClientUtils.verifyResourceName(bucketName); proxy.createBucket(name, bucketName); } @@ -192,10 +186,6 @@ public void createBucket(String bucketName) */ public void createBucket(String bucketName, BucketArgs bucketArgs) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(bucketName); - Preconditions.checkNotNull(bucketArgs); - HddsClientUtils.verifyResourceName(bucketName); proxy.createBucket(name, bucketName, bucketArgs); } @@ -206,9 +196,6 @@ public void createBucket(String bucketName, BucketArgs bucketArgs) * @throws IOException */ public OzoneBucket getBucket(String bucketName) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(bucketName); - HddsClientUtils.verifyResourceName(bucketName); OzoneBucket bucket = proxy.getBucketDetails(name, bucketName); return bucket; } @@ -246,9 +233,6 @@ public Iterator listBuckets(String bucketPrefix, * @throws IOException */ public void deleteBucket(String bucketName) throws IOException { - Preconditions.checkNotNull(proxy, "Client proxy is not set."); - Preconditions.checkNotNull(bucketName); - HddsClientUtils.verifyResourceName(bucketName); proxy.deleteBucket(name, bucketName); } diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java index ac71abe494..1169820382 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rest/RestClient.java @@ -211,7 +211,8 @@ public void createVolume(String volumeName) throws IOException { public void createVolume(String volumeName, VolumeArgs volArgs) throws IOException { try { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); + Preconditions.checkNotNull(volArgs); URIBuilder builder = new URIBuilder(ozoneRestUri); String owner = volArgs.getOwner() == null ? ugi.getUserName() : volArgs.getOwner(); @@ -256,7 +257,7 @@ public void createVolume(String volumeName, VolumeArgs volArgs) public void setVolumeOwner(String volumeName, String owner) throws IOException { try { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); Preconditions.checkNotNull(owner); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName); @@ -273,7 +274,7 @@ public void setVolumeOwner(String volumeName, String owner) public void setVolumeQuota(String volumeName, OzoneQuota quota) throws IOException { try { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); Preconditions.checkNotNull(quota); String quotaString = quota.toString(); URIBuilder builder = new URIBuilder(ozoneRestUri); @@ -291,7 +292,7 @@ public void setVolumeQuota(String volumeName, OzoneQuota quota) public OzoneVolume getVolumeDetails(String volumeName) throws IOException { try { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName); builder.setParameter(Header.OZONE_INFO_QUERY_TAG, @@ -326,7 +327,7 @@ public boolean checkVolumeAccess(String volumeName, OzoneAcl acl) @Override public void deleteVolume(String volumeName) throws IOException { try { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName); HttpDelete httpDelete = new HttpDelete(builder.build()); @@ -362,8 +363,7 @@ public void createBucket( String volumeName, String bucketName, BucketArgs bucketArgs) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(bucketArgs); URIBuilder builder = new URIBuilder(ozoneRestUri); OzoneConsts.Versioning versioning = OzoneConsts.Versioning.DISABLED; @@ -404,8 +404,7 @@ public void addBucketAcls( String volumeName, String bucketName, List addAcls) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(addAcls); URIBuilder builder = new URIBuilder(ozoneRestUri); @@ -429,8 +428,7 @@ public void removeBucketAcls( String volumeName, String bucketName, List removeAcls) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(removeAcls); URIBuilder builder = new URIBuilder(ozoneRestUri); @@ -454,8 +452,7 @@ public void setBucketVersioning( String volumeName, String bucketName, Boolean versioning) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(versioning); URIBuilder builder = new URIBuilder(ozoneRestUri); @@ -477,8 +474,7 @@ public void setBucketStorageType( String volumeName, String bucketName, StorageType storageType) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(storageType); URIBuilder builder = new URIBuilder(ozoneRestUri); @@ -498,8 +494,7 @@ public void setBucketStorageType( public void deleteBucket(String volumeName, String bucketName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName); @@ -521,8 +516,7 @@ public void checkBucketAccess(String volumeName, String bucketName) public OzoneBucket getBucketDetails(String volumeName, String bucketName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName); @@ -573,9 +567,8 @@ public OzoneOutputStream createKey( // TODO: Once ReplicationType and ReplicationFactor are supported in // OzoneHandler (in Datanode), set them in header. try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); - Preconditions.checkNotNull(keyName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); + HddsClientUtils.checkNotNull(keyName, type, factor); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName + @@ -617,8 +610,7 @@ public OzoneInputStream getKey( String volumeName, String bucketName, String keyName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(keyName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + @@ -661,8 +653,7 @@ public void close() throws IOException { public void deleteKey(String volumeName, String bucketName, String keyName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(keyName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + @@ -679,10 +670,8 @@ public void deleteKey(String volumeName, String bucketName, String keyName) public void renameKey(String volumeName, String bucketName, String fromKeyName, String toKeyName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); - Preconditions.checkNotNull(fromKeyName); - Preconditions.checkNotNull(toKeyName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); + HddsClientUtils.checkNotNull(fromKeyName, toKeyName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName + PATH_SEPARATOR + fromKeyName); @@ -708,8 +697,7 @@ public OzoneKey getKeyDetails( String volumeName, String bucketName, String keyName) throws IOException { try { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(keyName); URIBuilder builder = new URIBuilder(ozoneRestUri); builder.setPath(PATH_SEPARATOR + volumeName + diff --git a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java index ffe93dde34..43b94a1529 100644 --- a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java +++ b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java @@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.fs.StorageType; +import org.apache.hadoop.hdds.scm.client.HddsClientUtils; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ipc.Client; import org.apache.hadoop.ipc.ProtobufRpcEngine; @@ -170,7 +171,7 @@ public void createVolume(String volumeName) throws IOException { @Override public void createVolume(String volumeName, VolumeArgs volArgs) throws IOException { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); Preconditions.checkNotNull(volArgs); String admin = volArgs.getAdmin() == null ? @@ -214,7 +215,7 @@ public void createVolume(String volumeName, VolumeArgs volArgs) @Override public void setVolumeOwner(String volumeName, String owner) throws IOException { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); Preconditions.checkNotNull(owner); keySpaceManagerClient.setOwner(volumeName, owner); } @@ -222,7 +223,7 @@ public void setVolumeOwner(String volumeName, String owner) @Override public void setVolumeQuota(String volumeName, OzoneQuota quota) throws IOException { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); Preconditions.checkNotNull(quota); long quotaInBytes = quota.sizeInBytes(); keySpaceManagerClient.setQuota(volumeName, quotaInBytes); @@ -231,7 +232,7 @@ public void setVolumeQuota(String volumeName, OzoneQuota quota) @Override public OzoneVolume getVolumeDetails(String volumeName) throws IOException { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); KsmVolumeArgs volume = keySpaceManagerClient.getVolumeInfo(volumeName); return new OzoneVolume( conf, @@ -253,7 +254,7 @@ public boolean checkVolumeAccess(String volumeName, OzoneAcl acl) @Override public void deleteVolume(String volumeName) throws IOException { - Preconditions.checkNotNull(volumeName); + HddsClientUtils.verifyResourceName(volumeName); keySpaceManagerClient.deleteVolume(volumeName); } @@ -307,8 +308,7 @@ public void createBucket(String volumeName, String bucketName) public void createBucket( String volumeName, String bucketName, BucketArgs bucketArgs) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(bucketArgs); Boolean isVersionEnabled = bucketArgs.getVersioning() == null ? @@ -346,8 +346,7 @@ public void createBucket( public void addBucketAcls( String volumeName, String bucketName, List addAcls) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(addAcls); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); builder.setVolumeName(volumeName) @@ -360,8 +359,7 @@ public void addBucketAcls( public void removeBucketAcls( String volumeName, String bucketName, List removeAcls) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(removeAcls); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); builder.setVolumeName(volumeName) @@ -374,8 +372,7 @@ public void removeBucketAcls( public void setBucketVersioning( String volumeName, String bucketName, Boolean versioning) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(versioning); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); builder.setVolumeName(volumeName) @@ -388,8 +385,7 @@ public void setBucketVersioning( public void setBucketStorageType( String volumeName, String bucketName, StorageType storageType) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(storageType); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); builder.setVolumeName(volumeName) @@ -401,8 +397,7 @@ public void setBucketStorageType( @Override public void deleteBucket( String volumeName, String bucketName) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); keySpaceManagerClient.deleteBucket(volumeName, bucketName); } @@ -415,8 +410,7 @@ public void checkBucketAccess( @Override public OzoneBucket getBucketDetails( String volumeName, String bucketName) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); KsmBucketInfo bucketArgs = keySpaceManagerClient.getBucketInfo(volumeName, bucketName); return new OzoneBucket( @@ -454,6 +448,8 @@ public OzoneOutputStream createKey( String volumeName, String bucketName, String keyName, long size, ReplicationType type, ReplicationFactor factor) throws IOException { + HddsClientUtils.verifyResourceName(volumeName, bucketName); + HddsClientUtils.checkNotNull(keyName, type, factor); String requestId = UUID.randomUUID().toString(); KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() .setVolumeName(volumeName) @@ -486,8 +482,7 @@ public OzoneOutputStream createKey( public OzoneInputStream getKey( String volumeName, String bucketName, String keyName) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(keyName); String requestId = UUID.randomUUID().toString(); KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() @@ -508,8 +503,7 @@ public OzoneInputStream getKey( public void deleteKey( String volumeName, String bucketName, String keyName) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); Preconditions.checkNotNull(keyName); KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() .setVolumeName(volumeName) @@ -522,10 +516,8 @@ public void deleteKey( @Override public void renameKey(String volumeName, String bucketName, String fromKeyName, String toKeyName) throws IOException { - Preconditions.checkNotNull(volumeName); - Preconditions.checkNotNull(bucketName); - Preconditions.checkNotNull(fromKeyName); - Preconditions.checkNotNull(toKeyName); + HddsClientUtils.verifyResourceName(volumeName, bucketName); + HddsClientUtils.checkNotNull(fromKeyName, toKeyName); KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() .setVolumeName(volumeName) .setBucketName(bucketName)