From c8927898960befb843dab17075813e168f659b68 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Tue, 9 Jan 2018 10:51:15 -0600 Subject: [PATCH] YARN-6948. Invalid event: ATTEMPT_ADDED at FINAL_SAVING. Contributed by lujie (cherry picked from commit 90c86d6e090d668414681fcb5eb02add5d419b33) Conflicts: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java --- .../rmapp/attempt/RMAppAttemptImpl.java | 10 +++++-- .../attempt/TestRMAppAttemptTransitions.java | 27 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 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/attempt/RMAppAttemptImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java index 5bfb8b98061..07f949d29e9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java @@ -416,7 +416,8 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable { RMAppAttemptEventType.CONTAINER_ALLOCATED, RMAppAttemptEventType.ATTEMPT_NEW_SAVED, RMAppAttemptEventType.KILL, - RMAppAttemptEventType.FAIL)) + RMAppAttemptEventType.FAIL, + RMAppAttemptEventType.ATTEMPT_ADDED)) // Transitions from FAILED State // For work-preserving AM restart, failed attempt are still capturing @@ -908,7 +909,7 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable { } catch (InvalidStateTransitionException e) { LOG.error("App attempt: " + appAttemptID + " can't handle this event at current state", e); - /* TODO fail the application on the failed transition */ + onInvalidTranstion(event.getType(), oldState); } // Log at INFO if we're not recovering or not in a terminal state. @@ -2281,6 +2282,11 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable { return Collections.EMPTY_SET; } + protected void onInvalidTranstion(RMAppAttemptEventType rmAppAttemptEventType, + RMAppAttemptState state){ + /* TODO fail the application on the failed transition */ + } + /** * A {@link CharSequence} appender that considers its {@link #limit} as upper * bound. 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/attempt/TestRMAppAttemptTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java index 9dd57034438..0e4f30810b0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java @@ -327,7 +327,15 @@ public class TestRMAppAttemptTransitions { masterService, submissionContext, new Configuration(), Collections.singletonList(BuilderUtils.newResourceRequest( RMAppAttemptImpl.AM_CONTAINER_PRIORITY, ResourceRequest.ANY, - submissionContext.getResource(), 1)), application); + submissionContext.getResource(), 1)), application) { + @Override + protected void onInvalidTranstion( + RMAppAttemptEventType rmAppAttemptEventType, + RMAppAttemptState state) { + Assert.assertTrue("RMAppAttemptImpl can't handle " + + rmAppAttemptEventType + " at state " + state, false); + } + }; when(application.getCurrentAppAttempt()).thenReturn(applicationAttempt); when(application.getApplicationId()).thenReturn(applicationId); @@ -974,6 +982,23 @@ public class TestRMAppAttemptTransitions { applicationAttempt.getAppAttemptState()); } + @Test(timeout = 10000) + public void testAttemptAddedAtFinalSaving() { + submitApplicationAttempt(); + + // SUBNITED->FINAL_SAVING + applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt + .getAppAttemptId(), RMAppAttemptEventType.KILL)); + assertEquals(RMAppAttemptState.FINAL_SAVING, + applicationAttempt.getAppAttemptState()); + + applicationAttempt.handle(new RMAppAttemptEvent(applicationAttempt + .getAppAttemptId(), RMAppAttemptEventType.ATTEMPT_ADDED)); + + assertEquals(RMAppAttemptState.FINAL_SAVING, + applicationAttempt.getAppAttemptState()); + } + @Test public void testAMCrashAtAllocated() { Container amContainer = allocateApplicationAttempt();