HDDS-113. Rest and Rpc Client should verify resource name using HddsClientUtils.

Contributed by Lokesh Jain.
This commit is contained in:
Anu Engineer 2018-05-25 15:40:46 -07:00
parent 13d2528907
commit 2a9652e696
6 changed files with 64 additions and 108 deletions

View File

@ -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 <T>
*/
public static <T> void checkNotNull(T... references) {
for (T ref: references) {
Preconditions.checkNotNull(ref);
}
}
/** /**
* Returns the cache value to be used for list calls. * Returns the cache value to be used for list calls.
* @param conf Configuration object * @param conf Configuration object

View File

@ -63,8 +63,6 @@ public ObjectStore(Configuration conf, ClientProtocol proxy) {
* @throws IOException * @throws IOException
*/ */
public void createVolume(String volumeName) throws IOException { public void createVolume(String volumeName) throws IOException {
Preconditions.checkNotNull(volumeName);
HddsClientUtils.verifyResourceName(volumeName);
proxy.createVolume(volumeName); proxy.createVolume(volumeName);
} }
@ -76,9 +74,6 @@ public void createVolume(String volumeName) throws IOException {
*/ */
public void createVolume(String volumeName, VolumeArgs volumeArgs) public void createVolume(String volumeName, VolumeArgs volumeArgs)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName);
Preconditions.checkNotNull(volumeArgs);
HddsClientUtils.verifyResourceName(volumeName);
proxy.createVolume(volumeName, volumeArgs); proxy.createVolume(volumeName, volumeArgs);
} }
@ -89,8 +84,6 @@ public void createVolume(String volumeName, VolumeArgs volumeArgs)
* @throws IOException * @throws IOException
*/ */
public OzoneVolume getVolume(String volumeName) throws IOException { public OzoneVolume getVolume(String volumeName) throws IOException {
Preconditions.checkNotNull(volumeName);
HddsClientUtils.verifyResourceName(volumeName);
OzoneVolume volume = proxy.getVolumeDetails(volumeName); OzoneVolume volume = proxy.getVolumeDetails(volumeName);
return volume; return volume;
} }
@ -150,8 +143,6 @@ public Iterator<OzoneVolume> listVolumesByUser(String user,
* @throws IOException * @throws IOException
*/ */
public void deleteVolume(String volumeName) throws IOException { public void deleteVolume(String volumeName) throws IOException {
Preconditions.checkNotNull(volumeName);
HddsClientUtils.verifyResourceName(volumeName);
proxy.deleteVolume(volumeName); proxy.deleteVolume(volumeName);
} }

View File

@ -104,6 +104,7 @@ public OzoneBucket(Configuration conf, ClientProtocol proxy,
String volumeName, String bucketName, String volumeName, String bucketName,
List<OzoneAcl> acls, StorageType storageType, List<OzoneAcl> acls, StorageType storageType,
Boolean versioning, long creationTime) { Boolean versioning, long creationTime) {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
this.proxy = proxy; this.proxy = proxy;
this.volumeName = volumeName; this.volumeName = volumeName;
this.name = bucketName; this.name = bucketName;
@ -180,8 +181,6 @@ public long getCreationTime() {
* @throws IOException * @throws IOException
*/ */
public void addAcls(List<OzoneAcl> addAcls) throws IOException { public void addAcls(List<OzoneAcl> addAcls) throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(addAcls);
proxy.addBucketAcls(volumeName, name, addAcls); proxy.addBucketAcls(volumeName, name, addAcls);
addAcls.stream().filter(acl -> !acls.contains(acl)).forEach( addAcls.stream().filter(acl -> !acls.contains(acl)).forEach(
acls::add); acls::add);
@ -193,8 +192,6 @@ public void addAcls(List<OzoneAcl> addAcls) throws IOException {
* @throws IOException * @throws IOException
*/ */
public void removeAcls(List<OzoneAcl> removeAcls) throws IOException { public void removeAcls(List<OzoneAcl> removeAcls) throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(removeAcls);
proxy.removeBucketAcls(volumeName, name, removeAcls); proxy.removeBucketAcls(volumeName, name, removeAcls);
acls.removeAll(removeAcls); acls.removeAll(removeAcls);
} }
@ -205,8 +202,6 @@ public void removeAcls(List<OzoneAcl> removeAcls) throws IOException {
* @throws IOException * @throws IOException
*/ */
public void setStorageType(StorageType newStorageType) 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); proxy.setBucketStorageType(volumeName, name, newStorageType);
storageType = newStorageType; storageType = newStorageType;
} }
@ -217,8 +212,6 @@ public void setStorageType(StorageType newStorageType) throws IOException {
* @throws IOException * @throws IOException
*/ */
public void setVersioning(Boolean newVersioning) 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); proxy.setBucketVersioning(volumeName, name, newVersioning);
versioning = newVersioning; versioning = newVersioning;
} }
@ -233,8 +226,6 @@ public void setVersioning(Boolean newVersioning) throws IOException {
*/ */
public OzoneOutputStream createKey(String key, long size) public OzoneOutputStream createKey(String key, long size)
throws IOException { throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(key);
return createKey(key, size, defaultReplicationType, defaultReplication); return createKey(key, size, defaultReplicationType, defaultReplication);
} }
@ -251,10 +242,6 @@ public OzoneOutputStream createKey(String key, long size,
ReplicationType type, ReplicationType type,
ReplicationFactor factor) ReplicationFactor factor)
throws IOException { 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); return proxy.createKey(volumeName, name, key, size, type, factor);
} }
@ -265,8 +252,6 @@ public OzoneOutputStream createKey(String key, long size,
* @throws IOException * @throws IOException
*/ */
public OzoneInputStream readKey(String key) 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); return proxy.getKey(volumeName, name, key);
} }
@ -277,8 +262,6 @@ public OzoneInputStream readKey(String key) throws IOException {
* @throws IOException * @throws IOException
*/ */
public OzoneKey getKey(String key) 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); return proxy.getKeyDetails(volumeName, name, key);
} }
@ -314,16 +297,11 @@ public Iterator<OzoneKey> listKeys(String keyPrefix, String prevKey) {
* @throws IOException * @throws IOException
*/ */
public void deleteKey(String key) 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); proxy.deleteKey(volumeName, name, key);
} }
public void renameKey(String fromKeyName, String toKeyName) public void renameKey(String fromKeyName, String toKeyName)
throws IOException { throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(fromKeyName);
Preconditions.checkNotNull(toKeyName);
proxy.renameKey(volumeName, name, fromKeyName, toKeyName); proxy.renameKey(volumeName, name, fromKeyName, toKeyName);
} }

