Skip to content

Commit

Permalink
[improve][cli] pulsar cli: use return code 1 for general error (#18946)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgier authored Dec 17, 2022
1 parent b9446aa commit 002fa49
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected void initRootParamsFromProperties(Properties properties) {
} catch (IllegalArgumentException e) {
System.out.println("Incorrect proxyProtocol name '" + proxyProtocolString + "'");
e.printStackTrace();
System.exit(-1);
System.exit(1);
}
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ private void updateConfig() throws UnsupportedAuthenticationException {
if (isNotBlank(rootParams.proxyServiceURL)) {
if (rootParams.proxyProtocol == null) {
System.out.println("proxy-protocol must be provided with proxy-url");
System.exit(-1);
System.exit(1);
}
clientBuilder.proxyServiceUrl(rootParams.proxyServiceURL, rootParams.proxyProtocol);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public int run(String[] args) {
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: pulsar-client CONF_FILE_PATH [options] [command] [command options]");
System.exit(-1);
System.exit(1);
}
String configFile = args[0];
Properties properties = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static void main(String[] args) throws Exception {
}
} catch (Exception e) {
commander.usage();
Runtime.getRuntime().exit(-1);
Runtime.getRuntime().exit(1);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String toString() {
}, connectRetryPolicy, rateLimiter, createClientStats);
} catch (Exception e) {
log.error("Gave up reconnecting to ZooKeeper : ", e);
Runtime.getRuntime().exit(-1);
Runtime.getRuntime().exit(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public ProxyServiceStarter(String[] args) throws Exception {
}
} catch (Exception e) {
jcommander.usage();
System.exit(-1);
System.exit(1);
}

// load config file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ public Arguments loadArguments(String[] args) {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (isBlank(arguments.authPluginClassName) && !isBlank(arguments.deprecatedAuthPluginClassName)) {
Expand All @@ -161,7 +161,7 @@ public Arguments loadArguments(String[] args) {
if (arguments.topics.size() != 1) {
System.err.println("Only one topic name is allowed");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.confFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
final ZooKeeper zkClient = new ZooKeeper(arguments.connectString, ZOOKEEPER_TIMEOUT_MILLIS, null);
final BrokerMonitor monitor = new BrokerMonitor(zkClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

Map<String, Class<?>> cmdClassMap = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
PerfClientUtils.printJVMInformation(log);
(new LoadSimulationClient(mainArguments)).run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public static void main(String[] args) throws Exception {
} catch (Exception ex) {
System.out.println(ex.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
(new LoadSimulationController(arguments)).run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.metadataStoreUrl == null && arguments.zookeeperServers == null) {
Expand Down Expand Up @@ -280,7 +280,7 @@ public void addComplete(Position position, ByteBuf entryData, Object ctx) {
@Override
public void addFailed(ManagedLedgerException exception, Object ctx) {
log.warn("Write error on message", exception);
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void fillArgumentsFromProperties() {
} catch (IllegalArgumentException e) {
System.out.println("Incorrect proxyProtocol name '" + proxyProtocolString + "'");
e.printStackTrace();
exit(-1);
exit(1);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (isBlank(arguments.authPluginClassName) && !isBlank(arguments.deprecatedAuthPluginClassName)) {
Expand All @@ -228,7 +228,7 @@ public static void main(String[] args) throws Exception {
System.out.printf("invalid option: '%s'\nTo use a topic with the name '%s', "
+ "please use a fully qualified topic name\n", arg, arg);
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}

Expand All @@ -244,14 +244,14 @@ public static void main(String[] args) throws Exception {
} else {
System.out.println("The size of topics list should be equal to --num-topics");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}

if (arguments.subscriptionType == SubscriptionType.Exclusive && arguments.numConsumers > 1) {
System.out.println("Only one consumer is allowed when subscriptionType is Exclusive");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.subscriptions != null && arguments.subscriptions.size() != arguments.numSubscriptions) {
Expand All @@ -268,7 +268,7 @@ public static void main(String[] args) throws Exception {
} else {
System.out.println("The size of subscriptions list should be equal to --num-subscriptions");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}
arguments.fillArgumentsFromProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (isBlank(arguments.authPluginClassName) && !isBlank(arguments.deprecatedAuthPluginClassName)) {
Expand All @@ -297,7 +297,7 @@ public static void main(String[] args) throws Exception {
System.out.printf("invalid option: '%s'\nTo use a topic with the name '%s', "
+ "please use a fully qualified topic name\n", arg, arg);
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}

Expand All @@ -313,7 +313,7 @@ public static void main(String[] args) throws Exception {
} else {
System.out.println("The size of topics list should be equal to --num-topic");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}

Expand Down Expand Up @@ -379,7 +379,7 @@ public static void main(String[] args) throws Exception {
log.error("Topic {} already exists but it has a wrong number of partitions: {}, "
+ "expecting {}",
topic, partitionedTopicMetadata.partitions, arguments.partitions);
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}
}
Expand Down Expand Up @@ -692,7 +692,7 @@ private static void runProducer(int producerId,
log.warn("Write message error with exception", ex);
messagesFailed.increment();
if (arguments.exitOnFailure) {
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
return null;
});
Expand Down Expand Up @@ -753,7 +753,7 @@ private static void runProducer(int producerId,
if (null != client) {
try {
client.close();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
} catch (PulsarClientException e) {
log.error("Failed to close test client", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ public static void main(String[] args) throws Exception {
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

for (String arg : arguments.topic) {
if (arg.startsWith("-")) {
System.out.printf("invalid option: '%s'\nTo use a topic with the name '%s', "
+ "please use a fully qualified topic name\n", arg, arg);
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}

Expand All @@ -143,7 +143,7 @@ public static void main(String[] args) throws Exception {
} else {
System.out.println("The size of topics list should be equal to --num-topics");
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}
arguments.fillArgumentsFromProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ public static void main(String[] args)
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}

if (arguments.help) {
jc.usage();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
arguments.fillArgumentsFromProperties();

Expand Down Expand Up @@ -235,7 +235,7 @@ public static void main(String[] args)
log.error(
"Topic {} already exists but it has a wrong number of partitions: {}, expecting {}",
topic, partitionedTopicMetadata.partitions, arguments.partitions);
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ public static void main(String[] args)
} catch (Exception e) {
log.error("Failed to build Producer/Consumer with exception : ", e);
executorService.shutdownNow();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
//The while loop has no break, and finally ends the execution through the shutdownNow of
//the executorService
Expand Down Expand Up @@ -330,7 +330,7 @@ public static void main(String[] args)
} catch (PulsarClientException e) {
log.error("Receive message failed", e);
executorService.shutdownNow();
PerfClientUtils.exit(-1);
PerfClientUtils.exit(1);
}
long receiveTime = System.nanoTime();
if (!arguments.isDisableTransaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ public void fillArgumentsFromProperties(Properties prop) {
args.confFile = "./src/test/resources/performance_client3.conf";
PerfClientUtils.setExitProcedure(code -> {
calledVar2.set(true);
Assert.assertNotNull(code);
if (code != -1) {
fail("Incorrect exit code");
}
Assert.assertEquals(code, 1, "Incorrect exit code");
});

args.confFile = "./src/test/resources/performance_client3.conf";
Expand Down

0 comments on commit 002fa49

Please sign in to comment.