Skip to content

Commit

Permalink
Add advertisedAddress config field to ProxyConfiguration (apache#7542)
Browse files Browse the repository at this point in the history
* Add advertisedAddress config field to ProxyConfiguration

* Enable disabled proxy tests

Co-authored-by: Ali Ahmed <[email protected]>
  • Loading branch information
aahmed-se and Ali Ahmed authored Jul 16, 2020
1 parent 4acf775 commit b6ceec4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class ProxyConfiguration implements PulsarConfiguration {
@FieldContext(
category = CATEGORY_SERVER,
doc = "Hostname or IP address the service advertises to the outside world."
+ " If not set, the value of `InetAddress.getLocalHost().getHostname()` is used."
+ " If not set, the value of `InetAddress.getLocalHost().getCanonicalHostName()` is used."
)
private String advertisedAddress;
@FieldContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.concurrent.atomic.AtomicReference;

import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.broker.ServiceConfigurationUtils;
import org.apache.pulsar.broker.authentication.AuthenticationService;
import org.apache.pulsar.broker.authorization.AuthorizationService;
import org.apache.pulsar.broker.cache.ConfigurationCacheService;
Expand Down Expand Up @@ -143,7 +144,7 @@ public ProxyService(ProxyConfiguration proxyConfig,
statsExecutor.schedule(()->{
this.clientCnxs.forEach(cnx -> {
cnx.getDirectProxyHandler().getInboundChannelRequestsRate().calculateRate();
});
});
this.topicStats.forEach((topic, stats) -> {
stats.calculate();
});
Expand Down Expand Up @@ -186,13 +187,8 @@ public void start() throws Exception {
LOG.info("Started Pulsar TLS Proxy on {}", listenChannelTls.localAddress());
}

String hostname;
try {
hostname = StringUtils.isNotBlank(proxyConfig.getAdvertisedAddress()) ? proxyConfig.getAdvertisedAddress()
: InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
final String hostname =
ServiceConfigurationUtils.getDefaultOrConfiguredAddress(proxyConfig.getAdvertisedAddress());

if (proxyConfig.getServicePort().isPresent()) {
this.serviceUrl = String.format("pulsar://%s:%d/", hostname, getListenPort().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void cleanup() throws Exception {
}

@Test
void testForwardAuthData() throws Exception {
public void testForwardAuthData() throws Exception {
log.info("-- Starting {} test --", methodName);

// Step 1: Create Admin Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testRegexSubscription() throws Exception {
}

@Test
private void testProtocolVersionAdvertisement() throws Exception {
public void testProtocolVersionAdvertisement() throws Exception {
final String topic = "persistent://sample/test/local/protocol-version-advertisement";
final String sub = "my-sub";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected void cleanup() throws Exception {
}

@Test
void testIncorrectRoles() throws Exception {
public void testIncorrectRoles() throws Exception {
log.info("-- Starting {} test --", methodName);

// Step 1: Create Admin Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class ProxyTest extends MockedPulsarServiceBaseTest {
private ProxyService proxyService;
private ProxyConfiguration proxyConfig = new ProxyConfiguration();


@Data
@ToString
@EqualsAndHashCode
Expand Down Expand Up @@ -288,7 +287,6 @@ public void testProtocolVersionAdvertisement() throws Exception {
}
}


private static PulsarClient getClientActiveConsumerChangeNotSupported(ClientConfigurationData conf)
throws Exception {
ThreadFactory threadFactory = new DefaultThreadFactory("pulsar-client-io", Thread.currentThread().isDaemon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public class ProxyWithAuthorizationTest extends ProducerConsumerBase {

@DataProvider(name = "hostnameVerification")
public Object[][] hostnameVerificationCodecProvider() {
return new Object[][] { { Boolean.TRUE }, { Boolean.FALSE } };
return new Object[][] {
{ Boolean.TRUE },
{ Boolean.FALSE }
};
}

@DataProvider(name = "protocolsCiphersProvider")
Expand Down Expand Up @@ -129,10 +132,16 @@ public Object[][] protocolsCiphersProviderCodecProvider() {
ciphers_8.add("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
ciphers_8.add("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384");

return new Object[][] { { ciphers_1, protocols_1, Boolean.FALSE }, { ciphers_2, protocols_2, Boolean.FALSE },
{ ciphers_3, protocols_3, Boolean.TRUE }, { ciphers_4, protocols_4, Boolean.TRUE },
{ ciphers_5, protocols_5, Boolean.TRUE }, { ciphers_6, protocols_6, Boolean.FALSE },
{ ciphers_7, protocols_7, Boolean.FALSE }, { ciphers_8, protocols_8, Boolean.FALSE } };
return new Object[][] {
{ ciphers_1, protocols_1, Boolean.FALSE },
{ ciphers_2, protocols_2, Boolean.FALSE },
{ ciphers_3, protocols_3, Boolean.TRUE },
{ ciphers_4, protocols_4, Boolean.TRUE },
{ ciphers_5, protocols_5, Boolean.TRUE },
{ ciphers_6, protocols_6, Boolean.FALSE },
{ ciphers_7, protocols_7, Boolean.FALSE },
{ ciphers_8, protocols_8, Boolean.FALSE }
};
}

@BeforeMethod
Expand Down

0 comments on commit b6ceec4

Please sign in to comment.