View File

@ -83,6 +83,7 @@ public class OzoneVolume {
public OzoneVolume(Configuration conf, ClientProtocol proxy, String name, public OzoneVolume(Configuration conf, ClientProtocol proxy, String name,
String admin, String owner, long quotaInBytes, String admin, String owner, long quotaInBytes,
long creationTime, List<OzoneAcl> acls) { long creationTime, List<OzoneAcl> acls) {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
this.proxy = proxy; this.proxy = proxy;
this.name = name; this.name = name;
this.admin = admin; this.admin = admin;
@ -153,8 +154,6 @@ public List<OzoneAcl> getAcls() {
* @throws IOException * @throws IOException
*/ */
public void setOwner(String owner) throws IOException { public void setOwner(String owner) throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(owner);
proxy.setVolumeOwner(name, owner); proxy.setVolumeOwner(name, owner);
this.owner = owner; this.owner = owner;
} }
@ -165,8 +164,6 @@ public void setOwner(String owner) throws IOException {
* @throws IOException * @throws IOException
*/ */
public void setQuota(OzoneQuota quota) throws IOException { public void setQuota(OzoneQuota quota) throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(quota);
proxy.setVolumeQuota(name, quota); proxy.setVolumeQuota(name, quota);
this.quotaInBytes = quota.sizeInBytes(); this.quotaInBytes = quota.sizeInBytes();
} }
@ -178,9 +175,6 @@ public void setQuota(OzoneQuota quota) throws IOException {
*/ */
public void createBucket(String bucketName) public void createBucket(String bucketName)
throws IOException { throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(bucketName);
HddsClientUtils.verifyResourceName(bucketName);
proxy.createBucket(name, bucketName); proxy.createBucket(name, bucketName);
} }
@ -192,10 +186,6 @@ public void createBucket(String bucketName)
*/ */
public void createBucket(String bucketName, BucketArgs bucketArgs) public void createBucket(String bucketName, BucketArgs bucketArgs)
throws IOException { throws IOException {
Preconditions.checkNotNull(proxy, "Client proxy is not set.");
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(bucketArgs);
HddsClientUtils.verifyResourceName(bucketName);
proxy.createBucket(name, bucketName, bucketArgs); proxy.createBucket(name, bucketName, bucketArgs);
} }
@ -206,9 +196,6 @@ public void createBucket(String bucketName, BucketArgs bucketArgs)
* @throws IOException * @throws IOException
*/ */
public OzoneBucket getBucket(String bucketName) 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); OzoneBucket bucket = proxy.getBucketDetails(name, bucketName);
return bucket; return bucket;
} }
@ -246,9 +233,6 @@ public Iterator<OzoneBucket> listBuckets(String bucketPrefix,
* @throws IOException * @throws IOException
*/ */
public void deleteBucket(String bucketName) 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); proxy.deleteBucket(name, bucketName);
} }

