nicoloboschi commented on code in PR #16251:
URL: https://github.com/apache/pulsar/pull/16251#discussion_r917677614


##########
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/PulsarAdminTool.java:
##########
@@ -43,121 +44,88 @@ public class PulsarAdminTool {
 
     private static int lastExitCode = Integer.MIN_VALUE;
 
-    protected final Map<String, Class<?>> commandMap;
-    private final JCommander jcommander;
+    protected Map<String, Class<?>> commandMap;
+    protected JCommander jcommander;
     protected final PulsarAdminBuilder adminBuilder;
+    protected RootParams rootParams;
 
-    @Parameter(names = { "--admin-url" }, description = "Admin Service URL to 
which to connect.")
-    String serviceUrl = null;
+    @Getter
+    public static class RootParams {
 
-    @Parameter(names = { "--auth-plugin" }, description = "Authentication 
plugin class name.")
-    String authPluginClassName = null;
+        @Parameter(names = { "--admin-url" }, description = "Admin Service URL 
to which to connect.")
+        String serviceUrl = null;
 
-    @Parameter(names = { "--request-timeout" }, description = "Request time 
out in seconds for "
-            + "the pulsar admin client for any request")
-    int requestTimeout = PulsarAdminImpl.DEFAULT_REQUEST_TIMEOUT_SECONDS;
+        @Parameter(names = { "--auth-plugin" }, description = "Authentication 
plugin class name.")
+        String authPluginClassName = null;
 
-    @Parameter(
-        names = { "--auth-params" },
-            description = "Authentication parameters, whose format is 
determined by the implementation "
-                    + "of method `configure` in authentication plugin class, 
for example \"key1:val1,key2:val2\" "
-                    + "or \"{\"key1\":\"val1\",\"key2\":\"val2\"}.")
-    String authParams = null;
+        @Parameter(names = { "--request-timeout" }, description = "Request 
time out in seconds for "
+                + "the pulsar admin client for any request")
+        int requestTimeout = PulsarAdminImpl.DEFAULT_REQUEST_TIMEOUT_SECONDS;
 
-    @Parameter(names = { "--tls-allow-insecure" }, description = "Allow TLS 
insecure connection")
-    Boolean tlsAllowInsecureConnection;
+        @Parameter(
+            names = { "--auth-params" },
+                description = "Authentication parameters, whose format is 
determined by the implementation "
+                        + "of method `configure` in authentication plugin 
class, for example \"key1:val1,key2:val2\" "
+                        + "or \"{\"key1\":\"val1\",\"key2\":\"val2\"}.")
+        String authParams = null;
 
-    @Parameter(names = { "--tls-trust-cert-path" }, description = "Allow TLS 
trust cert file path")
-    String tlsTrustCertsFilePath;
+        @Parameter(names = { "--tls-allow-insecure" }, description = "Allow 
TLS insecure connection")
+        Boolean tlsAllowInsecureConnection;
 
-    @Parameter(names = { "--tls-enable-hostname-verification" }, description = 
"Enable TLS common name verification")
-    Boolean tlsEnableHostnameVerification;
+        @Parameter(names = { "--tls-trust-cert-path" }, description = "Allow 
TLS trust cert file path")
+        String tlsTrustCertsFilePath;
 
-    @Parameter(names = { "-v", "--version" }, description = "Get version of 
pulsar admin client")
-    boolean version;
+        @Parameter(names = { "--tls-enable-hostname-verification" },
+                description = "Enable TLS common name verification")
+        Boolean tlsEnableHostnameVerification;
 
-    @Parameter(names = { "-h", "--help", }, help = true, description = "Show 
this help.")
-    boolean help;
+        @Parameter(names = { "-v", "--version" }, description = "Get version 
of pulsar admin client")
+        boolean version;
 
-    // for tls with keystore type config
-    boolean useKeyStoreTls;
-    String tlsTrustStoreType;
-    String tlsTrustStorePath;
-    String tlsTrustStorePassword;
+        @Parameter(names = { "-h", "--help", }, help = true, description = 
"Show this help.")
+        boolean help;
+    }
 
-    PulsarAdminTool(Properties properties) throws Exception {
+    public PulsarAdminTool(Properties properties) throws Exception {
+        rootParams = new RootParams();
         // fallback to previous-version serviceUrl property to maintain 
backward-compatibility
-        serviceUrl = isNotBlank(properties.getProperty("webServiceUrl"))
-                ? properties.getProperty("webServiceUrl")
-                : properties.getProperty("serviceUrl");
-        authPluginClassName = properties.getProperty("authPlugin");
-        authParams = properties.getProperty("authParams");
-        boolean tlsAllowInsecureConnection = this.tlsAllowInsecureConnection 
!= null ? this.tlsAllowInsecureConnection
+        initRootParamsFromProperties(properties);
+        adminBuilder = createAdminBuilder(properties);
+        initJCommander();
+    }
+
+    protected PulsarAdminBuilder createAdminBuilder(Properties properties) {
+        boolean useKeyStoreTls = Boolean
+                .parseBoolean(properties.getProperty("useKeyStoreTls", 
"false"));
+        String tlsTrustStoreType = properties.getProperty("tlsTrustStoreType", 
"JKS");
+        String tlsTrustStorePath = properties.getProperty("tlsTrustStorePath");
+        String tlsTrustStorePassword = 
properties.getProperty("tlsTrustStorePassword");
+        boolean tlsAllowInsecureConnection = 
this.rootParams.tlsAllowInsecureConnection != null
+                ? this.rootParams.tlsAllowInsecureConnection
                 : 
Boolean.parseBoolean(properties.getProperty("tlsAllowInsecureConnection", 
"false"));
 
-        boolean tlsEnableHostnameVerification = 
this.tlsEnableHostnameVerification != null
-                ? this.tlsEnableHostnameVerification
+        boolean tlsEnableHostnameVerification = 
this.rootParams.tlsEnableHostnameVerification != null
+                ? this.rootParams.tlsEnableHostnameVerification
                 : 
Boolean.parseBoolean(properties.getProperty("tlsEnableHostnameVerification", 
"false"));
-        final String tlsTrustCertsFilePath = 
isNotBlank(this.tlsTrustCertsFilePath)
-                ? this.tlsTrustCertsFilePath
+        final String tlsTrustCertsFilePath = 
isNotBlank(this.rootParams.tlsTrustCertsFilePath)
+                ? this.rootParams.tlsTrustCertsFilePath
                 : properties.getProperty("tlsTrustCertsFilePath");
 
-        this.useKeyStoreTls = Boolean
-                .parseBoolean(properties.getProperty("useKeyStoreTls", 
"false"));
-        this.tlsTrustStoreType = properties.getProperty("tlsTrustStoreType", 
"JKS");
-        this.tlsTrustStorePath = properties.getProperty("tlsTrustStorePath");
-        this.tlsTrustStorePassword = 
properties.getProperty("tlsTrustStorePassword");
-
-        adminBuilder = 
PulsarAdmin.builder().allowTlsInsecureConnection(tlsAllowInsecureConnection)
+        return 
PulsarAdmin.builder().allowTlsInsecureConnection(tlsAllowInsecureConnection)
                 .enableTlsHostnameVerification(tlsEnableHostnameVerification)
                 .tlsTrustCertsFilePath(tlsTrustCertsFilePath)
                 .useKeyStoreTls(useKeyStoreTls)
                 .tlsTrustStoreType(tlsTrustStoreType)
                 .tlsTrustStorePath(tlsTrustStorePath)
                 .tlsTrustStorePassword(tlsTrustStorePassword);
+    }
 
-        jcommander = new JCommander();
-        jcommander.setProgramName("pulsar-admin");
-        jcommander.addObject(this);
-
-        commandMap = new HashMap<>();
-        commandMap.put("clusters", CmdClusters.class);
-        commandMap.put("ns-isolation-policy", 
CmdNamespaceIsolationPolicy.class);
-        commandMap.put("brokers", CmdBrokers.class);
-        commandMap.put("broker-stats", CmdBrokerStats.class);
-        commandMap.put("tenants", CmdTenants.class);
-        commandMap.put("resourcegroups", CmdResourceGroups.class);
-        commandMap.put("properties", CmdTenants.CmdProperties.class); // 
deprecated, doesn't show in usage()
-        commandMap.put("namespaces", CmdNamespaces.class);
-        commandMap.put("topics", CmdTopics.class);
-        commandMap.put("topicPolicies", CmdTopicPolicies.class);
-        commandMap.put("schemas", CmdSchemas.class);
-        commandMap.put("bookies", CmdBookies.class);
-
-        // Hidden deprecated "persistent" and "non-persistent" subcommands
-        commandMap.put("persistent", CmdPersistentTopics.class);
-        commandMap.put("non-persistent", CmdNonPersistentTopics.class);
-
-
-        commandMap.put("resource-quotas", CmdResourceQuotas.class);
-        // pulsar-proxy cli
-        commandMap.put("proxy-stats", CmdProxyStats.class);
-
-        commandMap.put("functions", CmdFunctions.class);
-        commandMap.put("functions-worker", CmdFunctionWorker.class);
-        commandMap.put("sources", CmdSources.class);
-        commandMap.put("sinks", CmdSinks.class);
-
-        // Automatically generate documents for pulsar-admin
-        commandMap.put("documents", CmdGenerateDocument.class);
-
-        // To remain backwards compatibility for "source" and "sink" commands
-        // TODO eventually remove this
-        commandMap.put("source", CmdSources.class);
-        commandMap.put("sink", CmdSinks.class);
-
-        commandMap.put("packages", CmdPackages.class);
-        commandMap.put("transactions", CmdTransactions.class);
+    protected void initRootParamsFromProperties(Properties properties) {
+        rootParams.serviceUrl = 
isNotBlank(properties.getProperty("webServiceUrl"))
+                ? properties.getProperty("webServiceUrl")
+                : properties.getProperty("serviceUrl");
+        rootParams.authPluginClassName = properties.getProperty("authPlugin");
+        rootParams.authParams = properties.getProperty("authParams");

Review Comment:
   yes they are added passed to jcommand as object



-- 
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]

Reply via email to