[pulsar-admin] Check backlog quota policy for namespace
@@ -1108,13 +1108,15 @@ public class CmdNamespaces extends CmdBase {
+ "Valid options are: [producer_request_hold, producer_exception, consumer_backlog_eviction]", required = true)
private String policyStr;
- @Parameter(names = {"-t", "--type"}, description = "Backlog quota type to set")
- private String backlogQuotaType = BacklogQuota.BacklogQuotaType.destination_storage.name();
+ @Parameter(names = {"-t", "--type"}, description = "Backlog quota type to set. Valid options are: " +
+ "destination_storage, message_age")
+ private String backlogQuotaTypeStr = BacklogQuota.BacklogQuotaType.destination_storage.name();
@Override
void run() throws PulsarAdminException {
BacklogQuota.RetentionPolicy policy;
long limit;
+ BacklogQuota.BacklogQuotaType backlogQuotaType;
try {
policy = BacklogQuota.RetentionPolicy.valueOf(policyStr);
@@ -1123,7 +1125,19 @@ public class CmdNamespaces extends CmdBase {
policyStr, Arrays.toString(BacklogQuota.RetentionPolicy.values())));
}
+ try {
limit = validateSizeString(limitStr);
+ } catch (IllegalArgumentException e) {
+ throw new ParameterException(String.format("Invalid retention policy type '%s'. Valid formats are: %s",
+ limitStr, "(4096, 100K, 10M, 16G, 2T)"));
+ }
+
+ try {
+ backlogQuotaType = BacklogQuota.BacklogQuotaType.valueOf(backlogQuotaTypeStr);
+ } catch (IllegalArgumentException e) {
+ throw new ParameterException(String.format("Invalid backlog quota type '%s'. Valid options are: %s",
+ backlogQuotaTypeStr, Arrays.toString(BacklogQuota.BacklogQuotaType.values())));
+ }
String namespace = validateNamespace(params);
getAdmin().namespaces().setBacklogQuota(namespace,
@@ -1131,7 +1145,7 @@ public class CmdNamespaces extends CmdBase {
.limitTime(limitTime)
.retentionPolicy(policy)
.build(),
- BacklogQuota.BacklogQuotaType.valueOf(backlogQuotaType));
+ backlogQuotaType);
}
}
@@ -1140,13 +1154,21 @@ public class CmdNamespaces extends CmdBase {
@Parameter(description = "tenant/namespace", required = true)
private java.util.List<String> params;
- @Parameter(names = {"-t", "--type"}, description = "Backlog quota type to remove")
- private String backlogQuotaType = BacklogQuota.BacklogQuotaType.destination_storage.name();
+ @Parameter(names = {"-t", "--type"}, description = "Backlog quota type to remove. Valid options are: " +
+ "destination_storage, message_age")
+ private String backlogQuotaTypeStr = BacklogQuota.BacklogQuotaType.destination_storage.name();
@Override
void run() throws PulsarAdminException {
String namespace = validateNamespace(params);
- getAdmin().namespaces().removeBacklogQuota(namespace, BacklogQuota.BacklogQuotaType.valueOf(backlogQuotaType));
+ BacklogQuota.BacklogQuotaType backlogQuotaType;
+ try {
+ backlogQuotaType = BacklogQuota.BacklogQuotaType.valueOf(backlogQuotaTypeStr);
+ } catch (IllegalArgumentException e) {
+ throw new ParameterException(String.format("Invalid backlog quota type '%s'. Valid options are: %s",
+ backlogQuotaTypeStr, Arrays.toString(BacklogQuota.BacklogQuotaType.values())));
+ }
+ getAdmin().namespaces().removeBacklogQuota(namespace, backlogQuotaType);
}
}
