sijie commented on a change in pull request #4018: Support multi-host for
pulsar-admin
URL: https://github.com/apache/pulsar/pull/4018#discussion_r277501520
##########
File path:
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java
##########
@@ -76,63 +86,102 @@ public boolean keepAlive(Request ahcRequest, HttpRequest
request, HttpResponse r
}
});
- if (conf != null && StringUtils.isNotBlank(conf.getServiceUrl())
- && conf.getServiceUrl().startsWith("https://")) {
-
- SslContext sslCtx = null;
-
- // Set client key and certificate if available
- AuthenticationDataProvider authData =
conf.getAuthentication().getAuthData();
- if (authData.hasDataForTls()) {
- sslCtx = SecurityUtility.createNettySslContextForClient(
- conf.isTlsAllowInsecureConnection() ||
!conf.isTlsHostnameVerificationEnable(),
- conf.getTlsTrustCertsFilePath(),
- authData.getTlsCertificates(),
authData.getTlsPrivateKey());
- } else {
- sslCtx = SecurityUtility.createNettySslContextForClient(
- conf.isTlsAllowInsecureConnection() ||
!conf.isTlsHostnameVerificationEnable(),
- conf.getTlsTrustCertsFilePath());
- }
+ serviceNameResolver = new PulsarServiceNameResolver();
+ if (conf != null && StringUtils.isNotBlank(conf.getServiceUrl())) {
+ serviceNameResolver.updateServiceUrl(conf.getServiceUrl());
+ if (conf.getServiceUrl().startsWith("https://")) {
+
+ SslContext sslCtx = null;
+
+ // Set client key and certificate if available
+ AuthenticationDataProvider authData =
conf.getAuthentication().getAuthData();
+ if (authData.hasDataForTls()) {
+ sslCtx =
SecurityUtility.createNettySslContextForClient(conf.isTlsAllowInsecureConnection()
|| !conf.isTlsHostnameVerificationEnable(),
+
conf.getTlsTrustCertsFilePath(), authData.getTlsCertificates(),
authData.getTlsPrivateKey());
+ } else {
+ sslCtx =
SecurityUtility.createNettySslContextForClient(conf.isTlsAllowInsecureConnection()
|| !conf.isTlsHostnameVerificationEnable(),
+
conf.getTlsTrustCertsFilePath());
+ }
- confBuilder.setSslContext(sslCtx);
+ confBuilder.setSslContext(sslCtx);
+ }
}
httpClient = new DefaultAsyncHttpClient(confBuilder.build());
}
- @Override
public ClientResponse apply(ClientRequest jerseyRequest) {
- CompletableFuture<ClientResponse> future = new CompletableFuture<>();
- try {
- Future<?> resultFuture = apply(jerseyRequest, new
AsyncConnectorCallback() {
- @Override
- public void response(ClientResponse response) {
- future.complete(response);
+ List<InetSocketAddress> addresses =
serviceNameResolver.getAddressList();
+ CompletableFuture<ClientResponse> future = null;
+ int lastTry = addresses.size() - 1;
+ for (int i = 0; i < addresses.size() * 3; i++) {
Review comment:
I don't fully understand the logic here. Can you explain why are you using
(* 3) here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services