Skip to content

Commit

Permalink
HDDS-7561. Improve setquota, clrquota CLI usage (#4016)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitagrawl committed Nov 30, 2022
1 parent eeeb0b5 commit f1d651d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ public void testShQuota() throws Exception {
.getQuotaInNamespace());

// Test clrquota option.
args = new String[]{"volume", "clrquota", "vol4"};
executeWithError(ozoneShell, args, "At least one of the quota clear" +
" flag is required");
out.reset();

args = new String[]{"volume", "clrquota", "vol4", "--space-quota",
"--namespace-quota"};
execute(ozoneShell, args);
Expand All @@ -828,6 +833,11 @@ public void testShQuota() throws Exception {
objectStore.getVolume("vol4").getQuotaInNamespace());
out.reset();

args = new String[]{"bucket", "clrquota", "vol4/buck4"};
executeWithError(ozoneShell, args, "At least one of the quota clear" +
" flag is required");
out.reset();

args = new String[]{"bucket", "clrquota", "vol4/buck4",
"--space-quota", "--namespace-quota"};
execute(ozoneShell, args);
Expand Down Expand Up @@ -870,6 +880,12 @@ public void testShQuota() throws Exception {
assertEquals(100,
objectStore.getVolume("vol4").getQuotaInNamespace());

// Test set volume quota without quota flag
String[] volumeArgs5 = new String[]{"volume", "setquota", "vol4"};
executeWithError(ozoneShell, volumeArgs5,
"At least one of the quota set flag is required");
out.reset();

// Test set bucket quota to 0.
String[] bucketArgs1 = new String[]{"bucket", "setquota", "vol4/buck4",
"--space-quota", "0GB"};
Expand Down Expand Up @@ -914,6 +930,12 @@ public void testShQuota() throws Exception {
assertEquals(100, objectStore.getVolume("vol4")
.getBucket("buck4").getQuotaInNamespace());

// Test set volume quota without quota flag
String[] bucketArgs6 = new String[]{"bucket", "setquota", "vol4/buck4"};
executeWithError(ozoneShell, bucketArgs6,
"At least one of the quota set flag is required");
out.reset();

objectStore.getVolume("vol").deleteBucket("buck");
objectStore.deleteVolume("vol");
objectStore.getVolume("vol1").deleteBucket("buck1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* clean quota of the bucket.
*/
@Command(name = "clrquota",
description = "clear quota of the bucket")
description = "clear quota of the bucket. At least one of the " +
"quota clear flag is mandatory.")
public class ClearQuotaHandler extends BucketHandler {

@CommandLine.Mixin
Expand All @@ -44,12 +45,19 @@ protected void execute(OzoneClient client, OzoneAddress address)
String bucketName = address.getBucketName();
OzoneBucket bucket = client.getObjectStore().getVolume(volumeName)
.getBucket(bucketName);

boolean isOptionPresent = false;
if (clrSpaceQuota.getClrSpaceQuota()) {
bucket.clearSpaceQuota();
isOptionPresent = true;
}
if (clrSpaceQuota.getClrNamespaceQuota()) {
bucket.clearNamespaceQuota();
isOptionPresent = true;
}

if (!isOptionPresent) {
throw new IOException(
"At least one of the quota clear flag is required.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* set quota of the bucket.
*/
@Command(name = "setquota",
description = "Set quota of the buckets")
description = "Set quota of the buckets. At least one of the " +
"quota set flag is mandatory.")
public class SetQuotaHandler extends BucketHandler {

@CommandLine.Mixin
Expand All @@ -50,15 +51,22 @@ public void execute(OzoneClient client, OzoneAddress address)
.getBucket(bucketName);
long spaceQuota = bucket.getQuotaInBytes();
long namespaceQuota = bucket.getQuotaInNamespace();

boolean isOptionPresent = false;
if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInBytes())) {
spaceQuota = OzoneQuota.parseSpaceQuota(
quotaOptions.getQuotaInBytes()).getQuotaInBytes();
isOptionPresent = true;
}

if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInNamespace())) {
namespaceQuota = OzoneQuota.parseNameSpaceQuota(
quotaOptions.getQuotaInNamespace()).getQuotaInNamespace();
isOptionPresent = true;
}

if (!isOptionPresent) {
throw new IOException(
"At least one of the quota set flag is required.");
}

if (bucket.getQuotaInNamespace() == OLD_QUOTA_DEFAULT ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* clear quota of the volume.
*/
@Command(name = "clrquota",
description = "clear quota of the volume")
description = "clear quota of the volume. At least one of the " +
"quota clear flag is mandatory.")
public class ClearQuotaHandler extends VolumeHandler {

@CommandLine.Mixin
Expand All @@ -42,12 +43,19 @@ protected void execute(OzoneClient client, OzoneAddress address)
throws IOException {
String volumeName = address.getVolumeName();
OzoneVolume volume = client.getObjectStore().getVolume(volumeName);

boolean isOptionPresent = false;
if (clrSpaceQuota.getClrSpaceQuota()) {
volume.clearSpaceQuota();
isOptionPresent = true;
}
if (clrSpaceQuota.getClrNamespaceQuota()) {
volume.clearNamespaceQuota();
isOptionPresent = true;
}

if (!isOptionPresent) {
throw new IOException(
"At least one of the quota clear flag is required.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* Executes set volume quota calls.
*/
@Command(name = "setquota",
description = "Set quota of the volumes")
description = "Set quota of the volumes. At least one of the " +
"quota set flag is mandatory.")
public class SetQuotaHandler extends VolumeHandler {

@CommandLine.Mixin
Expand All @@ -49,14 +50,22 @@ protected void execute(OzoneClient client, OzoneAddress address)

long spaceQuota = volume.getQuotaInBytes();
long namespaceQuota = volume.getQuotaInNamespace();
boolean isOptionPresent = false;
if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInBytes())) {
spaceQuota = OzoneQuota.parseSpaceQuota(
quotaOptions.getQuotaInBytes()).getQuotaInBytes();
isOptionPresent = true;
}

if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInNamespace())) {
namespaceQuota = OzoneQuota.parseNameSpaceQuota(
quotaOptions.getQuotaInNamespace()).getQuotaInNamespace();
isOptionPresent = true;
}

if (!isOptionPresent) {
throw new IOException(
"At least one of the quota set flag is required.");
}

if (volume.getQuotaInNamespace() == OLD_QUOTA_DEFAULT) {
Expand Down

0 comments on commit f1d651d

Please sign in to comment.