View File

@ -211,7 +211,8 @@ public void createVolume(String volumeName) throws IOException {
public void createVolume(String volumeName, VolumeArgs volArgs) public void createVolume(String volumeName, VolumeArgs volArgs)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(volArgs);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
String owner = volArgs.getOwner() == null ? String owner = volArgs.getOwner() == null ?
ugi.getUserName() : volArgs.getOwner(); ugi.getUserName() : volArgs.getOwner();
@ -256,7 +257,7 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
public void setVolumeOwner(String volumeName, String owner) public void setVolumeOwner(String volumeName, String owner)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(owner); Preconditions.checkNotNull(owner);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName); builder.setPath(PATH_SEPARATOR + volumeName);
@ -273,7 +274,7 @@ public void setVolumeOwner(String volumeName, String owner)
public void setVolumeQuota(String volumeName, OzoneQuota quota) public void setVolumeQuota(String volumeName, OzoneQuota quota)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(quota); Preconditions.checkNotNull(quota);
String quotaString = quota.toString(); String quotaString = quota.toString();
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
@ -291,7 +292,7 @@ public void setVolumeQuota(String volumeName, OzoneQuota quota)
public OzoneVolume getVolumeDetails(String volumeName) public OzoneVolume getVolumeDetails(String volumeName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName); builder.setPath(PATH_SEPARATOR + volumeName);
builder.setParameter(Header.OZONE_INFO_QUERY_TAG, builder.setParameter(Header.OZONE_INFO_QUERY_TAG,
@ -326,7 +327,7 @@ public boolean checkVolumeAccess(String volumeName, OzoneAcl acl)
@Override @Override
public void deleteVolume(String volumeName) throws IOException { public void deleteVolume(String volumeName) throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName); builder.setPath(PATH_SEPARATOR + volumeName);
HttpDelete httpDelete = new HttpDelete(builder.build()); HttpDelete httpDelete = new HttpDelete(builder.build());
@ -362,8 +363,7 @@ public void createBucket(
String volumeName, String bucketName, BucketArgs bucketArgs) String volumeName, String bucketName, BucketArgs bucketArgs)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(bucketArgs); Preconditions.checkNotNull(bucketArgs);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
OzoneConsts.Versioning versioning = OzoneConsts.Versioning.DISABLED; OzoneConsts.Versioning versioning = OzoneConsts.Versioning.DISABLED;
@ -404,8 +404,7 @@ public void addBucketAcls(
String volumeName, String bucketName, List<OzoneAcl> addAcls) String volumeName, String bucketName, List<OzoneAcl> addAcls)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(addAcls); Preconditions.checkNotNull(addAcls);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
@ -429,8 +428,7 @@ public void removeBucketAcls(
String volumeName, String bucketName, List<OzoneAcl> removeAcls) String volumeName, String bucketName, List<OzoneAcl> removeAcls)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(removeAcls); Preconditions.checkNotNull(removeAcls);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
@ -454,8 +452,7 @@ public void setBucketVersioning(
String volumeName, String bucketName, Boolean versioning) String volumeName, String bucketName, Boolean versioning)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(versioning); Preconditions.checkNotNull(versioning);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
@ -477,8 +474,7 @@ public void setBucketStorageType(
String volumeName, String bucketName, StorageType storageType) String volumeName, String bucketName, StorageType storageType)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(storageType); Preconditions.checkNotNull(storageType);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
@ -498,8 +494,7 @@ public void setBucketStorageType(
public void deleteBucket(String volumeName, String bucketName) public void deleteBucket(String volumeName, String bucketName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + builder.setPath(PATH_SEPARATOR + volumeName +
PATH_SEPARATOR + bucketName); PATH_SEPARATOR + bucketName);
@ -521,8 +516,7 @@ public void checkBucketAccess(String volumeName, String bucketName)
public OzoneBucket getBucketDetails(String volumeName, String bucketName) public OzoneBucket getBucketDetails(String volumeName, String bucketName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + builder.setPath(PATH_SEPARATOR + volumeName +
PATH_SEPARATOR + bucketName); PATH_SEPARATOR + bucketName);
@ -573,9 +567,8 @@ public OzoneOutputStream createKey(
// TODO: Once ReplicationType and ReplicationFactor are supported in // TODO: Once ReplicationType and ReplicationFactor are supported in
// OzoneHandler (in Datanode), set them in header. // OzoneHandler (in Datanode), set them in header.
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName); HddsClientUtils.checkNotNull(keyName, type, factor);
Preconditions.checkNotNull(keyName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + builder.setPath(PATH_SEPARATOR + volumeName +
PATH_SEPARATOR + bucketName + PATH_SEPARATOR + bucketName +
@ -617,8 +610,7 @@ public OzoneInputStream getKey(
String volumeName, String bucketName, String keyName) String volumeName, String bucketName, String keyName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(keyName); Preconditions.checkNotNull(keyName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + builder.setPath(PATH_SEPARATOR + volumeName +
@ -661,8 +653,7 @@ public void close() throws IOException {
public void deleteKey(String volumeName, String bucketName, String keyName) public void deleteKey(String volumeName, String bucketName, String keyName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(keyName); Preconditions.checkNotNull(keyName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + 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, public void renameKey(String volumeName, String bucketName,
String fromKeyName, String toKeyName) throws IOException { String fromKeyName, String toKeyName) throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName); HddsClientUtils.checkNotNull(fromKeyName, toKeyName);
Preconditions.checkNotNull(fromKeyName);
Preconditions.checkNotNull(toKeyName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName builder.setPath(PATH_SEPARATOR + volumeName + PATH_SEPARATOR + bucketName
+ PATH_SEPARATOR + fromKeyName); + PATH_SEPARATOR + fromKeyName);
@ -708,8 +697,7 @@ public OzoneKey getKeyDetails(
String volumeName, String bucketName, String keyName) String volumeName, String bucketName, String keyName)
throws IOException { throws IOException {
try { try {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(keyName); Preconditions.checkNotNull(keyName);
URIBuilder builder = new URIBuilder(ozoneRestUri); URIBuilder builder = new URIBuilder(ozoneRestUri);
builder.setPath(PATH_SEPARATOR + volumeName + builder.setPath(PATH_SEPARATOR + volumeName +

View File

@ -22,6 +22,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.ipc.Client; import org.apache.hadoop.ipc.Client;
import org.apache.hadoop.ipc.ProtobufRpcEngine; import org.apache.hadoop.ipc.ProtobufRpcEngine;
@ -170,7 +171,7 @@ public void createVolume(String volumeName) throws IOException {
@Override @Override
public void createVolume(String volumeName, VolumeArgs volArgs) public void createVolume(String volumeName, VolumeArgs volArgs)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(volArgs); Preconditions.checkNotNull(volArgs);
String admin = volArgs.getAdmin() == null ? String admin = volArgs.getAdmin() == null ?
@ -214,7 +215,7 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
@Override @Override
public void setVolumeOwner(String volumeName, String owner) public void setVolumeOwner(String volumeName, String owner)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(owner); Preconditions.checkNotNull(owner);
keySpaceManagerClient.setOwner(volumeName, owner); keySpaceManagerClient.setOwner(volumeName, owner);
} }
@ -222,7 +223,7 @@ public void setVolumeOwner(String volumeName, String owner)
@Override @Override
public void setVolumeQuota(String volumeName, OzoneQuota quota) public void setVolumeQuota(String volumeName, OzoneQuota quota)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
Preconditions.checkNotNull(quota); Preconditions.checkNotNull(quota);
long quotaInBytes = quota.sizeInBytes(); long quotaInBytes = quota.sizeInBytes();
keySpaceManagerClient.setQuota(volumeName, quotaInBytes); keySpaceManagerClient.setQuota(volumeName, quotaInBytes);
@ -231,7 +232,7 @@ public void setVolumeQuota(String volumeName, OzoneQuota quota)
@Override @Override
public OzoneVolume getVolumeDetails(String volumeName) public OzoneVolume getVolumeDetails(String volumeName)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
KsmVolumeArgs volume = keySpaceManagerClient.getVolumeInfo(volumeName); KsmVolumeArgs volume = keySpaceManagerClient.getVolumeInfo(volumeName);
return new OzoneVolume( return new OzoneVolume(
conf, conf,
@ -253,7 +254,7 @@ public boolean checkVolumeAccess(String volumeName, OzoneAcl acl)
@Override @Override
public void deleteVolume(String volumeName) throws IOException { public void deleteVolume(String volumeName) throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName);
keySpaceManagerClient.deleteVolume(volumeName); keySpaceManagerClient.deleteVolume(volumeName);
} }
@ -307,8 +308,7 @@ public void createBucket(String volumeName, String bucketName)
public void createBucket( public void createBucket(
String volumeName, String bucketName, BucketArgs bucketArgs) String volumeName, String bucketName, BucketArgs bucketArgs)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(bucketArgs); Preconditions.checkNotNull(bucketArgs);
Boolean isVersionEnabled = bucketArgs.getVersioning() == null ? Boolean isVersionEnabled = bucketArgs.getVersioning() == null ?
@ -346,8 +346,7 @@ public void createBucket(
public void addBucketAcls( public void addBucketAcls(
String volumeName, String bucketName, List<OzoneAcl> addAcls) String volumeName, String bucketName, List<OzoneAcl> addAcls)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(addAcls); Preconditions.checkNotNull(addAcls);
KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder();
builder.setVolumeName(volumeName) builder.setVolumeName(volumeName)
@ -360,8 +359,7 @@ public void addBucketAcls(
public void removeBucketAcls( public void removeBucketAcls(
String volumeName, String bucketName, List<OzoneAcl> removeAcls) String volumeName, String bucketName, List<OzoneAcl> removeAcls)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(removeAcls); Preconditions.checkNotNull(removeAcls);
KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder();
builder.setVolumeName(volumeName) builder.setVolumeName(volumeName)
@ -374,8 +372,7 @@ public void removeBucketAcls(
public void setBucketVersioning( public void setBucketVersioning(
String volumeName, String bucketName, Boolean versioning) String volumeName, String bucketName, Boolean versioning)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(versioning); Preconditions.checkNotNull(versioning);
KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder();
builder.setVolumeName(volumeName) builder.setVolumeName(volumeName)
@ -388,8 +385,7 @@ public void setBucketVersioning(
public void setBucketStorageType( public void setBucketStorageType(
String volumeName, String bucketName, StorageType storageType) String volumeName, String bucketName, StorageType storageType)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(storageType); Preconditions.checkNotNull(storageType);
KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder(); KsmBucketArgs.Builder builder = KsmBucketArgs.newBuilder();
builder.setVolumeName(volumeName) builder.setVolumeName(volumeName)
@ -401,8 +397,7 @@ public void setBucketStorageType(
@Override @Override
public void deleteBucket( public void deleteBucket(
String volumeName, String bucketName) throws IOException { String volumeName, String bucketName) throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
keySpaceManagerClient.deleteBucket(volumeName, bucketName); keySpaceManagerClient.deleteBucket(volumeName, bucketName);
} }
@ -415,8 +410,7 @@ public void checkBucketAccess(
@Override @Override
public OzoneBucket getBucketDetails( public OzoneBucket getBucketDetails(
String volumeName, String bucketName) throws IOException { String volumeName, String bucketName) throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
KsmBucketInfo bucketArgs = KsmBucketInfo bucketArgs =
keySpaceManagerClient.getBucketInfo(volumeName, bucketName); keySpaceManagerClient.getBucketInfo(volumeName, bucketName);
return new OzoneBucket( return new OzoneBucket(
@ -454,6 +448,8 @@ public OzoneOutputStream createKey(
String volumeName, String bucketName, String keyName, long size, String volumeName, String bucketName, String keyName, long size,
ReplicationType type, ReplicationFactor factor) ReplicationType type, ReplicationFactor factor)
throws IOException { throws IOException {
HddsClientUtils.verifyResourceName(volumeName, bucketName);
HddsClientUtils.checkNotNull(keyName, type, factor);
String requestId = UUID.randomUUID().toString(); String requestId = UUID.randomUUID().toString();
KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() KsmKeyArgs keyArgs = new KsmKeyArgs.Builder()
.setVolumeName(volumeName) .setVolumeName(volumeName)
@ -486,8 +482,7 @@ public OzoneOutputStream createKey(
public OzoneInputStream getKey( public OzoneInputStream getKey(
String volumeName, String bucketName, String keyName) String volumeName, String bucketName, String keyName)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(keyName); Preconditions.checkNotNull(keyName);
String requestId = UUID.randomUUID().toString(); String requestId = UUID.randomUUID().toString();
KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() KsmKeyArgs keyArgs = new KsmKeyArgs.Builder()
@ -508,8 +503,7 @@ public OzoneInputStream getKey(
public void deleteKey( public void deleteKey(
String volumeName, String bucketName, String keyName) String volumeName, String bucketName, String keyName)
throws IOException { throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName);
Preconditions.checkNotNull(keyName); Preconditions.checkNotNull(keyName);
KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() KsmKeyArgs keyArgs = new KsmKeyArgs.Builder()
.setVolumeName(volumeName) .setVolumeName(volumeName)
@ -522,10 +516,8 @@ public void deleteKey(
@Override @Override
public void renameKey(String volumeName, String bucketName, public void renameKey(String volumeName, String bucketName,
String fromKeyName, String toKeyName) throws IOException { String fromKeyName, String toKeyName) throws IOException {
Preconditions.checkNotNull(volumeName); HddsClientUtils.verifyResourceName(volumeName, bucketName);
Preconditions.checkNotNull(bucketName); HddsClientUtils.checkNotNull(fromKeyName, toKeyName);
Preconditions.checkNotNull(fromKeyName);
Preconditions.checkNotNull(toKeyName);
KsmKeyArgs keyArgs = new KsmKeyArgs.Builder() KsmKeyArgs keyArgs = new KsmKeyArgs.Builder()
.setVolumeName(volumeName) .setVolumeName(volumeName)
.setBucketName(bucketName) .setBucketName(bucketName)