Skip to content

Commit

Permalink
OOZIE-3070 Remove references to org.mortbay.jetty (pbacsko)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbacsko committed Sep 29, 2017
1 parent 0034f7f commit 2e6b50a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 49 deletions.
11 changes: 7 additions & 4 deletions core/pom.xml
Expand Up @@ -266,7 +266,6 @@
<scope>compile</scope>
</dependency>


<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
Expand Down Expand Up @@ -313,10 +312,14 @@
</dependency>

<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<scope>compile</scope>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>

<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
Expand Down
Expand Up @@ -18,15 +18,23 @@

package org.apache.oozie.test;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.Context;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.EnumSet;
import java.util.Map;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;

/**
* An embedded servlet container for testing purposes. <p> It provides reduced functionality, it supports only
* Servlets. <p> The servlet container is started in a free port.
Expand All @@ -36,7 +44,7 @@ public class EmbeddedServletContainer {
private String host = null;
private int port = -1;
private String contextPath;
Context context;
private ServletContextHandler context;

/**
* Create a servlet container.
Expand All @@ -47,7 +55,7 @@ public class EmbeddedServletContainer {
public EmbeddedServletContainer(String contextPath) {
this.contextPath = contextPath;
server = new Server(0);
context = new Context();
context = new ServletContextHandler();
context.setContextPath("/" + contextPath);
server.setHandler(context);
}
Expand All @@ -60,12 +68,12 @@ public EmbeddedServletContainer(String contextPath) {
* @param servletClass servlet class
* @param initParams a mapping of init parameters for the servlet, or null
*/
public void addServletEndpoint(String servletPath, Class servletClass, Map<String, String> initParams) {
ServletHolder s = new ServletHolder(servletClass);
context.addServlet(s, servletPath);
public void addServletEndpoint(String servletPath, Class<? extends Servlet> servletClass, Map<String, String> initParams) {
ServletHolder holder = new ServletHolder(servletClass);
if (initParams != null) {
s.setInitParameters(initParams);
holder.setInitParameters(initParams);
}
context.addServlet(holder, servletPath);
}

/**
Expand All @@ -75,19 +83,31 @@ public void addServletEndpoint(String servletPath, Class servletClass, Map<Strin
* the end.
* @param servletClass servlet class
*/
public void addServletEndpoint(String servletPath, Class servletClass) {
public void addServletEndpoint(String servletPath, Class<? extends Servlet> servletClass) {
addServletEndpoint(servletPath, servletClass, null);
}

/**
* Add a servlet instance to the container.
*
* @param servletPath servlet path for the servlet, it should be prefixed with '/", it may contain a wild card at
* the end.
* @param servletClass servlet instance
*/
public void addServletEndpoint(String servletPath, Servlet servlet) {
ServletHolder holder = new ServletHolder(servlet);
context.addServlet(holder, servletPath);
}

/**
* Add a filter to the container.
*
* @param filterPath path for the filter, it should be prefixed with '/", it may contain a wild card at
* the end.
* @param filterClass servlet class
*/
public void addFilter(String filterPath, Class filterClass) {
context.addFilter(new FilterHolder(filterClass), filterPath, 0);
public void addFilter(String filterPath, Class<? extends Filter> filterClass) {
context.addFilter(new FilterHolder(filterClass), filterPath, EnumSet.of(DispatcherType.REQUEST));
}

/**
Expand All @@ -97,9 +117,11 @@ public void addFilter(String filterPath, Class filterClass) {
*/
public void start() throws Exception {
host = InetAddress.getLocalHost().getHostName();
server.getConnectors()[0].setHost(host);
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(new HttpConfiguration()));
connector.setHost(host);
server.setConnectors(new Connector[] { connector });
server.start();
port = server.getConnectors()[0].getLocalPort();
port = connector.getLocalPort();
System.out.println("Running embedded servlet container at: http://" + host + ":" + port);
}

Expand Down Expand Up @@ -165,5 +187,4 @@ public void stop() {
host = null;
port = -1;
}

}
Expand Up @@ -32,6 +32,8 @@
import java.util.HashMap;
import java.util.Map;

import javax.servlet.Servlet;

// A lot of this adapted from org.apache.hadoop.mapreduce.v2.app.TestJobEndNotifier and org.apache.hadoop.mapred.TestJobEndNotifier
public class TestLauncherAMCallbackNotifier extends XTestCase {
private EmbeddedServletContainer container;
Expand Down Expand Up @@ -170,7 +172,7 @@ public void testNotifyBackgroundActionWhenSubmitFailsWithFailed() throws Excepti
waitForCallbackAndCheckResult(FinalApplicationStatus.FAILED.toString());
}

private Configuration setupEmbeddedContainer(Class<?> servletClass, String servletEndPoint,
private Configuration setupEmbeddedContainer(Class<? extends Servlet> servletClass, String servletEndPoint,
String servletUrl, Map<String, String> params) throws Exception {
container = new EmbeddedServletContainer("test");
if (servletEndPoint != null) {
Expand Down
Expand Up @@ -70,7 +70,7 @@ public class TestOozieCLI extends DagServletTestCase {
static final String VERSION = "/v" + OozieClient.WS_PROTOCOL_VERSION;
static final String[] END_POINTS = {"/versions", VERSION + "/jobs", VERSION + "/job/*", VERSION + "/admin/*",
VERSION + "/validate/*", "/v1/sla"};
static final Class[] SERVLET_CLASSES = { HeaderTestingVersionServlet.class, V1JobsServlet.class,
static final Class<?>[] SERVLET_CLASSES = { HeaderTestingVersionServlet.class, V1JobsServlet.class,
V2JobServlet.class, V2AdminServlet.class, V2ValidateServlet.class, SLAServlet.class};

@Override
Expand Down
Expand Up @@ -35,32 +35,51 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class TestWorkflowNotificationXCommand extends XTestCase {
private EmbeddedServletContainer container;
private CallbackServlet callbackServlet;

@SuppressWarnings("serial")
public static class CallbackServlet extends HttpServlet {
public static volatile String JOB_ID = null;
public static String NODE_NAME = null;
public static String STATUS = null;
public static String PARENT_ID = null;

public static void reset() {
JOB_ID = null;
NODE_NAME = null;
STATUS = null;
PARENT_ID = null;
}
String jobID = null;
String nodeName = null;
String status = null;
String parentID = null;
final ReentrantLock lock = new ReentrantLock();
final Condition updated = lock.newCondition();
boolean requestProcessed = false;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
JOB_ID = req.getParameter("jobId");
NODE_NAME = req.getParameter("nodeName");
STATUS = req.getParameter("status");
PARENT_ID = req.getParameter("parentId");
jobID = req.getParameter("jobId");
nodeName = req.getParameter("nodeName");
status = req.getParameter("status");
parentID = req.getParameter("parentId");
resp.setStatus(HttpServletResponse.SC_OK);

lock.lock();
try {
requestProcessed = true;
updated.signalAll();
} finally {
lock.unlock();
}
}

public void waitUntilRequestProcessed() throws InterruptedException {
lock.lock();
try {
while (!requestProcessed) {
updated.await(10, TimeUnit.SECONDS);
}
} finally {
lock.unlock();
}
}
}

@Override
Expand All @@ -71,8 +90,8 @@ public void setUp() throws Exception {
services.init();
container = new EmbeddedServletContainer("blah");
container.addServletEndpoint("/hang/*", HangServlet.class);
CallbackServlet.reset();
container.addServletEndpoint("/callback/*", CallbackServlet.class);
callbackServlet = new CallbackServlet();
container.addServletEndpoint("/callback/*", callbackServlet);
container.start();
}

Expand Down Expand Up @@ -110,7 +129,6 @@ public void testWFNotificationTimeout() throws Exception {
}

public void testWFNotification() throws Exception {

String notificationUrl = "/callback/wf?jobId=$jobId&parentId=$parentId";
_testNotificationParentId(notificationUrl, "1", null, "");

Expand Down Expand Up @@ -139,8 +157,9 @@ private void _testNotificationParentId(String notificationUrl, String jobId, Str
WorkflowNotificationXCommand command = new WorkflowNotificationXCommand(workflow);
command.setRetry(3);
command.call();
callbackServlet.waitUntilRequestProcessed();

Assert.assertEquals(jobId, CallbackServlet.JOB_ID);
Assert.assertEquals(expectedParentId, CallbackServlet.PARENT_ID);
Assert.assertEquals(jobId, callbackServlet.jobID);
Assert.assertEquals(expectedParentId, callbackServlet.parentID);
}
}
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -1255,12 +1255,6 @@
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.14</version>
</dependency>

<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
Expand Down
1 change: 1 addition & 0 deletions release-log.txt
@@ -1,5 +1,6 @@
-- Oozie 5.0.0 release (trunk - unreleased)

OOZIE-3070 Remove references to org.mortbay.jetty (pbacsko)
OOZIE-2885 Running Spark actions should not need Hive on the classpath (satishsaley)
OOZIE-2909 amend Fix license headers (andras.piros via gezapeti)
OOZIE-3054 Disable erasure coding for sharelib if Oozie runs on Hadoop 3 (pbacsko)
Expand Down
4 changes: 4 additions & 0 deletions sharelib/hive2/pom.xml
Expand Up @@ -43,6 +43,10 @@
<artifactId>hive-cli</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jetty</artifactId>
<groupId>org.mortbay.jetty</groupId>
</exclusion>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions sharelib/spark/pom.xml
Expand Up @@ -198,6 +198,12 @@
<artifactId>spark-streaming-flume_${spark.scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
Expand Down

0 comments on commit 2e6b50a

Please sign in to comment.