diff --git a/conf/client.conf b/conf/client.conf index ea1d339a09c5b..8a485e5676c7b 100644 --- a/conf/client.conf +++ b/conf/client.conf @@ -88,7 +88,11 @@ tlsKeyStorePassword= # When TLS authentication with KeyStore is used, available options can be SunJSSE, Conscrypt and so on. webserviceTlsProvider= +#Proxy-server URL to which to connect +proxyServiceUrl= +#Proxy protocol to select type of routing at proxy +proxyProtocol= # Pulsar Admin Custom Commands #customCommandFactoriesDirectory=commandFactories diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java index 1ce5777fd3219..a3552d314309c 100644 --- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java +++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java @@ -75,7 +75,8 @@ public static ClientBuilder createClientBuilderFromArguments(PerformanceBaseArgu .enableBusyWait(arguments.enableBusyWait) .listenerThreads(arguments.listenerThreads) .tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath) - .maxLookupRequests(arguments.maxLookupRequest); + .maxLookupRequests(arguments.maxLookupRequest) + .proxyServiceUrl(arguments.proxyServiceURL, arguments.proxyProtocol); if (isNotBlank(arguments.authPluginClassName)) { clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams); diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java index cff7e16e9caa4..307af7cbb152b 100644 --- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java +++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java @@ -19,10 +19,12 @@ package org.apache.pulsar.testclient; import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.pulsar.testclient.PerfClientUtils.exit; import com.beust.jcommander.Parameter; import java.io.FileInputStream; import java.util.Properties; import lombok.SneakyThrows; +import org.apache.pulsar.client.api.ProxyProtocol; public abstract class PerformanceBaseArguments { @@ -85,6 +87,12 @@ public abstract class PerformanceBaseArguments { + "on each broker connection to prevent overloading a broker") public int maxLookupRequest = 50000; + @Parameter(names = { "--proxy-url" }, description = "Proxy-server URL to which to connect.") + String proxyServiceURL = null; + + @Parameter(names = { "--proxy-protocol" }, description = "Proxy protocol to select type of routing at proxy.") + ProxyProtocol proxyProtocol = null; + public abstract void fillArgumentsFromProperties(Properties prop); @SneakyThrows @@ -133,6 +141,25 @@ public void fillArgumentsFromProperties() { .getProperty("tlsEnableHostnameVerification", "")); } + + if (proxyServiceURL == null) { + proxyServiceURL = prop.getProperty("proxyServiceURL"); + } + + if (proxyProtocol == null) { + try { + String proxyProtocolString = prop.getProperty("proxyProtocol"); + if (proxyProtocolString != null) { + proxyProtocol = ProxyProtocol.valueOf(prop.getProperty("proxyProtocol")); + } + } catch (IllegalArgumentException e) { + System.out.println("Incorrect proxyProtocol name"); + e.printStackTrace(); + exit(-1); + } + + } + fillArgumentsFromProperties(prop); } diff --git a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java index ea21112635a87..e1f1e7d358162 100644 --- a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java +++ b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Properties; import org.apache.pulsar.client.api.Authentication; +import org.apache.pulsar.client.api.ProxyProtocol; import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.impl.ClientBuilderImpl; import org.apache.pulsar.client.impl.conf.ClientConfigurationData; @@ -71,6 +72,8 @@ public void fillArgumentsFromProperties(Properties prop) { args.tlsTrustCertsFilePath = "path"; args.tlsAllowInsecureConnection = true; args.maxLookupRequest = 100000; + args.proxyServiceURL = "pulsar+ssl://my-proxy-pulsar:4443"; + args.proxyProtocol = ProxyProtocol.SNI; final ClientBuilderImpl builder = (ClientBuilderImpl)PerfClientUtils.createClientBuilderFromArguments(args); final ClientConfigurationData conf = builder.getClientConfigurationData(); @@ -88,6 +91,8 @@ public void fillArgumentsFromProperties(Properties prop) { Assert.assertEquals(conf.getTlsTrustCertsFilePath(), "path"); Assert.assertTrue(conf.isTlsAllowInsecureConnection()); Assert.assertEquals(conf.getMaxLookupRequest(), 100000); + Assert.assertEquals(conf.getProxyServiceUrl(), "pulsar+ssl://my-proxy-pulsar:4443"); + Assert.assertEquals(conf.getProxyProtocol(), ProxyProtocol.SNI); } } \ No newline at end of file diff --git a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java index 0b244a5a4e1ba..3071f92f9ccce 100644 --- a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java +++ b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java @@ -18,11 +18,19 @@ */ package org.apache.pulsar.testclient; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; + import org.testng.Assert; import org.testng.annotations.Test; +import static org.apache.pulsar.client.api.ProxyProtocol.SNI; +import static org.testng.Assert.fail; + public class PerformanceBaseArgumentsTest { @@ -47,6 +55,111 @@ public void fillArgumentsFromProperties(Properties prop) { Assert.assertEquals(args.tlsTrustCertsFilePath, "./path"); Assert.assertTrue(args.tlsAllowInsecureConnection); Assert.assertTrue(args.tlsHostnameVerificationEnable); + Assert.assertEquals(args.proxyServiceURL, "https://my-proxy-pulsar:4443/"); + Assert.assertEquals(args.proxyProtocol, SNI); + } + + @Test + public void testReadFromConfigFileWithoutProxyUrl() { + + AtomicBoolean called = new AtomicBoolean(); + + final PerformanceBaseArguments args = new PerformanceBaseArguments() { + @Override + public void fillArgumentsFromProperties(Properties prop) { + called.set(true); + } + }; + + File tempConfigFile = new File("./src/test/resources/performance_client2.conf"); + if (tempConfigFile.exists()) { + tempConfigFile.delete(); + } + try { + Properties props = new Properties(); + + Map configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/", + "authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth", + "authParams", "myparams", + "tlsTrustCertsFilePath", "./path", + "tlsAllowInsecureConnection","true", + "tlsEnableHostnameVerification", "true" + ); + props.putAll(configs); + FileOutputStream out = new FileOutputStream(tempConfigFile); + props.store(out, "properties file"); + out.close(); + args.confFile = "./src/test/resources/performance_client2.conf"; + + args.fillArgumentsFromProperties(); + Assert.assertTrue(called.get()); + Assert.assertEquals(args.serviceURL, "https://my-pulsar:8443/"); + Assert.assertEquals(args.authPluginClassName, + "org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth"); + Assert.assertEquals(args.authParams, "myparams"); + Assert.assertEquals(args.tlsTrustCertsFilePath, "./path"); + Assert.assertTrue(args.tlsAllowInsecureConnection); + Assert.assertTrue(args.tlsHostnameVerificationEnable); + + } catch (IOException e) { + e.printStackTrace(); + fail("Error while updating/reading config file"); + } finally { + tempConfigFile.delete(); + } + } + + @Test + public void testReadFromConfigFileProxyProtocolException() { + + AtomicBoolean calledVar1 = new AtomicBoolean(); + AtomicBoolean calledVar2 = new AtomicBoolean(); + + final PerformanceBaseArguments args = new PerformanceBaseArguments() { + @Override + public void fillArgumentsFromProperties(Properties prop) { + calledVar1.set(true); + } + }; + File tempConfigFile = new File("./src/test/resources/performance_client3.conf"); + if (tempConfigFile.exists()) { + tempConfigFile.delete(); + } + try { + Properties props = new Properties(); + + Map configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/", + "authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth", + "authParams", "myparams", + "tlsTrustCertsFilePath", "./path", + "tlsAllowInsecureConnection","true", + "tlsEnableHostnameVerification", "true", + "proxyServiceURL", "https://my-proxy-pulsar:4443/", + "proxyProtocol", "TEST" + ); + props.putAll(configs); + FileOutputStream out = new FileOutputStream(tempConfigFile); + props.store(out, "properties file"); + out.close(); + args.confFile = "./src/test/resources/performance_client3.conf"; + PerfClientUtils.setExitProcedure(code -> { + calledVar2.set(true); + Assert.assertNotNull(code); + if (code != -1) { + fail("Incorrect exit code"); + } + }); + + args.confFile = "./src/test/resources/performance_client3.conf"; + args.fillArgumentsFromProperties(); + Assert.assertTrue(calledVar1.get()); + Assert.assertTrue(calledVar2.get()); + } catch (IOException e) { + e.printStackTrace(); + fail("Error while updating/reading config file"); + } finally { + tempConfigFile.delete(); + } } } \ No newline at end of file diff --git a/pulsar-testclient/src/test/resources/perf_client1.conf b/pulsar-testclient/src/test/resources/perf_client1.conf index 127960618bf5d..1e96c7b35c7ca 100644 --- a/pulsar-testclient/src/test/resources/perf_client1.conf +++ b/pulsar-testclient/src/test/resources/perf_client1.conf @@ -23,3 +23,5 @@ authParams=myparams tlsTrustCertsFilePath=./path tlsAllowInsecureConnection=true tlsEnableHostnameVerification=true +proxyServiceURL=https://my-proxy-pulsar:4443/ +proxyProtocol=SNI \ No newline at end of file