You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ey...@apache.org on 2011/10/05 18:06:06 UTC

svn commit: r1179286 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/http/HttpServer.java src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java

Author: eyang
Date: Wed Oct  5 16:06:05 2011
New Revision: 1179286

URL: http://svn.apache.org/viewvc?rev=1179286&view=rev
Log:
HADOOP-7703. Improved excpetion handling of shutting down web server.
(Devaraj K via Eric Yang)

Modified:
    hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java
    hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1179286&r1=1179285&r2=1179286&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Wed Oct  5 16:06:05 2011
@@ -45,6 +45,8 @@ Trunk (unreleased changes)
     HADOOP-6220. HttpServer wraps InterruptedExceptions by IOExceptions if interrupted 
                  in startup (stevel)
 
+    HADOOP-7703. Improved excpetion handling of shutting down web server.
+    (Devaraj K via Eric Yang)
 
 Release 0.23.0 - Unreleased
 

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java?rev=1179286&r1=1179285&r2=1179286&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer.java Wed Oct  5 16:06:05 2011
@@ -210,7 +210,7 @@ public class HttpServer implements Filte
     webServer.setHandler(contexts);
 
     webAppContext = new WebAppContext();
-    webAppContext.setDisplayName("WepAppsContext");
+    webAppContext.setDisplayName(name);
     webAppContext.setContextPath("/");
     webAppContext.setWar(appDir + "/" + name);
     webAppContext.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
@@ -696,8 +696,44 @@ public class HttpServer implements Filte
    * stop the server
    */
   public void stop() throws Exception {
-    listener.close();
-    webServer.stop();
+    MultiException exception = null;
+    try {
+      listener.close();
+    } catch (Exception e) {
+      LOG.error("Error while stopping listener for webapp"
+          + webAppContext.getDisplayName(), e);
+      exception = addMultiException(exception, e);
+    }
+
+    try {
+      // clear & stop webAppContext attributes to avoid memory leaks.
+      webAppContext.clearAttributes();
+      webAppContext.stop();
+    } catch (Exception e) {
+      LOG.error("Error while stopping web app context for webapp "
+          + webAppContext.getDisplayName(), e);
+      exception = addMultiException(exception, e);
+    }
+    try {
+      webServer.stop();
+    } catch (Exception e) {
+      LOG.error("Error while stopping web server for webapp "
+          + webAppContext.getDisplayName(), e);
+      exception = addMultiException(exception, e);
+    }
+
+    if (exception != null) {
+      exception.ifExceptionThrow();
+    }
+
+  }
+
+  private MultiException addMultiException(MultiException exception, Exception e) {
+    if(exception == null){
+      exception = new MultiException();
+    }
+    exception.add(e);
+    return exception;
   }
 
   public void join() throws InterruptedException {

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java?rev=1179286&r1=1179285&r2=1179286&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/http/TestHttpServerLifecycle.java Wed Oct  5 16:06:05 2011
@@ -56,16 +56,14 @@ public class TestHttpServerLifecycle ext
    *
    * @throws Throwable on failure
    */
-  @Test public void testStartedServerIsAlive() throws Throwable {
+  @Test
+  public void testStartedServerIsAlive() throws Throwable {
     HttpServer server = null;
-    try {
-      server = createTestServer();
-      assertNotLive(server);
-      server.start();
-      assertAlive(server);
-    } finally {
-      stop(server);
-    }
+    server = createTestServer();
+    assertNotLive(server);
+    server.start();
+    assertAlive(server);
+    stop(server);
   }
 
   /**
@@ -105,4 +103,24 @@ public class TestHttpServerLifecycle ext
     assertNotLive(server);
   }
 
+  /**
+   * Test that the server is alive once started
+   * 
+   * @throws Throwable
+   *           on failure
+   */
+  @Test
+  public void testWepAppContextAfterServerStop() throws Throwable {
+    HttpServer server = null;
+    String key = "test.attribute.key";
+    String value = "test.attribute.value";
+    server = createTestServer();
+    assertNotLive(server);
+    server.start();
+    server.setAttribute(key, value);
+    assertAlive(server);
+    assertEquals(value, server.getAttribute(key));
+    stop(server);
+    assertNull("Server context should have cleared", server.getAttribute(key));
+  }
 }