From 7a9940d624aad3236cbf918b9a9393b57e953790 Mon Sep 17 00:00:00 2001 From: Roman Leventov Date: Wed, 11 Oct 2017 22:35:52 -0500 Subject: [PATCH] Add /readiness to HistoricalResource (#4916) * Add /loadStatusCode to HistoricalResource * Address comments * Fixes --- docs/content/design/historical.md | 9 ++++++++- .../java/io/druid/server/http/HistoricalResource.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/content/design/historical.md b/docs/content/design/historical.md index 567eba89628..36d502018e5 100644 --- a/docs/content/design/historical.md +++ b/docs/content/design/historical.md @@ -50,4 +50,11 @@ Returns the Druid version, loaded extensions, memory used, total memory and othe * `/druid/historical/v1/loadstatus` -Returns a flag indicating if all segments in the local cache have been loaded. This can be used to know when a historical node is ready to be queried after a restart. +Returns JSON of the form `{"cacheInitialized":}`, where value is either `true` or `false` indicating if all +segments in the local cache have been loaded. This can be used to know when a historical node is ready +to be queried after a restart. + +* `/druid/historical/v1/readiness` + +Similar to `/druid/historical/v1/loadstatus`, but instead of returning JSON with a flag, responses 200 OK if segments +in the local cache have been loaded, and 503 SERVICE UNAVAILABLE, if they haven't. diff --git a/server/src/main/java/io/druid/server/http/HistoricalResource.java b/server/src/main/java/io/druid/server/http/HistoricalResource.java index bc77ce0fc05..70d0b0d8cca 100644 --- a/server/src/main/java/io/druid/server/http/HistoricalResource.java +++ b/server/src/main/java/io/druid/server/http/HistoricalResource.java @@ -52,4 +52,15 @@ public class HistoricalResource { return Response.ok(ImmutableMap.of("cacheInitialized", coordinator.isStarted())).build(); } + + @GET + @Path("/readiness") + public Response getReadiness() + { + if (coordinator.isStarted()) { + return Response.ok().build(); + } else { + return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); + } + } }