vineeth1995 commented on code in PR #18663:
URL: https://github.com/apache/pulsar/pull/18663#discussion_r1054976089
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -878,6 +881,50 @@ protected BookieAffinityGroupData
internalGetBookieAffinityGroup() {
}
}
+ private void validateLeaderBroker() {
+ if (!this.isLeaderBroker()) {
+ LeaderBroker leaderBroker =
pulsar().getLeaderElectionService().getCurrentLeader().get();
+ String leaderBrokerUrl = leaderBroker.getServiceUrl();
+ CompletableFuture<LookupResult> result =
pulsar().getNamespaceService()
+ .createLookupResult(leaderBrokerUrl, false, null);
+ try {
+ LookupResult lookupResult = result.get();
+ String redirectUrl = isRequestHttps() ?
lookupResult.getLookupData().getHttpUrlTls()
+ : lookupResult.getLookupData().getHttpUrl();
+ if (redirectUrl == null) {
+ log.error("Redirected broker's service url is not
configured");
+ throw new
RestException(Response.Status.PRECONDITION_FAILED,
+ "Redirected broker's service url is not
configured.");
+ }
+ URL url = new URL(redirectUrl);
+ URI redirect =
UriBuilder.fromUri(uri.getRequestUri()).host(url.getHost())
+ .port(url.getPort())
+ .replaceQueryParam("authoritative",
+ false).build();
+
+ // Redirect
+ if (log.isDebugEnabled()) {
+ log.debug("Redirecting the request call to leader - {}",
redirect);
+ }
+ throw new
WebApplicationException(Response.temporaryRedirect(redirect).build());
+ } catch (MalformedURLException exception) {
+ log.error("The leader broker url is malformed - {}",
leaderBrokerUrl);
+ throw new RestException(exception);
+ } catch (ExecutionException | InterruptedException exception) {
+ log.error("Leader broker not found - {}", leaderBrokerUrl);
Review Comment:
addressed
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -878,6 +881,50 @@ protected BookieAffinityGroupData
internalGetBookieAffinityGroup() {
}
}
+ private void validateLeaderBroker() {
+ if (!this.isLeaderBroker()) {
+ LeaderBroker leaderBroker =
pulsar().getLeaderElectionService().getCurrentLeader().get();
+ String leaderBrokerUrl = leaderBroker.getServiceUrl();
+ CompletableFuture<LookupResult> result =
pulsar().getNamespaceService()
+ .createLookupResult(leaderBrokerUrl, false, null);
+ try {
+ LookupResult lookupResult = result.get();
Review Comment:
addressed
--
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]