Technoboy- commented on code in PR #17082:
URL: https://github.com/apache/pulsar/pull/17082#discussion_r945399502
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java:
##########
@@ -493,13 +502,47 @@ private URI getRedirectionUrl(ClusterData
differentClusterData) throws Malformed
} else {
serviceNameResolver.updateServiceUrl(differentClusterData.getServiceUrl());
}
- URL webUrl = new
URL(serviceNameResolver.resolveHostUri().toString());
- return
UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ return getConnectableURI(serviceNameResolver);
} catch (PulsarClientException.InvalidServiceURL exception) {
throw new MalformedURLException(exception.getMessage());
}
}
+ private CompletableFuture<URI> getConnectableURI(PulsarServiceNameResolver
serviceNameResolver) {
+ return CompletableFuture.supplyAsync(() -> {
+ String hostUri = serviceNameResolver.resolveHostUri().toString();
+ String firstHostUri = hostUri;
+ boolean connectable = false;
+ URL webUrl = null;
+ do {
+ try {
+ webUrl = new URL(hostUri);
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(webUrl.getHost(),
webUrl.getPort()), 5000);
+ socket.close();
+ connectable = true;
+ } catch (Exception e) {
+ log.warn("Unable connect to url:{}", hostUri);
+ hostUri = serviceNameResolver.resolveHostUri().toString();
+
+ if (firstHostUri.equals(hostUri)) {
+ break;
+ }
+ }
+ } while (!connectable);
+
+ if (webUrl == null) {
+ try {
+ webUrl = new URL(hostUri);
+ } catch (MalformedURLException e) {
+ throw new RestException(e);
+ }
+ }
+
+ return
UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
+ }, pulsar.getExecutor());
+ }
+
Review Comment:
We may add this logic to PulsarServiceNameResolver
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]