mirror of https://github.com/apache/druid.git
Refactoring: Moved BaseJettyServerInitializer.java to JettyServerInitUtils.java and changed it from abstract class to a utils class containing static methods
And, moved jetty stuff to its own package io.druid.server.initialization.jetty
This commit is contained in:
parent
a8648d8f3d
commit
956361dbbd
|
@ -55,7 +55,7 @@ import io.druid.guice.annotations.Json;
|
|||
import io.druid.guice.annotations.Smile;
|
||||
import io.druid.guice.http.HttpClientModule;
|
||||
import io.druid.server.initialization.EmitterModule;
|
||||
import io.druid.server.initialization.JettyServerModule;
|
||||
import io.druid.server.initialization.jetty.JettyServerModule;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import io.tesla.aether.Repository;
|
||||
import io.tesla.aether.TeslaAether;
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
/*
|
||||
* Druid - a distributed column store.
|
||||
* Copyright 2012 - 2015 Metamarkets Group Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Metamarkets licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package io.druid.server.initialization;
|
||||
package io.druid.server.initialization.jetty;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -32,19 +34,19 @@ import org.eclipse.jetty.servlets.GzipFilter;
|
|||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
public abstract class BaseJettyServerInitializer implements JettyServerInitializer
|
||||
public class JettyServerInitUtils
|
||||
{
|
||||
|
||||
public static final String GZIP_METHODS = Joiner.on(",").join(HttpMethod.GET, HttpMethod.POST);
|
||||
|
||||
public FilterHolder defaultGzipFilterHolder()
|
||||
public static FilterHolder defaultGzipFilterHolder()
|
||||
{
|
||||
final FilterHolder gzipFilterHolder = new FilterHolder(GzipFilter.class);
|
||||
setDefaultGzipFilterHolderParameters(gzipFilterHolder);
|
||||
return gzipFilterHolder;
|
||||
}
|
||||
|
||||
public FilterHolder defaultAsyncGzipFilterHolder()
|
||||
public static FilterHolder defaultAsyncGzipFilterHolder()
|
||||
{
|
||||
final FilterHolder gzipFilterHolder = new FilterHolder(AsyncGzipFilter.class);
|
||||
setDefaultGzipFilterHolderParameters(gzipFilterHolder);
|
||||
|
@ -60,7 +62,7 @@ public abstract class BaseJettyServerInitializer implements JettyServerInitializ
|
|||
filterHolder.setInitParameter("checkGzExists", String.valueOf(false));
|
||||
}
|
||||
|
||||
public void addExtensionFilters(ServletContextHandler handler, Injector injector) {
|
||||
public static void addExtensionFilters(ServletContextHandler handler, Injector injector) {
|
||||
Set<ServletFilterHolder> extensionFilters = injector.getInstance(Key.get(new TypeLiteral<Set<ServletFilterHolder>>(){}));
|
||||
|
||||
for (ServletFilterHolder servletFilterHolder : extensionFilters) {
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.druid.server.initialization;
|
||||
package io.druid.server.initialization.jetty;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import org.eclipse.jetty.server.Server;
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.druid.server.initialization;
|
||||
package io.druid.server.initialization.jetty;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
|
@ -45,6 +45,8 @@ import io.druid.guice.annotations.Json;
|
|||
import io.druid.guice.annotations.Self;
|
||||
import io.druid.server.DruidNode;
|
||||
import io.druid.server.StatusResource;
|
||||
import io.druid.server.initialization.ServerConfig;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package io.druid.server.initialization;
|
||||
package io.druid.server.initialization.jetty;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
|
@ -38,9 +38,9 @@ import io.druid.guice.annotations.Smile;
|
|||
import io.druid.guice.http.DruidHttpClientConfig;
|
||||
import io.druid.initialization.Initialization;
|
||||
import io.druid.query.Query;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.BaseJettyTest;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.log.RequestLogger;
|
||||
import io.druid.server.metrics.NoopServiceEmitter;
|
||||
import io.druid.server.router.QueryHostFinder;
|
||||
|
@ -122,7 +122,7 @@ public class AsyncQueryForwardingServletTest extends BaseJettyTest
|
|||
Assert.assertNotEquals("gzip", postNoGzip.getContentEncoding());
|
||||
}
|
||||
|
||||
public static class ProxyJettyServerInit extends BaseJettyServerInitializer
|
||||
public static class ProxyJettyServerInit implements JettyServerInitializer
|
||||
{
|
||||
|
||||
private final DruidNode node;
|
||||
|
@ -181,8 +181,8 @@ public class AsyncQueryForwardingServletTest extends BaseJettyTest
|
|||
}
|
||||
), "/proxy/*"
|
||||
);
|
||||
|
||||
root.addFilter(defaultAsyncGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultAsyncGzipFilterHolder(), "/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/slow/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/default/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/exception/*", null);
|
||||
|
|
|
@ -39,6 +39,10 @@ import io.druid.guice.LifecycleModule;
|
|||
import io.druid.guice.annotations.Self;
|
||||
import io.druid.initialization.Initialization;
|
||||
import io.druid.server.DruidNode;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.ServletFilterHolder;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
|
@ -189,7 +193,7 @@ public class BaseJettyTest
|
|||
}
|
||||
}
|
||||
|
||||
public static class JettyServerInit extends BaseJettyServerInitializer
|
||||
public static class JettyServerInit implements JettyServerInitializer
|
||||
{
|
||||
|
||||
@Override
|
||||
|
@ -197,8 +201,8 @@ public class BaseJettyTest
|
|||
{
|
||||
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultGzipFilterHolder(), "/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/*", null);
|
||||
|
||||
final HandlerList handlerList = new HandlerList();
|
||||
|
|
|
@ -54,8 +54,9 @@ import io.druid.server.coordination.AbstractDataSegmentAnnouncer;
|
|||
import io.druid.server.coordination.BatchDataSegmentAnnouncer;
|
||||
import io.druid.server.coordination.DruidServerMetadata;
|
||||
import io.druid.server.initialization.BatchDataSegmentAnnouncerConfig;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.ZkPathsConfig;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.BoundedExponentialBackoffRetry;
|
||||
|
|
|
@ -47,7 +47,7 @@ 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.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import io.druid.server.router.TieredBrokerConfig;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
|
|
@ -54,7 +54,7 @@ import io.druid.server.http.RedirectInfo;
|
|||
import io.druid.server.http.RulesResource;
|
||||
import io.druid.server.http.ServersResource;
|
||||
import io.druid.server.http.TiersResource;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.router.TieredBrokerConfig;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
|
|
@ -38,7 +38,7 @@ import io.druid.server.QueryResource;
|
|||
import io.druid.server.coordination.ServerManager;
|
||||
import io.druid.server.coordination.ZkCoordinator;
|
||||
import io.druid.server.http.HistoricalResource;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.metrics.MetricsModule;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ import io.druid.indexing.worker.config.WorkerConfig;
|
|||
import io.druid.indexing.worker.http.WorkerResource;
|
||||
import io.druid.segment.realtime.firehose.ChatHandlerProvider;
|
||||
import io.druid.server.DruidNode;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -71,8 +71,8 @@ import io.druid.indexing.worker.config.WorkerConfig;
|
|||
import io.druid.segment.realtime.firehose.ChatHandlerProvider;
|
||||
import io.druid.server.http.RedirectFilter;
|
||||
import io.druid.server.http.RedirectInfo;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.tasklogs.TaskLogStreamer;
|
||||
import io.druid.tasklogs.TaskLogs;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
|
@ -217,7 +217,7 @@ public class CliOverlord extends ServerRunnable
|
|||
|
||||
/**
|
||||
*/
|
||||
private static class OverlordJettyServerInitializer extends BaseJettyServerInitializer
|
||||
private static class OverlordJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
@Override
|
||||
public void initialize(Server server, Injector injector)
|
||||
|
@ -235,8 +235,8 @@ public class CliOverlord extends ServerRunnable
|
|||
}
|
||||
)
|
||||
);
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultGzipFilterHolder(), "/*", null);
|
||||
|
||||
// /status should not redirect, so add first
|
||||
root.addFilter(GuiceFilter.class, "/status/*", null);
|
||||
|
|
|
@ -69,7 +69,8 @@ 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;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -34,7 +34,7 @@ import io.druid.guice.LifecycleModule;
|
|||
import io.druid.guice.ManageLifecycle;
|
||||
import io.druid.guice.annotations.Self;
|
||||
import io.druid.guice.http.JettyHttpClientModule;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.router.CoordinatorRuleManager;
|
||||
import io.druid.server.router.QueryHostFinder;
|
||||
import io.druid.server.router.Router;
|
||||
|
|
|
@ -22,7 +22,9 @@ import com.google.inject.Injector;
|
|||
import com.google.inject.servlet.GuiceFilter;
|
||||
import io.druid.server.coordinator.DruidCoordinatorConfig;
|
||||
import io.druid.server.http.RedirectFilter;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
|
@ -34,7 +36,7 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
|
||||
/**
|
||||
*/
|
||||
class CoordinatorJettyServerInitializer extends BaseJettyServerInitializer
|
||||
class CoordinatorJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
private final DruidCoordinatorConfig config;
|
||||
|
||||
|
@ -57,8 +59,8 @@ class CoordinatorJettyServerInitializer extends BaseJettyServerInitializer
|
|||
} else {
|
||||
root.setResourceBase(config.getConsoleStatic());
|
||||
}
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultGzipFilterHolder(), "/*", null);
|
||||
|
||||
// /status should not redirect, so add first
|
||||
root.addFilter(GuiceFilter.class, "/status/*", null);
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
|
||||
package io.druid.cli;
|
||||
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceFilter;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
|
@ -30,15 +32,15 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
|
||||
/**
|
||||
*/
|
||||
class MiddleManagerJettyServerInitializer extends BaseJettyServerInitializer
|
||||
class MiddleManagerJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
@Override
|
||||
public void initialize(Server server, Injector injector)
|
||||
{
|
||||
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultGzipFilterHolder(), "/*", null);
|
||||
root.addFilter(GuiceFilter.class, "/*", null);
|
||||
|
||||
final HandlerList handlerList = new HandlerList();
|
||||
|
|
|
@ -19,7 +19,10 @@ package io.druid.cli;
|
|||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.servlet.GuiceFilter;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
|
@ -29,15 +32,15 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
|
||||
/**
|
||||
*/
|
||||
public class QueryJettyServerInitializer extends BaseJettyServerInitializer
|
||||
public class QueryJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
@Override
|
||||
public void initialize(Server server, Injector injector)
|
||||
{
|
||||
final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
|
||||
root.addServlet(new ServletHolder(new DefaultServlet()), "/*");
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultGzipFilterHolder(), "/*", null);
|
||||
|
||||
root.addFilter(GuiceFilter.class, "/*", null);
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ import io.druid.guice.annotations.Json;
|
|||
import io.druid.guice.annotations.Smile;
|
||||
import io.druid.guice.http.DruidHttpClientConfig;
|
||||
import io.druid.server.AsyncQueryForwardingServlet;
|
||||
import io.druid.server.initialization.BaseJettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitUtils;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
import io.druid.server.log.RequestLogger;
|
||||
import io.druid.server.router.QueryHostFinder;
|
||||
import io.druid.server.router.Router;
|
||||
|
@ -41,7 +42,7 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
|
||||
/**
|
||||
*/
|
||||
public class RouterJettyServerInitializer extends BaseJettyServerInitializer
|
||||
public class RouterJettyServerInitializer implements JettyServerInitializer
|
||||
{
|
||||
private final ObjectMapper jsonMapper;
|
||||
private final ObjectMapper smileMapper;
|
||||
|
@ -89,8 +90,8 @@ public class RouterJettyServerInitializer extends BaseJettyServerInitializer
|
|||
);
|
||||
asyncQueryForwardingServlet.setTimeout(httpClientConfig.getReadTimeout().getMillis());
|
||||
root.addServlet(new ServletHolder(asyncQueryForwardingServlet), "/druid/v2/*");
|
||||
addExtensionFilters(root, injector);
|
||||
root.addFilter(defaultAsyncGzipFilterHolder(), "/*", null);
|
||||
JettyServerInitUtils.addExtensionFilters(root, injector);
|
||||
root.addFilter(JettyServerInitUtils.defaultAsyncGzipFilterHolder(), "/*", null);
|
||||
// Can't use '/*' here because of Guice conflicts with AsyncQueryForwardingServlet path
|
||||
root.addFilter(GuiceFilter.class, "/status/*", null);
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ 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;
|
||||
import io.druid.server.initialization.JettyServerInitializer;
|
||||
import io.druid.server.initialization.jetty.JettyServerInitializer;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
|
Loading…
Reference in New Issue