diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java 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 1686836..76d59ec 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java @@ -130,7 +130,7 @@ .addTransition(RMAppState.NEW, RMAppState.NEW, RMAppEventType.NODE_UPDATE, new RMAppNodeUpdateTransition()) .addTransition(RMAppState.NEW, RMAppState.NEW_SAVING, - RMAppEventType.START, new RMAppSavingTransition()) + RMAppEventType.START, new RMAppNewlySavingTransition()) .addTransition(RMAppState.NEW, EnumSet.of(RMAppState.SUBMITTED, RMAppState.RUNNING, RMAppState.FINISHED, RMAppState.FAILED, RMAppState.KILLED, RMAppState.FINAL_SAVING), @@ -215,7 +215,8 @@ new AttemptFinishedAtFinalSavingTransition()) // ignorable transitions .addTransition(RMAppState.FINAL_SAVING, RMAppState.FINAL_SAVING, - EnumSet.of(RMAppEventType.NODE_UPDATE, RMAppEventType.KILL)) + EnumSet.of(RMAppEventType.NODE_UPDATE, RMAppEventType.KILL, + RMAppEventType.APP_NEW_SAVED)) // Transitions from FINISHING state .addTransition(RMAppState.FINISHING, RMAppState.FINISHED, @@ -760,7 +761,7 @@ private String getAppAttemptFailedDiagnostics(RMAppEvent event) { return msg; } - private static final class RMAppSavingTransition extends RMAppTransition { + private static final class RMAppNewlySavingTransition extends RMAppTransition { @Override public void transition(RMAppImpl app, RMAppEvent event) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java 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 b5f4992..b69db74 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestRMAppTransitions.java @@ -290,7 +290,6 @@ private static void assertFinalAppStatus(FinalApplicationStatus status, RMApp ap // test to make sure times are set when app finishes private void assertTimesAtFinish(RMApp application) { - sendAppUpdateSavedEvent(application); assertStartTimeSet(application); Assert.assertTrue("application finish time is not greater then 0", (application.getFinishTime() > 0)); @@ -303,7 +302,6 @@ private void assertAppFinalStateSaved(RMApp application){ } private void assertKilled(RMApp application) { - sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); assertFinalAppStatus(FinalApplicationStatus.KILLED, application); @@ -314,6 +312,7 @@ private void assertKilled(RMApp application) { private void assertAppAndAttemptKilled(RMApp application) throws InterruptedException { + sendAppUpdateSavedEvent(application); assertKilled(application); // send attempt final state saved event. application.getCurrentAppAttempt().handle( @@ -325,7 +324,6 @@ private void assertAppAndAttemptKilled(RMApp application) } private void assertFailed(RMApp application, String regex) { - sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); assertFinalAppStatus(FinalApplicationStatus.FAILED, application); @@ -475,6 +473,7 @@ public void testUnmanagedApp() throws IOException { rmDispatcher.await(); RMAppAttempt appAttempt = application.getCurrentAppAttempt(); Assert.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId()); + sendAppUpdateSavedEvent(application); assertFailed(application, ".*Unmanaged application.*Failing the application.*"); } @@ -504,6 +503,7 @@ public void testAppNewKill() throws IOException { new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertKilled(application); } @@ -518,6 +518,7 @@ public void testAppNewReject() throws IOException { new RMAppRejectedEvent(application.getApplicationId(), rejectedText); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); } @@ -531,6 +532,7 @@ public void testAppNewSavingKill() throws IOException { new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertKilled(application); } @@ -545,6 +547,7 @@ public void testAppNewSavingReject() throws IOException { new RMAppRejectedEvent(application.getApplicationId(), rejectedText); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); } @@ -559,6 +562,7 @@ public void testAppSubmittedRejected() throws IOException { new RMAppRejectedEvent(application.getApplicationId(), rejectedText); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertFailed(application, rejectedText); } @@ -603,6 +607,7 @@ public void testAppAcceptedFailed() throws IOException { RMAppEventType.ATTEMPT_FAILED, message); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertFailed(application, ".*" + message + ".*Failing the application.*"); } @@ -635,7 +640,7 @@ public void testAppRunningKill() throws IOException { new RMAppFinishedAttemptEvent(application.getApplicationId(), null); application.handle(finishEvent); assertAppState(RMAppState.FINAL_SAVING, application); - + sendAppUpdateSavedEvent(application); assertKilled(application); } @@ -681,6 +686,7 @@ public void testAppRunningFailed() throws IOException { RMAppEventType.ATTEMPT_FAILED, ""); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertFailed(application, ".*Failing the application.*"); // FAILED => FAILED event RMAppEventType.KILL @@ -758,6 +764,7 @@ public void testAppFailedFailed() throws IOException { new RMAppRejectedEvent(application.getApplicationId(), ""); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); @@ -769,10 +776,6 @@ public void testAppFailedFailed() throws IOException { assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); - // FAILED => FAILED event RMAppEventType.APP_SAVED - event = new RMAppNewSavedEvent(application.getApplicationId(), null); - application.handle(event); - rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.FAILED, application); } @@ -788,6 +791,7 @@ public void testAppKilledKilled() throws IOException { new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL); application.handle(event); rmDispatcher.await(); + sendAppUpdateSavedEvent(application); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); @@ -824,10 +828,6 @@ public void testAppKilledKilled() throws IOException { assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); - // KILLED => KILLED event RMAppEventType.APP_SAVED - event = new RMAppNewSavedEvent(application.getApplicationId(), null); - application.handle(event); - rmDispatcher.await(); assertTimesAtFinish(application); assertAppState(RMAppState.KILLED, application); } @@ -842,8 +842,11 @@ public void testGetAppReport() { Assert.assertNotNull(report.getApplicationResourceUsageReport()); } + // this is to test user can get client tokens only after the client token + // master key is saved in the state store and also registered in + // ClientTokenSecretManager @Test - public void testClientTokens() throws Exception { + public void testGetClientToken() throws Exception { assumeTrue(isSecurityEnabled); RMApp app = createNewTestApp(null); @@ -857,11 +860,13 @@ public void testClientTokens() throws Exception { rmDispatcher.await(); assertAppState(RMAppState.RUNNING, app); + // before ClientTokenMasterKey is registered, can not get client token report = app.createAndGetApplicationReport("clientuser", true); Assert.assertNull(report.getClientToAMToken()); // this method is to make AMLaunchedTransition invoked inside which - // ClientTokenMasterKey is registered in ClientTokenSecretManager + // ClientTokenMasterKey is registered in ClientTokenSecretManager, which + // also means the key has been saved in the state store. moveCurrentAttemptToLaunchedState(app.getCurrentAppAttempt()); report = app.createAndGetApplicationReport(null, true);