Revert "HIVE-14739: Replace runnables directly added to runtime shutdown hooks 
to avoid deadlock (Prasanth Jayachandran reviewed by Chris Nauroth, Siddharth 
Seth)"

This reverts commit f80d260250440719301c4c1e95759854598854a4.


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/5c5a6a99
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/5c5a6a99
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/5c5a6a99

Branch: refs/heads/hive-14535
Commit: 5c5a6a99af7319654ddd2e23306fd6fb4bfc4ad1
Parents: f80d260
Author: Prasanth Jayachandran <prasan...@apache.org>
Authored: Tue Sep 13 15:06:24 2016 -0700
Committer: Prasanth Jayachandran <prasan...@apache.org>
Committed: Tue Sep 13 15:06:24 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/hive/beeline/BeeLine.java   |   5 +-
 .../org/apache/hadoop/hive/cli/CliDriver.java   |   5 +-
 .../hive/common/util/ShutdownHookManager.java   | 171 ++++++++++++++++---
 .../common/util/TestShutdownHookManager.java    |  35 ++++
 .../hive/hcatalog/common/HiveClientCache.java   |   3 +-
 .../hadoop/hive/metastore/HiveMetaStore.java    |   3 +-
 .../hive/ql/exec/mr/HadoopJobExecHelper.java    |   3 +-
 .../spark/session/SparkSessionManagerImpl.java  |   3 +-
 .../hadoop/hive/ql/exec/tez/TezJobMonitor.java  |   3 +-
 .../apache/hadoop/hive/ql/hooks/ATSHook.java    |   3 +-
 .../zookeeper/CuratorFrameworkSingleton.java    |   3 +-
 .../apache/hive/service/server/HiveServer2.java |   3 +-
 .../ptest/api/server/ExecutionController.java   |   2 +-
 13 files changed, 198 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/beeline/src/java/org/apache/hive/beeline/BeeLine.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BeeLine.java 
b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
index 5322ca6..ecd60f6 100644
--- a/beeline/src/java/org/apache/hive/beeline/BeeLine.java
+++ b/beeline/src/java/org/apache/hive/beeline/BeeLine.java
@@ -92,7 +92,6 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.io.IOUtils;
 import org.apache.hive.beeline.cli.CliOptionsProcessor;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.transport.TTransportException;
 
 import org.apache.hive.jdbc.Utils;
@@ -1077,7 +1076,7 @@ public class BeeLine implements Closeable {
     }
 
     // add shutdown hook to flush the history to history file
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
         @Override
         public void run() {
             History h = consoleReader.getHistory();
@@ -1089,7 +1088,7 @@ public class BeeLine implements Closeable {
                 }
             }
         }
-    });
+    }));
 
     consoleReader.addCompleter(new BeeLineCompleter(this));
     return consoleReader;

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
----------------------------------------------------------------------
diff --git a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java 
b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
index 5364ca6..874e5aa 100644
--- a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
+++ b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
@@ -79,7 +79,6 @@ import 
org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 import org.apache.hadoop.io.IOUtils;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -809,7 +808,7 @@ public class CliDriver {
     }
 
     // add shutdown hook to flush the history to history file
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
       @Override
       public void run() {
         History h = reader.getHistory();
@@ -821,7 +820,7 @@ public class CliDriver {
           }
         }
       }
