From 49a98972bd2aa8deef2f9a95cf7678bd1e6033a4 Mon Sep 17 00:00:00 2001 From: Sijie Guo Date: Thu, 23 Jan 2020 23:02:35 -0800 Subject: [PATCH] [Websocket] Websocket doesn't set the correct cluster data (#6102) *Motivation* Fixes #5997 Fixes #6079 A regression was introduced in #5486. If websocket service as running as part of pulsar standalone, the cluster data is set with null service urls. This causes service url is not set correctly in the pulsar client and an illegal argument exception ("Param serviceUrl must not be blank.") will be thrown. *Modifications* 1. Pass `null` when constructing the websocket service. So the local cluster data can be refreshed when creating pulsar client. 2. Set the cluster data after both broker service and web service started and ports are allocated. --- .../java/org/apache/pulsar/broker/PulsarService.java | 10 +++++++--- .../org/apache/pulsar/websocket/WebSocketService.java | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java index fd169fe1d1d59..ff7ba47728a9c 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java @@ -427,9 +427,7 @@ public Boolean get() { if (config.isWebSocketServiceEnabled()) { // Use local broker address to avoid different IP address when using a VIP for service discovery - this.webSocketService = new WebSocketService( - new ClusterData(webServiceAddress, webServiceAddressTls, brokerServiceUrl, brokerServiceUrlTls), - config); + this.webSocketService = new WebSocketService(null, config); this.webSocketService.start(); final WebSocketServlet producerWebSocketServlet = new WebSocketProducerServlet(webSocketService); @@ -466,6 +464,12 @@ public Boolean get() { this.brokerServiceUrl = brokerUrl(config); this.brokerServiceUrlTls = brokerUrlTls(config); + if (null != this.webSocketService) { + ClusterData clusterData = + new ClusterData(webServiceAddress, webServiceAddressTls, brokerServiceUrl, brokerServiceUrlTls); + this.webSocketService.setLocalCluster(clusterData); + } + // needs load management service this.startNamespaceService(); diff --git a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java index 79cd4366e9fdf..062af7efb82ed 100644 --- a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java +++ b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/WebSocketService.java @@ -30,6 +30,7 @@ import javax.servlet.ServletException; import javax.websocket.DeploymentException; +import lombok.Setter; import org.apache.bookkeeper.common.util.OrderedScheduler; import org.apache.pulsar.broker.PulsarServerException; import org.apache.pulsar.broker.ServiceConfiguration; @@ -77,6 +78,7 @@ public class WebSocketService implements Closeable { private ServiceConfiguration config; private ConfigurationCacheService configurationCacheService; + @Setter private ClusterData localCluster; private final ConcurrentOpenHashMap> topicProducerMap; private final ConcurrentOpenHashMap> topicConsumerMap;