You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by sr...@apache.org on 2014/11/05 22:16:31 UTC

git commit: SENTRY-513: Sentry web service may not be stoped completely (Dapeng Sun via Sravya Tirukkovalur)

Repository: incubator-sentry
Updated Branches:
  refs/heads/master f81a224fc -> 9dc278379


SENTRY-513: Sentry web service may not be stoped completely (Dapeng Sun via Sravya Tirukkovalur)


Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/9dc27837
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/9dc27837
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/9dc27837

Branch: refs/heads/master
Commit: 9dc278379625a3a0f00fcbeea69daa7772190311
Parents: f81a224
Author: Sravya Tirukkovalur <sr...@clouera.com>
Authored: Wed Nov 5 13:15:50 2014 -0800
Committer: Sravya Tirukkovalur <sr...@clouera.com>
Committed: Wed Nov 5 13:15:50 2014 -0800

----------------------------------------------------------------------
 .../db/service/thrift/SentryWebServer.java      |  3 ++
 .../sentry/service/thrift/SentryService.java    | 52 ++++++++++++++++----
 2 files changed, 46 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/9dc27837/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryWebServer.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryWebServer.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryWebServer.java
index 0243c48..090917c 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryWebServer.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryWebServer.java
@@ -52,4 +52,7 @@ public class SentryWebServer {
   public void stop() throws Exception{
     server.stop();
   }
+  public boolean isAlive() {
+    return server != null && server.isStarted();
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/9dc27837/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
index ec17480..1e20ff1 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryService.java
@@ -60,6 +60,7 @@ import org.apache.thrift.transport.TSaslServerTransport;
 import org.apache.thrift.transport.TServerSocket;
 import org.apache.thrift.transport.TServerTransport;
 import org.apache.thrift.transport.TTransportFactory;
+import org.eclipse.jetty.util.MultiException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -258,20 +259,53 @@ public class SentryService implements Callable {
   }
 
   public synchronized void stop() throws Exception{
-    if (status == Status.NOT_STARTED) {
-      return;
-    }
+    MultiException exception = null;
     LOGGER.info("Attempting to stop...");
-
-    if (thriftServer.isServing()) {
-      thriftServer.stop();
+    if (isRunning()) {
+      LOGGER.info("Attempting to stop sentry thrift service...");
+      try {
+        thriftServer.stop();
+        thriftServer = null;
+        status = Status.NOT_STARTED;
+      } catch (Exception e) {
+        LOGGER.error("Error while stopping sentry thrift service", e);
+        exception = addMultiException(exception,e);
+      }
+    } else {
+      thriftServer = null;
+      status = Status.NOT_STARTED;
+      LOGGER.info("Sentry thrift service is already stopped...");
+    }
+    if (isWebServerRunning()) {
+      try {
+        LOGGER.info("Attempting to stop sentry web service...");
+        stopSentryWebServer();
+      } catch (Exception e) {
+        LOGGER.error("Error while stopping sentry web service", e);
+        exception = addMultiException(exception,e);
+      }
+    } else {
+      LOGGER.info("Sentry web service is already stopped...");
+    }
+    if (exception != null) {
+      exception.ifExceptionThrow();
     }
-    thriftServer = null;
-    stopSentryWebServer();
-    status = Status.NOT_STARTED;
     LOGGER.info("Stopped...");
   }
 
+  private MultiException addMultiException(MultiException exception, Exception e) {
+    if(exception == null){
+      exception = new MultiException();
+    }
+    exception.add(e);
+    return exception;
+  }
+
+  private boolean isWebServerRunning() {
+    return sentryWebServer != null
+        && sentryWebServer.isAlive();
+  }
+
   private static int findFreePort() {
     int attempts = 0;
     while (attempts++ <= 1000) {