JooHyukKim commented on code in PR #20764:
URL: https://github.com/apache/pulsar/pull/20764#discussion_r1328735763
##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java:
##########
@@ -747,39 +743,27 @@ private class SetRetention extends CliCommand {
+ "For example, 100m, 3h, 2d, 5w. "
+ "If the time unit is not specified, the default unit
is seconds. For example, "
+ "-t 120 sets retention to 2 minutes. "
- + "0 means no retention and -1 means infinite time
retention.", required = true)
- private String retentionTimeStr;
+ + "0 means no retention and -1 means infinite time
retention.", required = true,
+ converter = TimeUnitToSecondsConverter.class,
+ validateValueWith = MinNegativeOneValidator.class)
+ private Long retentionTimeInSec;
@Parameter(names = { "--size", "-s" }, description = "Retention size
limit with optional size unit suffix. "
+ "For example, 4096, 10M, 16G, 3T. The size unit suffix
character can be k/K, m/M, g/G, or t/T. "
+ "If the size unit suffix is not specified, the default unit
is bytes. "
- + "0 or less than 1MB means no retention and -1 means infinite
size retention", required = true)
- private String limitStr;
+ + "0 or less than 1MB means no retention and -1 means infinite
size retention", required = true,
+ converter = ByteUnitIntegerConverter.class)
+ private Integer sizeLimit;
@Override
void run() throws PulsarAdminException {
String namespace = validateNamespace(params);
- long sizeLimit = validateSizeString(limitStr);
- long retentionTimeInSec;
- try {
- retentionTimeInSec =
RelativeTimeUtil.parseRelativeTimeInSeconds(retentionTimeStr);
- } catch (IllegalArgumentException exception) {
- throw new ParameterException(exception.getMessage());
- }
-
- final int retentionTimeInMin;
- if (retentionTimeInSec != -1) {
- retentionTimeInMin = (int)
TimeUnit.SECONDS.toMinutes(retentionTimeInSec);
- } else {
- retentionTimeInMin = -1;
- }
-
- final int retentionSizeInMB;
- if (sizeLimit != -1) {
- retentionSizeInMB = (int) (sizeLimit / (1024 * 1024));
- } else {
- retentionSizeInMB = -1;
- }
+ final int retentionTimeInMin = retentionTimeInSec != -1
+ ? (int) TimeUnit.SECONDS.toMinutes(retentionTimeInSec)
+ : retentionTimeInSec.intValue();
+ final int retentionSizeInMB = sizeLimit != -1
Review Comment:
True true 👍🏼, added to https://github.com/apache/pulsar/issues/21056
##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java:
##########
@@ -747,39 +743,27 @@ private class SetRetention extends CliCommand {
+ "For example, 100m, 3h, 2d, 5w. "
+ "If the time unit is not specified, the default unit
is seconds. For example, "
+ "-t 120 sets retention to 2 minutes. "
- + "0 means no retention and -1 means infinite time
retention.", required = true)
- private String retentionTimeStr;
+ + "0 means no retention and -1 means infinite time
retention.", required = true,
+ converter = TimeUnitToSecondsConverter.class,
+ validateValueWith = MinNegativeOneValidator.class)
+ private Long retentionTimeInSec;
@Parameter(names = { "--size", "-s" }, description = "Retention size
limit with optional size unit suffix. "
+ "For example, 4096, 10M, 16G, 3T. The size unit suffix
character can be k/K, m/M, g/G, or t/T. "
+ "If the size unit suffix is not specified, the default unit
is bytes. "
- + "0 or less than 1MB means no retention and -1 means infinite
size retention", required = true)
- private String limitStr;
+ + "0 or less than 1MB means no retention and -1 means infinite
size retention", required = true,
+ converter = ByteUnitIntegerConverter.class)
+ private Integer sizeLimit;
@Override
void run() throws PulsarAdminException {
String namespace = validateNamespace(params);
- long sizeLimit = validateSizeString(limitStr);
- long retentionTimeInSec;
- try {
- retentionTimeInSec =
RelativeTimeUtil.parseRelativeTimeInSeconds(retentionTimeStr);
- } catch (IllegalArgumentException exception) {
- throw new ParameterException(exception.getMessage());
- }
-
- final int retentionTimeInMin;
- if (retentionTimeInSec != -1) {
- retentionTimeInMin = (int)
TimeUnit.SECONDS.toMinutes(retentionTimeInSec);
- } else {
- retentionTimeInMin = -1;
- }
-
- final int retentionSizeInMB;
- if (sizeLimit != -1) {
- retentionSizeInMB = (int) (sizeLimit / (1024 * 1024));
- } else {
- retentionSizeInMB = -1;
- }
+ final int retentionTimeInMin = retentionTimeInSec != -1
+ ? (int) TimeUnit.SECONDS.toMinutes(retentionTimeInSec)
+ : retentionTimeInSec.intValue();
+ final int retentionSizeInMB = sizeLimit != -1
Review Comment:
True true 👍🏼, added to https://github.com/apache/pulsar/issues/21056
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]