You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2022/12/05 07:52:22 UTC
[pulsar] branch master updated: [improve][cli] Better relative path arguments (#18740)
This is an automated email from the ASF dual-hosted git repository.
zixuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new ecf83d06082 [improve][cli] Better relative path arguments (#18740)
ecf83d06082 is described below
commit ecf83d06082fcdb939ae3faaf8ce3f68c364a557
Author: tison <wa...@gmail.com>
AuthorDate: Mon Dec 5 15:52:10 2022 +0800
[improve][cli] Better relative path arguments (#18740)
Signed-off-by: tison <wa...@gmail.com>
---
.../org/apache/pulsar/PulsarBrokerStarter.java | 25 +++++++++++----------
.../java/org/apache/pulsar/PulsarStandalone.java | 8 +++----
.../apache/pulsar/compaction/CompactorTool.java | 26 +++++++++++-----------
.../org/apache/pulsar/functions/LocalRunner.java | 12 +++++-----
4 files changed, 37 insertions(+), 34 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
index cfbd4ed3071..92fc8c5c9ac 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java
@@ -31,7 +31,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
@@ -79,8 +79,7 @@ public class PulsarBrokerStarter {
@Parameters(commandDescription = "Options")
private static class StarterArguments {
@Parameter(names = {"-c", "--broker-conf"}, description = "Configuration file for Broker")
- private String brokerConfigFile =
- Paths.get("").toAbsolutePath().normalize().toString() + "/conf/broker.conf";
+ private String brokerConfigFile = "conf/broker.conf";
@Parameter(names = {"-rb", "--run-bookie"}, description = "Run Bookie together with Broker")
private boolean runBookie = false;
@@ -90,15 +89,13 @@ public class PulsarBrokerStarter {
private boolean runBookieAutoRecovery = false;
@Parameter(names = {"-bc", "--bookie-conf"}, description = "Configuration file for Bookie")
- private String bookieConfigFile =
- Paths.get("").toAbsolutePath().normalize().toString() + "/conf/bookkeeper.conf";
+ private String bookieConfigFile = "conf/bookkeeper.conf";
@Parameter(names = {"-rfw", "--run-functions-worker"}, description = "Run functions worker with Broker")
private boolean runFunctionsWorker = false;
@Parameter(names = {"-fwc", "--functions-worker-conf"}, description = "Configuration file for Functions Worker")
- private String fnWorkerConfigFile =
- Paths.get("").toAbsolutePath().normalize().toString() + "/conf/functions_worker.yml";
+ private String fnWorkerConfigFile = "conf/functions_worker.yml";
@Parameter(names = {"-h", "--help"}, description = "Show this help message")
private boolean help = false;
@@ -167,7 +164,9 @@ public class PulsarBrokerStarter {
jcommander.usage();
throw new IllegalArgumentException("Need to specify a configuration file for broker");
} else {
- brokerConfig = loadConfig(starterArguments.brokerConfigFile);
+ final String filepath = Path.of(starterArguments.brokerConfigFile)
+ .toAbsolutePath().normalize().toString();
+ brokerConfig = loadConfig(filepath);
}
int maxFrameSize = brokerConfig.getMaxMessageSize() + Commands.MESSAGE_SIZE_FRAME_PADDING;
@@ -190,9 +189,9 @@ public class PulsarBrokerStarter {
// init functions worker
if (starterArguments.runFunctionsWorker || brokerConfig.isFunctionsWorkerEnabled()) {
- workerConfig = PulsarService.initializeWorkerConfigFromBrokerConfig(
- brokerConfig, starterArguments.fnWorkerConfigFile
- );
+ final String filepath = Path.of(starterArguments.fnWorkerConfigFile)
+ .toAbsolutePath().normalize().toString();
+ workerConfig = PulsarService.initializeWorkerConfigFromBrokerConfig(brokerConfig, filepath);
functionsWorkerService = WorkerServiceLoader.load(workerConfig);
} else {
workerConfig = null;
@@ -231,7 +230,9 @@ public class PulsarBrokerStarter {
if (starterArguments.runBookie || starterArguments.runBookieAutoRecovery) {
checkState(isNotBlank(starterArguments.bookieConfigFile),
"No configuration file for Bookie");
- bookieConfig = readBookieConfFile(starterArguments.bookieConfigFile);
+ final String filepath = Path.of(starterArguments.bookieConfigFile)
+ .toAbsolutePath().normalize().toString();
+ bookieConfig = readBookieConfFile(filepath);
Class<? extends StatsProvider> statsProviderClass = bookieConfig.getStatsProviderClass();
bookieStatsProvider = ReflectionUtils.newInstance(statsProviderClass);
} else {
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
index 5aead455357..4429a081d41 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
@@ -25,6 +25,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import io.netty.util.internal.PlatformDependent;
import java.io.File;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
@@ -251,8 +252,7 @@ public class PulsarStandalone implements AutoCloseable {
private boolean noFunctionsWorker = false;
@Parameter(names = {"-fwc", "--functions-worker-conf"}, description = "Configuration file for Functions Worker")
- private String fnWorkerConfigFile =
- Paths.get("").toAbsolutePath().normalize().toString() + "/conf/functions_worker.yml";
+ private String fnWorkerConfigFile = "conf/functions_worker.yml";
@Parameter(names = {"-nss", "--no-stream-storage"}, description = "Disable stream storage")
private boolean noStreamStorage = false;
@@ -305,8 +305,8 @@ public class PulsarStandalone implements AutoCloseable {
// initialize the functions worker
if (!this.isNoFunctionsWorker()) {
- workerConfig = PulsarService.initializeWorkerConfigFromBrokerConfig(
- config, this.getFnWorkerConfigFile());
+ final String filepath = Path.of(getFnWorkerConfigFile()).toAbsolutePath().normalize().toString();
+ workerConfig = PulsarService.initializeWorkerConfigFromBrokerConfig(config, filepath);
if (usingNewDefaultsPIP117) {
workerConfig.setStateStorageProviderImplementation(
PulsarMetadataStateStoreProviderImpl.class.getName());
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java
index bbd93205811..c359823549f 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java
@@ -25,7 +25,7 @@ import com.beust.jcommander.Parameter;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.channel.EventLoopGroup;
import io.netty.util.concurrent.DefaultThreadFactory;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -53,7 +53,7 @@ public class CompactorTool {
private static class Arguments {
@Parameter(names = {"-c", "--broker-conf"}, description = "Configuration file for Broker")
- private String brokerConfigFile = Paths.get("").toAbsolutePath().normalize().toString() + "/conf/broker.conf";
+ private String brokerConfigFile = "conf/broker.conf";
@Parameter(names = {"-t", "--topic"}, description = "Topic to compact", required = true)
private String topic;
@@ -124,24 +124,24 @@ public class CompactorTool {
}
// init broker config
- ServiceConfiguration brokerConfig;
if (isBlank(arguments.brokerConfigFile)) {
jcommander.usage();
throw new IllegalArgumentException("Need to specify a configuration file for broker");
- } else {
- log.info(String.format("read configuration file %s", arguments.brokerConfigFile));
- brokerConfig = PulsarConfigurationLoader.create(
- arguments.brokerConfigFile, ServiceConfiguration.class);
}
+ final String filepath = Path.of(arguments.brokerConfigFile).toAbsolutePath().normalize().toString();
+ log.info(String.format("read configuration file %s", filepath));
+ final ServiceConfiguration brokerConfig =
+ PulsarConfigurationLoader.create(filepath, ServiceConfiguration.class);
+
if (isBlank(brokerConfig.getMetadataStoreUrl())) {
- throw new IllegalArgumentException(
- String.format("Need to specify `metadataStoreUrl` or `zookeeperServers` in configuration file \n"
- + "or specify configuration file path from command line.\n"
- + "now configuration file path is=[%s]\n",
- arguments.brokerConfigFile)
- );
+ final String message = String.format("""
+ Need to specify `metadataStoreUrl` or `zookeeperServers` in configuration file
+ or specify configuration file path from command line.
+ now configuration file path is=[%s]
+ """, filepath);
+ throw new IllegalArgumentException(message);
}
@Cleanup(value = "shutdownNow")
diff --git a/pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java b/pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
index 370dee271c6..0e5ac310b57 100644
--- a/pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
+++ b/pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java
@@ -34,7 +34,7 @@ import java.io.UncheckedIOException;
import java.net.InetSocketAddress;
import java.net.URISyntaxException;
import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -267,11 +267,13 @@ public class LocalRunner implements AutoCloseable {
}
private static String getPulsarDirectory(String directory) {
- String pulsarHome = System.getenv("PULSAR_HOME");
- if (pulsarHome == null) {
- pulsarHome = Paths.get("").toAbsolutePath().toString();
+ final Path directoryPath;
+ if (System.getenv("PULSAR_HOME") != null) {
+ directoryPath = Path.of(System.getenv("PULSAR_HOME"), directory);
+ } else {
+ directoryPath = Path.of(directory);
}
- return Paths.get(pulsarHome, directory).toString();
+ return directoryPath.toAbsolutePath().toString();
}
private static File createNarExtractionTempDirectory() {