Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-7561. Improve setquota, clrquota CLI usage #4016

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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