jai1 closed pull request #1492: Fixed InvocationTargetException in pulsar-admin
URL: https://github.com/apache/incubator-pulsar/pull/1492
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/PulsarAdmin.java
 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/PulsarAdmin.java
index 5a5683065..7bb23b97c 100644
--- 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/PulsarAdmin.java
+++ 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/PulsarAdmin.java
@@ -29,6 +29,7 @@
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.WebTarget;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.pulsar.client.admin.internal.BrokerStatsImpl;
 import org.apache.pulsar.client.admin.internal.BrokersImpl;
 import org.apache.pulsar.client.admin.internal.ClustersImpl;
@@ -71,7 +72,7 @@
     private final PersistentTopics persistentTopics;
     private final NonPersistentTopics nonPersistentTopics;
     private final ResourceQuotas resourceQuotas;
-
+    private final ClientConfigurationData clientConfigData;
     private final Client client;
     private final String serviceUrl;
     private final Lookup lookups;
@@ -103,8 +104,9 @@ public static PulsarAdminBuilder builder() {
         return new PulsarAdminBuilderImpl();
     }
 
-    public PulsarAdmin(String serviceUrl, ClientConfigurationData 
pulsarConfig) throws PulsarClientException {
-        this.auth = pulsarConfig != null ? pulsarConfig.getAuthentication() : 
new AuthenticationDisabled();
+    public PulsarAdmin(String serviceUrl, ClientConfigurationData 
clientConfigData) throws PulsarClientException {
+        this.clientConfigData = clientConfigData;
+        this.auth = clientConfigData != null ? 
clientConfigData.getAuthentication() : new AuthenticationDisabled();
         LOG.debug("created: serviceUrl={}, authMethodName={}", serviceUrl,
                 auth != null ? auth.getAuthMethodName() : null);
 
@@ -120,22 +122,24 @@ public PulsarAdmin(String serviceUrl, 
ClientConfigurationData pulsarConfig) thro
         ClientBuilder clientBuilder = 
ClientBuilder.newBuilder().withConfig(httpConfig)
                 
.register(JacksonConfigurator.class).register(JacksonFeature.class);
 
-        boolean useTls = pulsarConfig.getServiceUrl().startsWith("https://";);
+        boolean useTls = false;
 
-        if (pulsarConfig != null && useTls) {
+        if (clientConfigData != null && 
StringUtils.isNotBlank(clientConfigData.getServiceUrl())
+                && clientConfigData.getServiceUrl().startsWith("https://";)) {
+            useTls = true;
             try {
                 SSLContext sslCtx = null;
 
                 X509Certificate trustCertificates[] = SecurityUtility
-                        
.loadCertificatesFromPemFile(pulsarConfig.getTlsTrustCertsFilePath());
+                        
.loadCertificatesFromPemFile(clientConfigData.getTlsTrustCertsFilePath());
 
                 // Set private key and certificate if available
                 AuthenticationDataProvider authData = auth.getAuthData();
                 if (authData.hasDataForTls()) {
-                    sslCtx = 
SecurityUtility.createSslContext(pulsarConfig.isTlsAllowInsecureConnection(),
+                    sslCtx = 
SecurityUtility.createSslContext(clientConfigData.isTlsAllowInsecureConnection(),
                             trustCertificates, authData.getTlsCertificates(), 
authData.getTlsPrivateKey());
                 } else {
-                    sslCtx = 
SecurityUtility.createSslContext(pulsarConfig.isTlsAllowInsecureConnection(),
+                    sslCtx = 
SecurityUtility.createSslContext(clientConfigData.isTlsAllowInsecureConnection(),
                             trustCertificates);
                 }
 
@@ -313,6 +317,13 @@ public String getServiceUrl() {
         return serviceUrl;
     }
 
+    /**
+     * @return the client Configuration Data that is being used
+     */
+    public ClientConfigurationData getClientConfigData() {
+        return clientConfigData;
+    }
+
     /**
      * Close the Pulsar admin client to release all the resources
      */
diff --git 
a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/CmdFunctionsTest.java
 
b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/CmdFunctionsTest.java
index 9fa0d7c0d..80425f1a5 100644
--- 
a/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/CmdFunctionsTest.java
+++ 
b/pulsar-client-tools-test/src/test/java/org/apache/pulsar/admin/cli/CmdFunctionsTest.java
@@ -104,7 +104,7 @@ public void setup() throws Exception {
         this.functions = mock(Functions.class);
         when(admin.functions()).thenReturn(functions);
         when(admin.getServiceUrl()).thenReturn("http://localhost:1234";);
-        when(admin.getClientConf()).thenReturn(new ClientConfigurationData());
+        when(admin.getClientConfigData()).thenReturn(new 
ClientConfigurationData());
         this.cmd = new CmdFunctions(admin);
 
         // mock reflections
diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
index eb7fed74a..0bb409814 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
@@ -45,6 +45,7 @@
 import org.apache.bookkeeper.clients.utils.NetUtils;
 import org.apache.pulsar.client.admin.PulsarAdmin;
 import org.apache.pulsar.client.admin.PulsarAdminWithFunctions;
+import org.apache.pulsar.client.api.PulsarClientException;
 import org.apache.pulsar.common.naming.TopicName;
 import org.apache.pulsar.functions.api.Function;
 import org.apache.pulsar.functions.api.utils.DefaultSerDe;
@@ -456,7 +457,7 @@ void runCmd() throws Exception {
                 throw new RuntimeException("Missing arguments");
             }
 
-            String serviceUrl = ((PulsarAdminWithFunctions) 
admin).getClientConf().getServiceUrl();
+            String serviceUrl = admin.getServiceUrl();
             if (brokerServiceUrl != null) {
                 serviceUrl = brokerServiceUrl;
             }
@@ -634,9 +635,13 @@ void runCmd() throws Exception {
         }
     }
 
-    public CmdFunctions(PulsarAdmin admin) {
+    public CmdFunctions(PulsarAdmin admin) throws PulsarClientException {
         super("functions", admin);
-        this.fnAdmin = (PulsarAdminWithFunctions) admin;
+        if (admin instanceof PulsarAdminWithFunctions) {
+            this.fnAdmin = (PulsarAdminWithFunctions) admin;
+        } else {
+            this.fnAdmin = new PulsarAdminWithFunctions(admin.getServiceUrl(), 
admin.getClientConfigData());
+        }
         localRunner = new LocalRunner();
         creater = new CreateFunction();
         deleter = new DeleteFunction();
diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/admin/PulsarAdminWithFunctions.java
 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/admin/PulsarAdminWithFunctions.java
index 8ef8a6d94..aa1758561 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/client/admin/PulsarAdminWithFunctions.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/client/admin/PulsarAdminWithFunctions.java
@@ -19,11 +19,9 @@
 package org.apache.pulsar.client.admin;
 
 import org.apache.pulsar.client.admin.internal.FunctionsImpl;
-import org.apache.pulsar.client.admin.internal.PulsarAdminBuilderImpl;
 import org.apache.pulsar.client.api.PulsarClientException;
 import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
 
-
 /**
  * Pulsar client admin client with functions support.
  */
@@ -32,23 +30,13 @@
     private final Functions functions;
     private final ClientConfigurationData clientConf;
 
-    /**
-     * Creates a builder to construct an instance of {@link 
PulsarAdminWithFunctions}.
-     */
-    public static PulsarAdminBuilder builder() {
-        return new PulsarAdminBuilderImpl();
-    }
-
-    PulsarAdminWithFunctions(String serviceUrl, ClientConfigurationData 
pulsarConfig) throws PulsarClientException {
+    public PulsarAdminWithFunctions(String serviceUrl, ClientConfigurationData 
pulsarConfig)
+            throws PulsarClientException {
         super(serviceUrl, pulsarConfig);
         this.functions = new FunctionsImpl(root, auth);
         this.clientConf = pulsarConfig;
     }
 
-    public ClientConfigurationData getClientConf() {
-        return clientConf;
-    }
-
     /**
      * @return the function management object
      */


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to