From 4b5282d22405c5f4a793d598933bddb67b04867a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Fri, 12 Dec 2014 12:59:49 -0800 Subject: [PATCH] add loadstatus endpoint for serverView status --- .../io/druid/client/BrokerServerView.java | 8 +++ .../coordination/BaseZkCoordinator.java | 2 +- .../io/druid/server/http/BrokerResource.java | 50 +++++++++++++++++++ .../src/main/java/io/druid/cli/CliBroker.java | 3 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/io/druid/server/http/BrokerResource.java diff --git a/server/src/main/java/io/druid/client/BrokerServerView.java b/server/src/main/java/io/druid/client/BrokerServerView.java index 543951df1c3..ca2d4d6cb99 100644 --- a/server/src/main/java/io/druid/client/BrokerServerView.java +++ b/server/src/main/java/io/druid/client/BrokerServerView.java @@ -66,6 +66,8 @@ public class BrokerServerView implements TimelineServerView private final ServerInventoryView baseView; private final TierSelectorStrategy tierSelectorStrategy; + private volatile boolean initialized = false; + @Inject public BrokerServerView( QueryToolChestWarehouse warehouse, @@ -109,6 +111,7 @@ public class BrokerServerView implements TimelineServerView @Override public CallbackAction segmentViewInitialized() { + initialized = true; return ServerView.CallbackAction.CONTINUE; } } @@ -128,6 +131,11 @@ public class BrokerServerView implements TimelineServerView ); } + public boolean isInitialized() + { + return initialized; + } + public void clear() { synchronized (lock) { diff --git a/server/src/main/java/io/druid/server/coordination/BaseZkCoordinator.java b/server/src/main/java/io/druid/server/coordination/BaseZkCoordinator.java index 43776480829..97fa1253ec5 100644 --- a/server/src/main/java/io/druid/server/coordination/BaseZkCoordinator.java +++ b/server/src/main/java/io/druid/server/coordination/BaseZkCoordinator.java @@ -54,7 +54,7 @@ public abstract class BaseZkCoordinator implements DataSegmentChangeHandler private final CuratorFramework curator; private volatile PathChildrenCache loadQueueCache; - private volatile boolean started; + private volatile boolean started = false; private final ListeningExecutorService loadingExec; public BaseZkCoordinator( diff --git a/server/src/main/java/io/druid/server/http/BrokerResource.java b/server/src/main/java/io/druid/server/http/BrokerResource.java new file mode 100644 index 00000000000..d843ca50e63 --- /dev/null +++ b/server/src/main/java/io/druid/server/http/BrokerResource.java @@ -0,0 +1,50 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2014 Metamarkets Group Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package io.druid.server.http; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; +import io.druid.client.BrokerServerView; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("/druid/broker/v1") +public class BrokerResource +{ + private final BrokerServerView brokerServerView; + + @Inject + public BrokerResource(BrokerServerView brokerServerView) + { + this.brokerServerView = brokerServerView; + } + + @GET + @Path("/loadstatus") + @Produces(MediaType.APPLICATION_JSON) + public Response getLoadStatus() + { + return Response.ok(ImmutableMap.of("inventoryInitialized", brokerServerView.isInitialized())).build(); + } +} diff --git a/services/src/main/java/io/druid/cli/CliBroker.java b/services/src/main/java/io/druid/cli/CliBroker.java index 9050bc827aa..e5ac925da02 100644 --- a/services/src/main/java/io/druid/cli/CliBroker.java +++ b/services/src/main/java/io/druid/cli/CliBroker.java @@ -48,6 +48,7 @@ import io.druid.server.ClientInfoResource; import io.druid.server.ClientQuerySegmentWalker; import io.druid.server.QueryResource; import io.druid.server.coordination.broker.DruidBroker; +import io.druid.server.http.BrokerResource; import io.druid.server.initialization.JettyServerInitializer; import io.druid.server.metrics.MetricsModule; import io.druid.server.router.TieredBrokerConfig; @@ -87,6 +88,7 @@ public class CliBroker extends ServerRunnable binder.bind(QueryToolChestWarehouse.class).to(MapQueryToolChestWarehouse.class); binder.bind(CachingClusteredClient.class).in(LazySingleton.class); + binder.bind(BrokerServerView.class).in(LazySingleton.class); binder.bind(TimelineServerView.class).to(BrokerServerView.class).in(LazySingleton.class); binder.bind(Cache.class).toProvider(CacheProvider.class).in(ManageLifecycle.class); @@ -101,6 +103,7 @@ public class CliBroker extends ServerRunnable binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class); Jerseys.addResource(binder, QueryResource.class); + Jerseys.addResource(binder, BrokerResource.class); Jerseys.addResource(binder, ClientInfoResource.class); LifecycleModule.register(binder, QueryResource.class); LifecycleModule.register(binder, DruidBroker.class);