mirror of https://github.com/apache/druid.git
Merge pull request #304 from metamx/query-resource
Replace query servlet with query resource to make adding new resources easier
This commit is contained in:
commit
c085c3753f
2
pom.xml
2
pom.xml
|
@ -76,7 +76,7 @@
|
|||
<dependency>
|
||||
<groupId>com.metamx</groupId>
|
||||
<artifactId>http-client</artifactId>
|
||||
<version>0.8.1</version>
|
||||
<version>0.8.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.metamx</groupId>
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.google.inject.Binder;
|
|||
import com.google.inject.util.Providers;
|
||||
import io.druid.initialization.DruidModule;
|
||||
import io.druid.query.QuerySegmentWalker;
|
||||
import io.druid.server.QueryServlet;
|
||||
import io.druid.server.log.EmittingRequestLoggerProvider;
|
||||
import io.druid.server.log.FileRequestLoggerProvider;
|
||||
import io.druid.server.log.RequestLogger;
|
||||
|
@ -41,7 +40,6 @@ public class QueryableModule implements DruidModule
|
|||
@Override
|
||||
public void configure(Binder binder)
|
||||
{
|
||||
binder.bind(QueryServlet.class).in(LazySingleton.class);
|
||||
binder.bind(QuerySegmentWalker.class).toProvider(Providers.<QuerySegmentWalker>of(null));
|
||||
binder.bind(RequestLogger.class).toProvider(RequestLoggerProvider.class).in(ManageLifecycle.class);
|
||||
JsonConfigProvider.bind(binder, "druid.request.logging", RequestLoggerProvider.class);
|
||||
|
|
|
@ -37,22 +37,25 @@ import io.druid.guice.annotations.Smile;
|
|||
import io.druid.query.Query;
|
||||
import io.druid.query.QuerySegmentWalker;
|
||||
import io.druid.server.log.RequestLogger;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class QueryServlet extends HttpServlet
|
||||
@Path("/druid/v2/")
|
||||
public class QueryResource
|
||||
{
|
||||
private static final Logger log = new Logger(QueryServlet.class);
|
||||
private static final Logger log = new Logger(QueryResource.class);
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private final ObjectMapper jsonMapper;
|
||||
|
@ -62,7 +65,7 @@ public class QueryServlet extends HttpServlet
|
|||
private final RequestLogger requestLogger;
|
||||
|
||||
@Inject
|
||||
public QueryServlet(
|
||||
public QueryResource(
|
||||
@Json ObjectMapper jsonMapper,
|
||||
@Smile ObjectMapper smileMapper,
|
||||
QuerySegmentWalker texasRanger,
|
||||
|
@ -77,8 +80,12 @@ public class QueryServlet extends HttpServlet
|
|||
this.requestLogger = requestLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
@POST
|
||||
@Produces("application/json")
|
||||
public void doPost(
|
||||
@Context HttpServletRequest req,
|
||||
@Context HttpServletResponse resp
|
||||
) throws ServletException, IOException
|
||||
{
|
||||
Query query = null;
|
||||
byte[] requestQuery = null;
|
||||
|
@ -111,7 +118,7 @@ public class QueryServlet extends HttpServlet
|
|||
out = resp.getOutputStream();
|
||||
jsonWriter.writeValue(out, results);
|
||||
|
||||
long requestTime = System.currentTimeMillis() - ((Request) req).getTimeStamp();
|
||||
long requestTime = System.currentTimeMillis() - req.getSession().getCreationTime();
|
||||
|
||||
emitter.emit(
|
||||
new ServiceMetricEvent.Builder()
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* 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.cli;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceFilter;
|
||||
import io.druid.server.QueryServlet;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.servlets.GzipFilter;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class BrokerJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
@Override
|
||||
public void initialize(Server server, Injector injector)
|
||||
{
|
||||
final ServletContextHandler resources = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
resources.addServlet(new ServletHolder(new DefaultServlet()), "/druid/v2/datasources/*");
|
||||
resources.addFilter(GuiceFilter.class, "/druid/v2/datasources/*", null);
|
||||
|
||||
final ServletContextHandler queries = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
queries.setResourceBase("/");
|
||||
queries.addServlet(new ServletHolder(injector.getInstance(QueryServlet.class)), "/druid/v2/*");
|
||||
|
||||
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
|
||||
root.addFilter(GzipFilter.class, "/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/*", null);
|
||||
|
||||
final HandlerList handlerList = new HandlerList();
|
||||
handlerList.setHandlers(new Handler[]{resources, queries, root, new DefaultHandler()});
|
||||
server.setHandler(handlerList);
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ import io.druid.query.QuerySegmentWalker;
|
|||
import io.druid.query.QueryToolChestWarehouse;
|
||||
import io.druid.server.ClientInfoResource;
|
||||
import io.druid.server.ClientQuerySegmentWalker;
|
||||
import io.druid.server.QueryResource;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -81,7 +82,9 @@ public class CliBroker extends ServerRunnable
|
|||
JsonConfigProvider.bind(binder, "druid.broker.cache", CacheProvider.class);
|
||||
|
||||
binder.bind(QuerySegmentWalker.class).to(ClientQuerySegmentWalker.class).in(LazySingleton.class);
|
||||
binder.bind(JettyServerInitializer.class).to(BrokerJettyServerInitializer.class).in(LazySingleton.class);
|
||||
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
|
||||
Jerseys.addResource(binder, QueryResource.class);
|
||||
Jerseys.addResource(binder, ClientInfoResource.class);
|
||||
|
||||
DiscoveryModule.register(binder, Self.class);
|
||||
|
|
|
@ -24,11 +24,13 @@ import com.google.inject.Binder;
|
|||
import com.google.inject.Module;
|
||||
import com.metamx.common.logger.Logger;
|
||||
import io.airlift.command.Command;
|
||||
import io.druid.guice.Jerseys;
|
||||
import io.druid.guice.LazySingleton;
|
||||
import io.druid.guice.LifecycleModule;
|
||||
import io.druid.guice.ManageLifecycle;
|
||||
import io.druid.guice.NodeTypeConfig;
|
||||
import io.druid.query.QuerySegmentWalker;
|
||||
import io.druid.server.QueryResource;
|
||||
import io.druid.server.coordination.ServerManager;
|
||||
import io.druid.server.coordination.ZkCoordinator;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
|
@ -66,6 +68,8 @@ public class CliHistorical extends ServerRunnable
|
|||
|
||||
binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("historical"));
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
|
||||
Jerseys.addResource(binder, QueryResource.class);
|
||||
|
||||
|
||||
LifecycleModule.register(binder, ZkCoordinator.class);
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
|
|
|
@ -65,6 +65,7 @@ import io.druid.segment.loading.DataSegmentKiller;
|
|||
import io.druid.segment.loading.OmniDataSegmentKiller;
|
||||
import io.druid.segment.loading.SegmentLoaderConfig;
|
||||
import io.druid.segment.loading.StorageLocationConfig;
|
||||
import io.druid.server.QueryResource;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
|
@ -149,6 +150,7 @@ public class CliPeon extends GuiceRunnable
|
|||
.toInstance(new SegmentLoaderConfig().withLocations(Arrays.<StorageLocationConfig>asList()));
|
||||
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class);
|
||||
Jerseys.addResource(binder, QueryResource.class);
|
||||
Jerseys.addResource(binder, ChatHandlerResource.class);
|
||||
binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig(nodeType));
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package io.druid.cli;
|
|||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceFilter;
|
||||
import io.druid.server.QueryServlet;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -41,7 +40,6 @@ public class QueryJettyServerInitializer implements JettyServerInitializer
|
|||
{
|
||||
final ServletContextHandler queries = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
queries.setResourceBase("/");
|
||||
queries.addServlet(new ServletHolder(injector.getInstance(QueryServlet.class)), "/druid/v2/*");
|
||||
|
||||
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
|
||||
|
|
|
@ -31,6 +31,7 @@ import io.druid.segment.realtime.FireDepartment;
|
|||
import io.druid.segment.realtime.NoopSegmentPublisher;
|
||||
import io.druid.segment.realtime.RealtimeManager;
|
||||
import io.druid.segment.realtime.SegmentPublisher;
|
||||
import io.druid.server.QueryResource;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
|
@ -64,6 +65,7 @@ public class RealtimeModule implements Module
|
|||
binder.bind(QuerySegmentWalker.class).to(RealtimeManager.class).in(ManageLifecycle.class);
|
||||
binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("realtime"));
|
||||
binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
|
||||
Jerseys.addResource(binder, QueryResource.class);
|
||||
|
||||
LifecycleModule.register(binder, Server.class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue