From 63f7322522e0ab223ceb91440636eb62ca0a3e41 Mon Sep 17 00:00:00 2001 From: Robert Kanter Date: Fri, 7 Apr 2017 14:28:07 -0700 Subject: [PATCH] YARN-6368. Decommissioning an NM results in a -1 exit code (miklos.szegedi@cloudera.com via rkanter) --- .../yarn/server/nodemanager/NodeManager.java | 26 ++++++++++++++++--- .../nodemanager/TestNodeManagerResync.java | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/NodeManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/NodeManager.java index 60bd00bc58..1cff53f211 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/NodeManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/NodeManager.java @@ -82,6 +82,24 @@ public class NodeManager extends CompositeService implements EventHandler { + /** + * Node manager return status codes. + */ + public enum NodeManagerStatus { + NO_ERROR(0), + EXCEPTION(1); + + private int exitCode; + + NodeManagerStatus(int exitCode) { + this.exitCode = exitCode; + } + + public int getExitCode() { + return exitCode; + } + } + /** * Priority of the NodeManager shutdown hook. */ @@ -421,7 +439,7 @@ public String getName() { return "NodeManager"; } - protected void shutDown() { + protected void shutDown(final int exitCode) { new Thread() { @Override public void run() { @@ -432,7 +450,7 @@ public void run() { } finally { if (shouldExitOnShutdownEvent && !ShutdownHookManager.get().isShutdownInProgress()) { - ExitUtil.terminate(-1); + ExitUtil.terminate(exitCode); } } } @@ -457,7 +475,7 @@ public void run() { .rebootNodeStatusUpdaterAndRegisterWithRM(); } catch (YarnRuntimeException e) { LOG.fatal("Error while rebooting NodeStatusUpdater.", e); - shutDown(); + shutDown(NodeManagerStatus.EXCEPTION.getExitCode()); } } }.start(); @@ -744,7 +762,7 @@ private void initAndStartNodeManager(Configuration conf, boolean hasToReboot) { public void handle(NodeManagerEvent event) { switch (event.getType()) { case SHUTDOWN: - shutDown(); + shutDown(NodeManagerStatus.NO_ERROR.getExitCode()); break; case RESYNC: resyncWithRM(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerResync.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerResync.java index 04cfae9f39..5ab5c3754f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerResync.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeManagerResync.java @@ -638,7 +638,7 @@ public int getNMRegistrationCount() { } @Override - protected void shutDown() { + protected void shutDown(int exitCode) { synchronized (isNMShutdownCalled) { isNMShutdownCalled.set(true); isNMShutdownCalled.notify();