Skip to content

Commit

Permalink
Refactoring: Moved BaseJettyServerInitializer.java to JettyServerInit…
Browse files Browse the repository at this point in the history
…Utils.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
  • Loading branch information
himanshug committed Mar 6, 2015
1 parent a8648d8 commit 956361d
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -32,19 +34,19 @@

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);
Expand All @@ -60,7 +62,7 @@ private static void setDefaultGzipFilterHolderParameters(final FilterHolder filt
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +45,8 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
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;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testProxyGzipCompression() throws Exception
Assert.assertNotEquals("gzip", postNoGzip.getContentEncoding());
}

public static class ProxyJettyServerInit extends BaseJettyServerInitializer
public static class ProxyJettyServerInit implements JettyServerInitializer
{

private final DruidNode node;
Expand Down Expand Up @@ -181,8 +181,8 @@ protected URI rewriteURI(HttpServletRequest request)
}
), "/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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
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;
Expand Down Expand Up @@ -189,16 +193,16 @@ public HttpClient getClient()
}
}

public static class JettyServerInit extends BaseJettyServerInitializer
public static class JettyServerInit 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();
Expand Down
3 changes: 2 additions & 1 deletion services/src/main/java/io/druid/cli/CliBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion services/src/main/java/io/druid/cli/CliBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion services/src/main/java/io/druid/cli/CliCoordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion services/src/main/java/io/druid/cli/CliHistorical.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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;

Expand Down
3 changes: 2 additions & 1 deletion services/src/main/java/io/druid/cli/CliMiddleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
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;
Expand Down
10 changes: 5 additions & 5 deletions services/src/main/java/io/druid/cli/CliOverlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
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;
Expand Down Expand Up @@ -217,7 +217,7 @@ private void configureAutoscale(Binder binder)

/**
*/
private static class OverlordJettyServerInitializer extends BaseJettyServerInitializer
private static class OverlordJettyServerInitializer implements JettyServerInitializer
{
@Override
public void initialize(Server server, Injector injector)
Expand All @@ -235,8 +235,8 @@ public void initialize(Server server, Injector injector)
}
)
);
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);
Expand Down
3 changes: 2 additions & 1 deletion services/src/main/java/io/druid/cli/CliPeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion services/src/main/java/io/druid/cli/CliRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
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;
Expand All @@ -34,7 +36,7 @@

/**
*/
class CoordinatorJettyServerInitializer extends BaseJettyServerInitializer
class CoordinatorJettyServerInitializer implements JettyServerInitializer
{
private final DruidCoordinatorConfig config;

Expand All @@ -57,8 +59,8 @@ public void initialize(Server server, Injector injector)
} 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,15 +32,15 @@

/**
*/
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

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;
Expand All @@ -29,15 +32,15 @@

/**
*/
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);

Expand Down
Loading

0 comments on commit 956361d

Please sign in to comment.