Skip to content

Commit

Permalink
support tls in performance tool (apache#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsakai authored and merlimat committed Aug 9, 2017
1 parent 005aa12 commit de24aaf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,6 +101,14 @@ static class Arguments {
@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 {
Expand Down Expand Up @@ -150,6 +159,14 @@ public static void main(String[] args) throws Exception {
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
Expand Down Expand Up @@ -181,6 +198,8 @@ public void received(Consumer consumer, Message msg) {
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<Future<Consumer>> futures = Lists.newArrayList();
Expand Down Expand Up @@ -235,4 +254,4 @@ public void received(Consumer consumer, Message msg) {
}

private static final Logger log = LoggerFactory.getLogger(PerformanceConsumer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,6 +133,14 @@ static class Arguments {
@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 {
Expand Down Expand Up @@ -182,6 +191,14 @@ public static void main(String[] args) throws Exception {
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);
Expand Down Expand Up @@ -210,6 +227,8 @@ public static void main(String[] args) throws Exception {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +96,14 @@ static class Arguments {
@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 {
Expand Down Expand Up @@ -145,6 +154,14 @@ public static void main(String[] args) throws Exception {
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
Expand Down Expand Up @@ -172,6 +189,8 @@ public static void main(String[] args) throws Exception {
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<CompletableFuture<Reader>> futures = Lists.newArrayList();
Expand Down Expand Up @@ -222,4 +241,4 @@ public static void main(String[] args) throws Exception {
}

private static final Logger log = LoggerFactory.getLogger(PerformanceReader.class);
}
}

0 comments on commit de24aaf

Please sign in to comment.