From d2c2d8c913dfc12585394a1168d4a92934a4cfb4 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Tue, 9 Jan 2018 09:52:59 -0600 Subject: [PATCH] YARN-7663. RMAppImpl:Invalid event: START at KILLED. Contributed by lujie (cherry picked from commit ebff4decfe86571d203859928e28e6855862737b) Conflicts: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java --- .../resourcemanager/rmapp/RMAppImpl.java | 14 ++++++-- .../rmapp/TestRMAppTransitions.java | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java index c4bbac4025e..e39d9e1645c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java @@ -393,7 +393,7 @@ public class RMAppImpl implements RMApp, Recoverable { EnumSet.of(RMAppEventType.APP_ACCEPTED, RMAppEventType.APP_REJECTED, RMAppEventType.KILL, RMAppEventType.ATTEMPT_FINISHED, RMAppEventType.ATTEMPT_FAILED, - RMAppEventType.NODE_UPDATE)) + RMAppEventType.NODE_UPDATE, RMAppEventType.START)) .installTopology(); @@ -875,7 +875,7 @@ public class RMAppImpl implements RMApp, Recoverable { } catch (InvalidStateTransitionException e) { LOG.error("App: " + appID + " can't handle this event at current state", e); - /* TODO fail the application on the failed transition */ + onInvalidStateTransition(event.getType(), oldState); } // Log at INFO if we're not recovering or not in a terminal state. @@ -2016,4 +2016,14 @@ public class RMAppImpl implements RMApp, Recoverable { this.submissionContext.setAMContainerSpec(null); this.submissionContext.setLogAggregationContext(null); } + + /** + * catch the InvalidStateTransition. + * @param state + * @param rmAppEventType + */ + protected void onInvalidStateTransition(RMAppEventType rmAppEventType, + RMAppState state){ + /* TODO fail the application on the failed transition */ + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java index 344f8bb7de0..920bd4fd2b9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -1151,6 +1151,41 @@ public class TestRMAppTransitions { verifyRMAppFieldsForFinalTransitions(application); } + @Test (timeout = 30000) + public void testAppStartAfterKilled() throws IOException { + LOG.info("--- START: testAppStartAfterKilled ---"); + + ApplicationId applicationId = MockApps.newAppID(appId++); + RMApp application = new RMAppImpl(applicationId, rmContext, conf, null, + null, null, new ApplicationSubmissionContextPBImpl(), null, null, + System.currentTimeMillis(), "YARN", null, null) { + @Override + protected void onInvalidStateTransition(RMAppEventType rmAppEventType, + RMAppState state) { + Assert.assertTrue("RMAppImpl: can't handle " + rmAppEventType + + " at state " + state, false); + } + }; + + // NEW => KILLED event RMAppEventType.KILL + UserGroupInformation fooUser = UserGroupInformation.createUserForTesting( + "testAppStartAfterKilled", new String[] {"foo_group"}); + RMAppEvent event = new RMAppKillByClientEvent( + applicationId, "Application killed by user.", + fooUser, Server.getRemoteIp()); + application.handle(event); + rmDispatcher.await(); + assertKilled(application); + + // KILLED => KILLED event RMAppEventType.START + event = new RMAppFailedAttemptEvent(application.getApplicationId(), + RMAppEventType.START, "", false); + application.handle(event); + rmDispatcher.await(); + assertTimesAtFinish(application); + assertAppState(RMAppState.KILLED, application); + } + @Test(timeout = 30000) public void testAppsRecoveringStates() throws Exception { RMState state = new RMState();