Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5f4b14f
Add new module
JooHyukKim Jul 11, 2023
4945b0e
Fix maven
JooHyukKim Jul 11, 2023
ceb3fc4
Fix compile error wrt validation utils
JooHyukKim Jul 11, 2023
45b2120
Add apache commons dep
JooHyukKim Jul 11, 2023
963a7e3
Add test for ValueValidationUtilsTest
JooHyukKim Jul 11, 2023
cbdda80
Refactor test methods
JooHyukKim Jul 11, 2023
346a361
Fix tests and compile errors
JooHyukKim Jul 11, 2023
25a93ab
Fix checkstyle
JooHyukKim Jul 11, 2023
b4e2971
Fix build failure wrt findBugsFIlter
JooHyukKim Jul 11, 2023
91e5caf
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 12, 2023
848fe00
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 15, 2023
e28e104
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 19, 2023
59a6bed
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 20, 2023
1634aca
Remove protobuf dep
JooHyukKim Jul 21, 2023
487f3ef
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 21, 2023
293f358
Rephrase errror message in RelativeTimeUtil
JooHyukKim Jul 21, 2023
d9d2194
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Jul 22, 2023
238b590
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Aug 4, 2023
f0f9f9c
Remove whitespace
JooHyukKim Aug 4, 2023
a9eb0d5
Add more test covreatge and reformat
JooHyukKim Aug 5, 2023
44dc72f
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Aug 12, 2023
e0ad3bf
Remove unncessary comment
JooHyukKim Aug 12, 2023
b4b0ba7
Merge remote-tracking branch 'upstream/master' into pip280-separate-m…
JooHyukKim Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,7 @@ flexible messaging model and an intuitive client API.</description>
<module>pulsar-common</module>
<module>pulsar-broker-common</module>
<module>pulsar-broker</module>
<module>pulsar-cli-utils</module>
<module>pulsar-client-api</module>
<module>pulsar-client</module>
<module>pulsar-client-shaded</module>
Expand Down
149 changes: 149 additions & 0 deletions pulsar-cli-utils/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar</artifactId>
<version>3.1.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>pulsar-cli-utils</artifactId>
<name>Pulsar CLI Utils</name>
<description>Isolated CLI utility module</description>

<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${pulsar.client.compiler.release}</release>
</configuration>
</plugin>

<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<configuration>
<failOnViolations>true</failOnViolations>
<javaVersion>8</javaVersion>
</configuration>
<executions>
<execution>
<id>modernizer</id>
<phase>verify</phase>
<goals>
<goal>modernizer</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<id>git-info</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>false</skip>
<useNativeGit>true</useNativeGit>
<prefix>git</prefix>
<verbose>false</verbose>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<format>properties</format>
<gitDescribe>
<skip>true</skip>
</gitDescribe>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filtering-java-templates</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeFilterFile>${basedir}/src/main/resources/findbugsExclude.xml</excludeFilterFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.cli;

import com.beust.jcommander.ParameterException;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

@UtilityClass
public class ValueValidationUtil {

public static void maxValueCheck(String paramName, long value, long maxValue) {
if (value > maxValue) {
throw new ParameterException(paramName + " cannot be bigger than <" + maxValue + ">!");
}
}

public static void positiveCheck(String paramName, long value) {
if (value <= 0) {
throw new ParameterException(paramName + " cannot be less than or equal to <0>!");
}
}

public static void positiveCheck(String paramName, int value) {
if (value <= 0) {
throw new ParameterException(paramName + " cannot be less than or equal to <0>!");
}
}

public static void emptyCheck(String paramName, String value) {
if (StringUtils.isEmpty(value)) {
throw new ParameterException("The value of " + paramName + " can't be empty");
}
}

public static void minValueCheck(String name, Long value, long min) {
if (value < min) {
throw new ParameterException(name + " cannot be less than <" + min + ">!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.cli.converters;

import static org.apache.pulsar.cli.ValueValidationUtil.emptyCheck;
import static org.apache.pulsar.cli.converters.ByteUnitUtil.validateSizeString;
import com.beust.jcommander.converters.BaseConverter;

public class ByteUnitIntegerConverter extends BaseConverter<Integer> {

public ByteUnitIntegerConverter(String optionName) {
super(optionName);
}

@Override
public Integer convert(String argStr) {
return parseBytes(argStr).intValue();
}

Long parseBytes(String argStr) {
emptyCheck(getOptionName(), argStr);
long valueInBytes = validateSizeString(argStr);
return valueInBytes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.cli.converters;

import static org.apache.pulsar.cli.ValueValidationUtil.emptyCheck;
import com.beust.jcommander.converters.BaseConverter;

public class ByteUnitToLongConverter extends BaseConverter<Long> {

public ByteUnitToLongConverter(String optionName) {
super(optionName);
}

@Override
public Long convert(String argStr) {
return parseBytes(argStr);
}

Long parseBytes(String argStr) {
emptyCheck(getOptionName(), argStr);
return ByteUnitUtil.validateSizeString(argStr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.cli.converters;

import com.beust.jcommander.ParameterException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import lombok.experimental.UtilityClass;

@UtilityClass
class ByteUnitUtil {

private static Set<Character> sizeUnit = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList('k', 'K', 'm', 'M', 'g', 'G', 't', 'T')));

static long validateSizeString(String byteStr) {
if (byteStr.isEmpty()) {
throw new IllegalArgumentException("byte string cannot be empty");
}

char last = byteStr.charAt(byteStr.length() - 1);
String subStr = byteStr.substring(0, byteStr.length() - 1);
long size;
try {
size = sizeUnit.contains(last)
? Long.parseLong(subStr)
: Long.parseLong(byteStr);
} catch (IllegalArgumentException e) {
throw new ParameterException(String.format("Invalid size '%s'. Valid formats are: %s",
byteStr, "(4096, 100K, 10M, 16G, 2T)"));
}
switch (last) {
case 'k':
case 'K':
return size * 1024;

case 'm':
case 'M':
return size * 1024 * 1024;

case 'g':
case 'G':
return size * 1024 * 1024 * 1024;

case 't':
case 'T':
return size * 1024 * 1024 * 1024 * 1024;

default:
return size;
}
}
}
Loading