You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2020/10/20 02:52:23 UTC
[pulsar] branch master updated: Added REST handler for broker ready
probe (#8303)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new def7081 Added REST handler for broker ready probe (#8303)
def7081 is described below
commit def7081a2d2d9925b605b43898faab36855e8d37
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Mon Oct 19 19:52:02 2020 -0700
Added REST handler for broker ready probe (#8303)
---
.../java/org/apache/pulsar/broker/PulsarService.java | 4 ++--
.../apache/pulsar/broker/admin/impl/BrokersBase.java | 19 +++++++++++++++++--
.../org/apache/pulsar/broker/web/WebServiceTest.java | 14 ++++++++++++++
3 files changed, 33 insertions(+), 4 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 43e2dc5..f2a2b34 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
@@ -587,8 +587,6 @@ public class PulsarService implements AutoCloseable {
this.protocolHandlers.newChannelInitializers();
this.brokerService.startProtocolHandlers(protocolHandlerChannelInitializers);
- state = State.Started;
-
acquireSLANamespace();
// start function worker service if necessary
@@ -603,6 +601,8 @@ public class PulsarService implements AutoCloseable {
LOG.info("messaging service is ready, {}, cluster={}, configs={}", bootstrapMessage,
config.getClusterName(), ReflectionToStringBuilder.toString(config));
+
+ state = State.Started;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new PulsarServerException(e);
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
index 48eb8bc..476e573 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
@@ -43,6 +43,7 @@ import javax.ws.rs.core.Response.Status;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.util.ZkUtils;
import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.PulsarService.State;
import org.apache.pulsar.broker.admin.AdminResource;
import org.apache.pulsar.broker.loadbalance.LoadManager;
import org.apache.pulsar.broker.namespace.NamespaceService;
@@ -152,7 +153,7 @@ public class BrokersBase extends AdminResource {
validateSuperUserAccess();
deleteDynamicConfigurationOnZk(configName);
}
-
+
@GET
@Path("/configuration/values")
@ApiOperation(value = "Get value of all dynamic configurations' value overridden on local config")
@@ -277,6 +278,20 @@ public class BrokersBase extends AdminResource {
}
@GET
+ @Path("/ready")
+ @ApiOperation(value = "Check if the broker is fully initialized")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Broker is ready"),
+ @ApiResponse(code = 500, message = "Broker is not ready") })
+ public void isReady(@Suspended AsyncResponse asyncResponse) {
+ if (pulsar().getState() == State.Started) {
+ asyncResponse.resume(Response.ok("ok").build());
+ } else {
+ asyncResponse.resume(Response.serverError().build());
+ }
+ }
+
+ @GET
@Path("/health")
@ApiOperation(value = "Run a healthcheck against the broker")
@ApiResponses(value = {
@@ -378,7 +393,7 @@ public class BrokersBase extends AdminResource {
});
});
}
-
+
private synchronized void deleteDynamicConfigurationOnZk(String configName) {
try {
if (BrokerService.isDynamicConfiguration(configName)) {
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java
index fcb9cd8..e5c4ece 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/web/WebServiceTest.java
@@ -274,6 +274,20 @@ public class WebServiceTest {
assertEquals(res3.getStatusCode(), 200);
}
+ @Test
+ public void testBrokerReady() throws Exception {
+ setupEnv(true, "1.0", true, false, false, false, -1);
+
+ String url = pulsar.getWebServiceAddress() + "/admin/v2/brokers/ready";
+
+ @Cleanup
+ AsyncHttpClient client = new DefaultAsyncHttpClient();
+
+ Response res = client.prepareGet(url).execute().get();
+ assertEquals(res.getStatusCode(), 200);
+ assertEquals(res.getResponseBody(), "ok");
+ }
+
private String makeHttpRequest(boolean useTls, boolean useAuth) throws Exception {
InputStream response = null;
try {