提交 de24aaf1 编写于 作者: H hrsakai 提交者: Matteo Merli

support tls in performance tool (#662)

上级 005aa12d
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
package org.apache.pulsar.testclient; package org.apache.pulsar.testclient;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -100,6 +101,14 @@ public class PerformanceConsumer { ...@@ -100,6 +101,14 @@ public class PerformanceConsumer {
@Parameter(names = { @Parameter(names = {
"--auth_params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"") "--auth_params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"")
public String authParams; 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 { public static void main(String[] args) throws Exception {
...@@ -150,6 +159,14 @@ public class PerformanceConsumer { ...@@ -150,6 +159,14 @@ public class PerformanceConsumer {
if (arguments.authParams == null) { if (arguments.authParams == null) {
arguments.authParams = prop.getProperty("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 // Dump config variables
...@@ -181,6 +198,8 @@ public class PerformanceConsumer { ...@@ -181,6 +198,8 @@ public class PerformanceConsumer {
if (isNotBlank(arguments.authPluginClassName)) { if (isNotBlank(arguments.authPluginClassName)) {
clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams);
} }
clientConf.setUseTls(arguments.useTls);
clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath);
PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf); PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf);
List<Future<Consumer>> futures = Lists.newArrayList(); List<Future<Consumer>> futures = Lists.newArrayList();
...@@ -235,4 +254,4 @@ public class PerformanceConsumer { ...@@ -235,4 +254,4 @@ public class PerformanceConsumer {
} }
private static final Logger log = LoggerFactory.getLogger(PerformanceConsumer.class); private static final Logger log = LoggerFactory.getLogger(PerformanceConsumer.class);
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.pulsar.testclient; package org.apache.pulsar.testclient;
import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -132,6 +133,14 @@ public class PerformanceProducer { ...@@ -132,6 +133,14 @@ public class PerformanceProducer {
@Parameter(names = { "-time", @Parameter(names = { "-time",
"--test-duration" }, description = "Test duration in secs. If 0, it will keep publishing") "--test-duration" }, description = "Test duration in secs. If 0, it will keep publishing")
public long testTime = 0; 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 { public static void main(String[] args) throws Exception {
...@@ -182,6 +191,14 @@ public class PerformanceProducer { ...@@ -182,6 +191,14 @@ public class PerformanceProducer {
if (arguments.authParams == null) { if (arguments.authParams == null) {
arguments.authParams = prop.getProperty("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); arguments.testTime = TimeUnit.SECONDS.toMillis(arguments.testTime);
...@@ -210,6 +227,8 @@ public class PerformanceProducer { ...@@ -210,6 +227,8 @@ public class PerformanceProducer {
if (isNotBlank(arguments.authPluginClassName)) { if (isNotBlank(arguments.authPluginClassName)) {
clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams);
} }
clientConf.setUseTls(arguments.useTls);
clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath);
PulsarClient client = new PulsarClientImpl(arguments.serviceURL, clientConf); PulsarClient client = new PulsarClientImpl(arguments.serviceURL, clientConf);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
package org.apache.pulsar.testclient; package org.apache.pulsar.testclient;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -95,6 +96,14 @@ public class PerformanceReader { ...@@ -95,6 +96,14 @@ public class PerformanceReader {
@Parameter(names = { @Parameter(names = {
"--auth-params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"") "--auth-params" }, description = "Authentication parameters, e.g., \"key1:val1,key2:val2\"")
public String authParams; 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 { public static void main(String[] args) throws Exception {
...@@ -145,6 +154,14 @@ public class PerformanceReader { ...@@ -145,6 +154,14 @@ public class PerformanceReader {
if (arguments.authParams == null) { if (arguments.authParams == null) {
arguments.authParams = prop.getProperty("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 // Dump config variables
...@@ -172,6 +189,8 @@ public class PerformanceReader { ...@@ -172,6 +189,8 @@ public class PerformanceReader {
if (isNotBlank(arguments.authPluginClassName)) { if (isNotBlank(arguments.authPluginClassName)) {
clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams); clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams);
} }
clientConf.setUseTls(arguments.useTls);
clientConf.setTlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath);
PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf); PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf);
List<CompletableFuture<Reader>> futures = Lists.newArrayList(); List<CompletableFuture<Reader>> futures = Lists.newArrayList();
...@@ -222,4 +241,4 @@ public class PerformanceReader { ...@@ -222,4 +241,4 @@ public class PerformanceReader {
} }
private static final Logger log = LoggerFactory.getLogger(PerformanceReader.class); private static final Logger log = LoggerFactory.getLogger(PerformanceReader.class);
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册