From de24aaf11ce61f8af28bb1dd70c099a8e43d0f08 Mon Sep 17 00:00:00 2001 From: hrsakai Date: Wed, 9 Aug 2017 15:28:04 +0900 Subject: [PATCH] support tls in performance tool (#662) --- .../testclient/PerformanceConsumer.java | 21 ++++++++++++++++++- .../testclient/PerformanceProducer.java | 19 +++++++++++++++++ .../pulsar/testclient/PerformanceReader.java | 21 ++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceConsumer.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceConsumer.java index f982622fd34..8d8ecc23637 100644 --- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceConsumer.java +++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceConsumer.java @@ -18,6 +18,7 @@ */ package org.apache.pulsar.testclient; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.FileInputStream; @@ -100,6 +101,14 @@ public class PerformanceConsumer { @Parameter(names = { "--auth_params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"") public String authParams; + + @Parameter(names = { + "--use-tls" }, description = "Use TLS encryption on the connection") + public boolean useTls; + + @Parameter(names = { + "--trust-cert-file" }, description = "Path for the trusted TLS certificate file") + public String tlsTrustCertsFilePath = ""; } public static void main(String[] args) throws Exception { @@ -150,6 +159,14 @@ public class PerformanceConsumer { if (arguments.authParams == null) { arguments.authParams = prop.getProperty("authParams", null); } + + if (arguments.useTls == false) { + arguments.useTls = Boolean.parseBoolean(prop.getProperty("useTls")); + } + + if (isBlank(arguments.tlsTrustCertsFilePath)) { + arguments.tlsTrustCertsFilePath = prop.getProperty("tlsTrustCertsFilePath", ""); + } } // Dump config variables @@ -181,6 +198,8 @@ public class PerformanceConsumer { if (isNotBlank(arguments.authPluginClassName)) { clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); } + clientConf.setUseTls(arguments.useTls); + clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf); List> futures = Lists.newArrayList(); @@ -235,4 +254,4 @@ public class PerformanceConsumer { } private static final Logger log = LoggerFactory.getLogger(PerformanceConsumer.class); -} \ No newline at end of file +} diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java index f20fa52834f..8de85bf1a10 100644 --- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java +++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceProducer.java @@ -19,6 +19,7 @@ package org.apache.pulsar.testclient; import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.FileInputStream; @@ -132,6 +133,14 @@ public class PerformanceProducer { @Parameter(names = { "-time", "--test-duration" }, description = "Test duration in secs. If 0, it will keep publishing") public long testTime = 0; + + @Parameter(names = { + "--use-tls" }, description = "Use TLS encryption on the connection") + public boolean useTls; + + @Parameter(names = { + "--trust-cert-file" }, description = "Path for the trusted TLS certificate file") + public String tlsTrustCertsFilePath = ""; } public static void main(String[] args) throws Exception { @@ -182,6 +191,14 @@ public class PerformanceProducer { if (arguments.authParams == null) { arguments.authParams = prop.getProperty("authParams", null); } + + if (arguments.useTls == false) { + arguments.useTls = Boolean.parseBoolean(prop.getProperty("useTls")); + } + + if (isBlank(arguments.tlsTrustCertsFilePath)) { + arguments.tlsTrustCertsFilePath = prop.getProperty("tlsTrustCertsFilePath", ""); + } } arguments.testTime = TimeUnit.SECONDS.toMillis(arguments.testTime); @@ -210,6 +227,8 @@ public class PerformanceProducer { if (isNotBlank(arguments.authPluginClassName)) { clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); } + clientConf.setUseTls(arguments.useTls); + clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); PulsarClient client = new PulsarClientImpl(arguments.serviceURL, clientConf); diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceReader.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceReader.java index f3c42f9cdb7..9d158926867 100644 --- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceReader.java +++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceReader.java @@ -18,6 +18,7 @@ */ package org.apache.pulsar.testclient; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.FileInputStream; @@ -95,6 +96,14 @@ public class PerformanceReader { @Parameter(names = { "--auth-params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"") public String authParams; + + @Parameter(names = { + "--use-tls" }, description = "Use TLS encryption on the connection") + public boolean useTls; + + @Parameter(names = { + "--trust-cert-file" }, description = "Path for the trusted TLS certificate file") + public String tlsTrustCertsFilePath = ""; } public static void main(String[] args) throws Exception { @@ -145,6 +154,14 @@ public class PerformanceReader { if (arguments.authParams == null) { arguments.authParams = prop.getProperty("authParams", null); } + + if (arguments.useTls == false) { + arguments.useTls = Boolean.parseBoolean(prop.getProperty("useTls")); + } + + if (isBlank(arguments.tlsTrustCertsFilePath)) { + arguments.tlsTrustCertsFilePath = prop.getProperty("tlsTrustCertsFilePath", ""); + } } // Dump config variables @@ -172,6 +189,8 @@ public class PerformanceReader { if (isNotBlank(arguments.authPluginClassName)) { clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); } + clientConf.setUseTls(arguments.useTls); + clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath); PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf); List> futures = Lists.newArrayList(); @@ -222,4 +241,4 @@ public class PerformanceReader { } private static final Logger log = LoggerFactory.getLogger(PerformanceReader.class); -} \ No newline at end of file +} -- GitLab