From ea8b2dffd599c5e9704a5ef753b94ffaa74fba07 Mon Sep 17 00:00:00 2001 From: nishantmonu51 Date: Wed, 9 Apr 2014 14:25:18 +0530 Subject: [PATCH] Add chatHandlerResource --- .../firehose/ChatHandlerResource.java | 55 +++++++++++++++++++ .../src/main/java/io/druid/cli/CliPeon.java | 2 +- .../java/io/druid/guice/RealtimeModule.java | 2 + 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/io/druid/segment/realtime/firehose/ChatHandlerResource.java diff --git a/server/src/main/java/io/druid/segment/realtime/firehose/ChatHandlerResource.java b/server/src/main/java/io/druid/segment/realtime/firehose/ChatHandlerResource.java new file mode 100644 index 00000000000..a1d26b56dfd --- /dev/null +++ b/server/src/main/java/io/druid/segment/realtime/firehose/ChatHandlerResource.java @@ -0,0 +1,55 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2012, 2013 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.segment.realtime.firehose; + +import com.google.common.base.Optional; +import com.google.inject.Inject; +import io.druid.segment.realtime.firehose.ChatHandler; +import io.druid.segment.realtime.firehose.ChatHandlerProvider; + +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +@Path("/druid/worker/v1") +public class ChatHandlerResource +{ + private final ChatHandlerProvider handlers; + + @Inject + public ChatHandlerResource(ChatHandlerProvider handlers) + { + this.handlers = handlers; + } + + @Path("/chat/{id}") + public Object doTaskChat( + @PathParam("id") String handlerId + ) + { + final Optional handler = handlers.get(handlerId); + + if (handler.isPresent()) { + return handler.get(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } + } +} diff --git a/services/src/main/java/io/druid/cli/CliPeon.java b/services/src/main/java/io/druid/cli/CliPeon.java index 36812948900..d4eb0228c9a 100644 --- a/services/src/main/java/io/druid/cli/CliPeon.java +++ b/services/src/main/java/io/druid/cli/CliPeon.java @@ -56,7 +56,7 @@ import io.druid.indexing.overlord.IndexerDBCoordinator; import io.druid.indexing.overlord.TaskRunner; import io.druid.indexing.overlord.TaskStorage; import io.druid.indexing.overlord.ThreadPoolTaskRunner; -import io.druid.indexing.worker.executor.ChatHandlerResource; +import io.druid.segment.realtime.firehose.ChatHandlerResource; import io.druid.indexing.worker.executor.ExecutorLifecycle; import io.druid.indexing.worker.executor.ExecutorLifecycleConfig; import io.druid.query.QuerySegmentWalker; diff --git a/services/src/main/java/io/druid/guice/RealtimeModule.java b/services/src/main/java/io/druid/guice/RealtimeModule.java index ae4ca1319df..7bcce15823a 100644 --- a/services/src/main/java/io/druid/guice/RealtimeModule.java +++ b/services/src/main/java/io/druid/guice/RealtimeModule.java @@ -32,6 +32,7 @@ import io.druid.segment.realtime.NoopSegmentPublisher; import io.druid.segment.realtime.RealtimeManager; import io.druid.segment.realtime.SegmentPublisher; import io.druid.segment.realtime.firehose.ChatHandlerProvider; +import io.druid.segment.realtime.firehose.ChatHandlerResource; import io.druid.segment.realtime.firehose.NoopChatHandlerProvider; import io.druid.segment.realtime.firehose.ServiceAnnouncingChatHandlerProvider; import io.druid.server.QueryResource; @@ -83,6 +84,7 @@ public class RealtimeModule implements Module binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("realtime")); binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class); Jerseys.addResource(binder, QueryResource.class); + Jerseys.addResource(binder, ChatHandlerResource.class); LifecycleModule.register(binder, QueryResource.class); LifecycleModule.register(binder, Server.class);