-    });
+    }));
   }
 
   protected void setupConsoleReader() throws IOException {

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
----------------------------------------------------------------------
diff --git 
a/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java 
b/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
index 6585e3b..5efeda9 100644
--- a/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
+++ b/common/src/java/org/apache/hive/common/util/ShutdownHookManager.java
@@ -18,37 +18,131 @@
 
 package org.apache.hive.common.util;
 
+import com.google.common.annotations.VisibleForTesting;
+
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.apache.hadoop.fs.FileSystem;
-
-import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * This is just a wrapper around hadoop's ShutdownHookManager but also manages 
delete on exit hook for temp files.
+ * The <code>ShutdownHookManager</code> enables running shutdownHook
+ * in a deterministic order, higher priority first.
+ * <p/>
+ * The JVM runs ShutdownHooks in a non-deterministic order or in parallel.
+ * This class registers a single JVM shutdownHook and run all the
+ * shutdownHooks registered to it (to this class) in order based on their
+ * priority.
+ *
+ * Originally taken from o.a.hadoop.util.ShutdownHookManager
  */
 public class ShutdownHookManager {
 
-  private static final org.apache.hadoop.util.ShutdownHookManager MGR = 
org.apache.hadoop.util.ShutdownHookManager.get();
+  private static final ShutdownHookManager MGR = new ShutdownHookManager();
 
   private static final DeleteOnExitHook DELETE_ON_EXIT_HOOK = new 
DeleteOnExitHook();
 
+  private static final Logger LOG = 
LoggerFactory.getLogger(ShutdownHookManager.class);
+
   static {
-    MGR.addShutdownHook(DELETE_ON_EXIT_HOOK, -1);
+    MGR.addShutdownHookInternal(DELETE_ON_EXIT_HOOK, -1);
+    Runtime.getRuntime().addShutdownHook(
+      new Thread() {
+        @Override
+        public void run() {
+          MGR.shutdownInProgress.set(true);
+          for (Runnable hook : getShutdownHooksInOrder()) {
+            try {
+              hook.run();
+            } catch (Throwable ex) {
+              LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() +
+                       "' failed, " + ex.toString(), ex);
+            }
+          }
+        }
+      }
+    );
   }
 
+
   /**
-   * Adds shutdown hook with default priority (10)
-   * @param shutdownHook - shutdown hook
+   * Private structure to store ShutdownHook and its priority.
    */
-  public static void addShutdownHook(Runnable shutdownHook) {
-    addShutdownHook(shutdownHook, FileSystem.SHUTDOWN_HOOK_PRIORITY);
+  private static class HookEntry {
+    Runnable hook;
+    int priority;
+
+    public HookEntry(Runnable hook, int priority) {
+      this.hook = hook;
+      this.priority = priority;
+    }
+
+    @Override
+    public int hashCode() {
+      return hook.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      boolean eq = false;
+      if (obj != null) {
+        if (obj instanceof HookEntry) {
+          eq = (hook == ((HookEntry)obj).hook);
+        }
+      }
+      return eq;
+    }
+
+  }
+
+  private final Set<HookEntry> hooks =
+    Collections.synchronizedSet(new HashSet<HookEntry>());
+
+  private final AtomicBoolean shutdownInProgress = new AtomicBoolean(false);
+
+  //private to constructor to ensure singularity
+  private ShutdownHookManager() {
   }
 
   /**
+   * Returns the list of shutdownHooks in order of execution,
+   * Highest priority first.
+   *
+   * @return the list of shutdownHooks in order of execution.
+   */
+  static List<Runnable> getShutdownHooksInOrder() {
+    return MGR.getShutdownHooksInOrderInternal();
+  }
+
+  private List<Runnable> getShutdownHooksInOrderInternal() {
+    List<HookEntry> list;
+    synchronized (MGR.hooks) {
+      list = new ArrayList<HookEntry>(MGR.hooks);
+    }
+    Collections.sort(list, new Comparator<HookEntry>() {
+
+      //reversing comparison so highest priority hooks are first
+      @Override
+      public int compare(HookEntry o1, HookEntry o2) {
+        return o2.priority - o1.priority;
+      }
+    });
+    List<Runnable> ordered = new ArrayList<Runnable>();
+    for (HookEntry entry: list) {
+      ordered.add(entry.hook);
+    }
+    return ordered;
+  }
+
+
+  /**
    * Adds a shutdownHook with a priority, the higher the priority
    * the earlier will run. ShutdownHooks with same priority run
    * in a non-deterministic order.
@@ -60,16 +154,17 @@ public class ShutdownHookManager {
     if (priority < 0) {
       throw new IllegalArgumentException("Priority should be greater than or 
equal to zero");
     }
-    MGR.addShutdownHook(shutdownHook, priority);
+    MGR.addShutdownHookInternal(shutdownHook, priority);
   }
 
-  /**
-   * Indicates if shutdown is in progress or not.
-   *
-   * @return TRUE if the shutdown is in progress, otherwise FALSE.
-   */
-  public static boolean isShutdownInProgress() {
-    return MGR.isShutdownInProgress();
+  private void addShutdownHookInternal(Runnable shutdownHook, int priority) {
+    if (shutdownHook == null) {
+      throw new IllegalArgumentException("shutdownHook cannot be NULL");
+    }
+    if (shutdownInProgress.get()) {
+      throw new IllegalStateException("Shutdown in progress, cannot add a 
shutdownHook");
+    }
+    hooks.add(new HookEntry(shutdownHook, priority));
   }
 
   /**
@@ -83,7 +178,41 @@ public class ShutdownHookManager {
     if (shutdownHook == null) {
       return false;
     }
-    return MGR.removeShutdownHook(shutdownHook);
+    return MGR.removeShutdownHookInternal(shutdownHook);
+  }
+
+  private boolean removeShutdownHookInternal(Runnable shutdownHook) {
+    if (shutdownInProgress.get()) {
+      throw new IllegalStateException("Shutdown in progress, cannot remove a 
shutdownHook");
+    }
+    return hooks.remove(new HookEntry(shutdownHook, 0));
+  }
+
+  /**
+   * Indicates if a shutdownHook is registered or not.
+   *
+   * @param shutdownHook shutdownHook to check if registered.
+   * @return TRUE/FALSE depending if the shutdownHook is is registered.
+   */
+  public static boolean hasShutdownHook(Runnable shutdownHook) {
+    return MGR.hasShutdownHookInternal(shutdownHook);
+  }
+
+  public boolean hasShutdownHookInternal(Runnable shutdownHook) {
+    return hooks.contains(new HookEntry(shutdownHook, 0));
+  }
+
+  /**
+   * Indicates if shutdown is in progress or not.
+   *
+   * @return TRUE if the shutdown is in progress, otherwise FALSE.
+   */
+  public static boolean isShutdownInProgress() {
+    return MGR.isShutdownInProgressInternal();
+  }
+
+  private boolean isShutdownInProgressInternal() {
+    return shutdownInProgress.get();
   }
 
   /**
@@ -92,7 +221,7 @@ public class ShutdownHookManager {
    * @see {@link org.apache.hadoop.hive.common.FileUtils#createTempFile}
    */
   public static void deleteOnExit(File file) {
-    if (MGR.isShutdownInProgress()) {
+    if (isShutdownInProgress()) {
       throw new IllegalStateException("Shutdown in progress, cannot add a 
deleteOnExit");
     }
     DELETE_ON_EXIT_HOOK.deleteTargets.add(file);
@@ -102,7 +231,7 @@ public class ShutdownHookManager {
    * deregister file from delete-on-exit hook
    */
   public static void cancelDeleteOnExit(File file) {
-    if (MGR.isShutdownInProgress()) {
+    if (isShutdownInProgress()) {
       throw new IllegalStateException("Shutdown in progress, cannot cancel a 
deleteOnExit");
     }
     DELETE_ON_EXIT_HOOK.deleteTargets.remove(file);

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
----------------------------------------------------------------------
diff --git 
a/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java 
b/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
index d740670..66f6073 100644
--- a/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
+++ b/common/src/test/org/apache/hive/common/util/TestShutdownHookManager.java
@@ -34,6 +34,41 @@ import org.apache.hadoop.hive.common.FileUtils;
 public class TestShutdownHookManager {
 
   @Test
+  public void shutdownHookManager() {
+    Assert.assertEquals(1, 
ShutdownHookManager.getShutdownHooksInOrder().size());
+    Runnable hook1 = new Runnable() {
+      @Override
+      public void run() {
+      }
+    };
+    Runnable hook2 = new Runnable() {
+      @Override
+      public void run() {
+      }
+    };
+
+    ShutdownHookManager.addShutdownHook(hook1, 0);
+    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
+    Assert.assertEquals(2, 
ShutdownHookManager.getShutdownHooksInOrder().size());
+    Assert.assertEquals(hook1, 
ShutdownHookManager.getShutdownHooksInOrder().get(0));
+    ShutdownHookManager.removeShutdownHook(hook1);
+    Assert.assertFalse(ShutdownHookManager.hasShutdownHook(hook1));
+
+    ShutdownHookManager.addShutdownHook(hook1, 0);
+    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
+    Assert.assertEquals(2, 
ShutdownHookManager.getShutdownHooksInOrder().size());
+    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
+    Assert.assertEquals(2, 
ShutdownHookManager.getShutdownHooksInOrder().size());
+
+    ShutdownHookManager.addShutdownHook(hook2, 1);
+    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook1));
+    Assert.assertTrue(ShutdownHookManager.hasShutdownHook(hook2));
+    Assert.assertEquals(3, 
ShutdownHookManager.getShutdownHooksInOrder().size());
+    Assert.assertEquals(hook2, 
ShutdownHookManager.getShutdownHooksInOrder().get(0));
+    Assert.assertEquals(hook1, 
ShutdownHookManager.getShutdownHooksInOrder().get(1));
+  }
+
+  @Test
   public void deleteOnExit() throws IOException {
     File file = FileUtils.createTempFile(null, "tmp", null);
     Assert.assertTrue(ShutdownHookManager.isRegisteredToDeleteOnExit(file));

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
----------------------------------------------------------------------
diff --git 
a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
 
b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
index c1b63d9..51f516e 100644
--- 
a/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
+++ 
b/hcatalog/core/src/main/java/org/apache/hive/hcatalog/common/HiveClientCache.java
@@ -42,7 +42,6 @@ import 
org.apache.hadoop.hive.metastore.annotation.NoReconnect;
 import org.apache.hadoop.hive.shims.ShimLoader;
 import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -218,7 +217,7 @@ class HiveClientCache {
       }
     };
 
-    ShutdownHookManager.addShutdownHook(cleanupHiveClientShutdownThread);
+    Runtime.getRuntime().addShutdownHook(cleanupHiveClientShutdownThread);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index f0b8476..3f85ca6 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -97,7 +97,6 @@ import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hive.common.util.HiveStringUtils;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.thrift.TException;
 import org.apache.thrift.TProcessor;
 import org.apache.thrift.protocol.TBinaryProtocol;
@@ -6642,7 +6641,7 @@ public class HiveMetaStore extends ThriftHiveMetastore {
       }
 
       // Add shutdown hook.
-      ShutdownHookManager.addShutdownHook(new Runnable() {
+      Runtime.getRuntime().addShutdownHook(new Thread() {
         @Override
         public void run() {
           String shutdownMsg = "Shutting down hive metastore.";

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
index 41887d7..bb6ed84 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/mr/HadoopJobExecHelper.java
@@ -54,7 +54,6 @@ import org.apache.hadoop.mapred.JobStatus;
 import org.apache.hadoop.mapred.RunningJob;
 import org.apache.hadoop.mapred.TaskCompletionEvent;
 import org.apache.hadoop.mapred.TaskReport;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Logger;
@@ -173,7 +172,7 @@ public class HadoopJobExecHelper {
    *
    */
   static {
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+      Runtime.getRuntime().addShutdownHook(new Thread() {
         @Override
         public void run() {
           killRunningJobs();

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
index 3c2f0e6..75e5913 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/spark/session/SparkSessionManagerImpl.java
@@ -24,7 +24,6 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -47,7 +46,7 @@ public class SparkSessionManagerImpl implements 
SparkSessionManager {
   private static SparkSessionManagerImpl instance;
 
   static {
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         try {

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java 
b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
index 211a281..d617879 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezJobMonitor.java
@@ -48,7 +48,6 @@ import org.apache.hadoop.hive.ql.log.PerfLogger;
 import org.apache.hadoop.hive.ql.plan.BaseWork;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.tez.common.counters.FileSystemCounter;
 import org.apache.tez.common.counters.TaskCounter;
 import org.apache.tez.common.counters.TezCounter;
@@ -141,7 +140,7 @@ public class TezJobMonitor {
 
   static {
     shutdownList = new LinkedList<DAGClient>();
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         TezJobMonitor.killRunningJobs();

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java 
b/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
index 7438570..e593945 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/hooks/ATSHook.java
@@ -37,7 +37,6 @@ import 
org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
 import org.apache.hadoop.yarn.api.records.timeline.TimelineEvent;
 import org.apache.hadoop.yarn.client.api.TimelineClient;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -76,7 +75,7 @@ public class ATSHook implements ExecuteWithHookContext {
         timelineClient.init(yarnConf);
         timelineClient.start();
 
-        ShutdownHookManager.addShutdownHook(new Runnable() {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
           @Override
           public void run() {
             try {

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
 
b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
index b55b6ca..6482f3b 100644
--- 
a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
+++ 
b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/zookeeper/CuratorFrameworkSingleton.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hive.ql.lockmgr.zookeeper;
 
 import java.util.concurrent.TimeUnit;
 
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.curator.framework.CuratorFramework;
@@ -35,7 +34,7 @@ public class CuratorFrameworkSingleton {
   static final Logger LOG = 
LoggerFactory.getLogger("CuratorFrameworkSingleton");
   static {
     // Add shutdown hook.
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         closeAndReleaseInstance();

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/service/src/java/org/apache/hive/service/server/HiveServer2.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java 
b/service/src/java/org/apache/hive/service/server/HiveServer2.java
index 58e9aeb..9822a85 100644
--- a/service/src/java/org/apache/hive/service/server/HiveServer2.java
+++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java
@@ -60,7 +60,6 @@ import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hive.common.util.HiveStringUtils;
 import org.apache.hive.common.util.HiveVersionInfo;
-import org.apache.hive.common.util.ShutdownHookManager;
 import org.apache.hive.http.HttpServer;
 import org.apache.hive.http.LlapServlet;
 import org.apache.hive.service.CompositeService;
@@ -207,7 +206,7 @@ public class HiveServer2 extends CompositeService {
       throw new ServiceException(ie);
     }
     // Add a shutdown hook for catching SIGTERM & SIGINT
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         hiveServer2.stop();

http://git-wip-us.apache.org/repos/asf/hive/blob/5c5a6a99/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
----------------------------------------------------------------------
diff --git 
a/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
 
b/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
index dd8957d..2f96ad0 100644
--- 
a/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
+++ 
b/testutils/ptest2/src/main/java/org/apache/hive/ptest/api/server/ExecutionController.java
@@ -101,7 +101,7 @@ public class ExecutionController {
     mTestExecutor.setName("TestExecutor");
     mTestExecutor.setDaemon(true);
     mTestExecutor.start();
-    ShutdownHookManager.addShutdownHook(new Runnable() {
+    Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
         LOG.info("Shutdown hook called");

Reply via email to