|
@@ -18,19 +18,14 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.rmapp;
|
|
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
-import static org.junit.Assume.assumeTrue;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.times;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
|
|
|
import junit.framework.Assert;
|
|
|
|
|
@@ -41,13 +36,10 @@ import org.apache.hadoop.security.SecurityUtil;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
|
|
|
import org.apache.hadoop.yarn.MockApps;
|
|
|
-import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
|
|
-import org.apache.hadoop.yarn.api.records.Container;
|
|
|
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
|
|
|
-import org.apache.hadoop.yarn.api.records.Resource;
|
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationSubmissionContextPBImpl;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.event.DrainDispatcher;
|
|
@@ -64,11 +56,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEvent;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEventType;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState;
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.event.RMAppAttemptContainerAllocatedEvent;
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.event.RMAppAttemptNewSavedEvent;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.event.RMAppAttemptUpdateSavedEvent;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.ContainerAllocationExpirer;
|
|
|
-import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType;
|
|
@@ -76,7 +65,6 @@ import org.apache.hadoop.yarn.server.resourcemanager.security.AMRMTokenSecretMan
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.security.ClientToAMTokenSecretManagerInRM;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.security.NMTokenSecretManagerInRM;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
|
|
-import org.apache.hadoop.yarn.server.utils.BuilderUtils;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
@@ -290,7 +278,6 @@ public class TestRMAppTransitions {
|
|
|
|
|
|
// 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 +290,6 @@ public class TestRMAppTransitions {
|
|
|
}
|
|
|
|
|
|
private void assertKilled(RMApp application) {
|
|
|
- sendAppUpdateSavedEvent(application);
|
|
|
assertTimesAtFinish(application);
|
|
|
assertAppState(RMAppState.KILLED, application);
|
|
|
assertFinalAppStatus(FinalApplicationStatus.KILLED, application);
|
|
@@ -314,6 +300,7 @@ public class TestRMAppTransitions {
|
|
|
|
|
|
private void assertAppAndAttemptKilled(RMApp application)
|
|
|
throws InterruptedException {
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertKilled(application);
|
|
|
// send attempt final state saved event.
|
|
|
application.getCurrentAppAttempt().handle(
|
|
@@ -325,7 +312,6 @@ public class TestRMAppTransitions {
|
|
|
}
|
|
|
|
|
|
private void assertFailed(RMApp application, String regex) {
|
|
|
- sendAppUpdateSavedEvent(application);
|
|
|
assertTimesAtFinish(application);
|
|
|
assertAppState(RMAppState.FAILED, application);
|
|
|
assertFinalAppStatus(FinalApplicationStatus.FAILED, application);
|
|
@@ -475,6 +461,7 @@ public class TestRMAppTransitions {
|
|
|
rmDispatcher.await();
|
|
|
RMAppAttempt appAttempt = application.getCurrentAppAttempt();
|
|
|
Assert.assertEquals(1, appAttempt.getAppAttemptId().getAttemptId());
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application,
|
|
|
".*Unmanaged application.*Failing the application.*");
|
|
|
}
|
|
@@ -504,6 +491,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertKilled(application);
|
|
|
}
|
|
|
|
|
@@ -518,6 +506,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppRejectedEvent(application.getApplicationId(), rejectedText);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application, rejectedText);
|
|
|
}
|
|
|
|
|
@@ -531,6 +520,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertKilled(application);
|
|
|
}
|
|
|
|
|
@@ -545,6 +535,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppRejectedEvent(application.getApplicationId(), rejectedText);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application, rejectedText);
|
|
|
}
|
|
|
|
|
@@ -559,6 +550,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppRejectedEvent(application.getApplicationId(), rejectedText);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application, rejectedText);
|
|
|
}
|
|
|
|
|
@@ -603,6 +595,7 @@ public class TestRMAppTransitions {
|
|
|
RMAppEventType.ATTEMPT_FAILED, message);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application, ".*" + message + ".*Failing the application.*");
|
|
|
}
|
|
|
|
|
@@ -635,7 +628,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppFinishedAttemptEvent(application.getApplicationId(), null);
|
|
|
application.handle(finishEvent);
|
|
|
assertAppState(RMAppState.FINAL_SAVING, application);
|
|
|
-
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertKilled(application);
|
|
|
}
|
|
|
|
|
@@ -681,6 +674,7 @@ public class TestRMAppTransitions {
|
|
|
RMAppEventType.ATTEMPT_FAILED, "");
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertFailed(application, ".*Failing the application.*");
|
|
|
|
|
|
// FAILED => FAILED event RMAppEventType.KILL
|
|
@@ -758,6 +752,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppRejectedEvent(application.getApplicationId(), "");
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertTimesAtFinish(application);
|
|
|
assertAppState(RMAppState.FAILED, application);
|
|
|
|
|
@@ -769,10 +764,6 @@ public class TestRMAppTransitions {
|
|
|
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 +779,7 @@ public class TestRMAppTransitions {
|
|
|
new RMAppEvent(application.getApplicationId(), RMAppEventType.KILL);
|
|
|
application.handle(event);
|
|
|
rmDispatcher.await();
|
|
|
+ sendAppUpdateSavedEvent(application);
|
|
|
assertTimesAtFinish(application);
|
|
|
assertAppState(RMAppState.KILLED, application);
|
|
|
|
|
@@ -824,10 +816,6 @@ public class TestRMAppTransitions {
|
|
|
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);
|
|
|
}
|
|
@@ -841,70 +829,4 @@ public class TestRMAppTransitions {
|
|
|
report = app.createAndGetApplicationReport("clientuser", true);
|
|
|
Assert.assertNotNull(report.getApplicationResourceUsageReport());
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testClientTokens() throws Exception {
|
|
|
- assumeTrue(isSecurityEnabled);
|
|
|
-
|
|
|
- RMApp app = createNewTestApp(null);
|
|
|
- assertAppState(RMAppState.NEW, app);
|
|
|
- ApplicationReport report = app.createAndGetApplicationReport(null, true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
- report = app.createAndGetApplicationReport("clientuser", true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
-
|
|
|
- app = testCreateAppRunning(null);
|
|
|
- rmDispatcher.await();
|
|
|
- assertAppState(RMAppState.RUNNING, app);
|
|
|
-
|
|
|
- report = app.createAndGetApplicationReport("clientuser", true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
-
|
|
|
- // this method is to make AMLaunchedTransition invoked inside which
|
|
|
- // ClientTokenMasterKey is registered in ClientTokenSecretManager
|
|
|
- moveCurrentAttemptToLaunchedState(app.getCurrentAppAttempt());
|
|
|
-
|
|
|
- report = app.createAndGetApplicationReport(null, true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
- report = app.createAndGetApplicationReport("clientuser", true);
|
|
|
- Assert.assertNotNull(report.getClientToAMToken());
|
|
|
-
|
|
|
- // kill the app attempt and verify client token is unavailable
|
|
|
- app.handle(new RMAppEvent(app.getApplicationId(), RMAppEventType.KILL));
|
|
|
- rmDispatcher.await();
|
|
|
- assertAppAndAttemptKilled(app);
|
|
|
- report = app.createAndGetApplicationReport(null, true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
- report = app.createAndGetApplicationReport("clientuser", true);
|
|
|
- Assert.assertNull(report.getClientToAMToken());
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private void moveCurrentAttemptToLaunchedState(RMAppAttempt attempt) {
|
|
|
- attempt.handle(new RMAppAttemptEvent(attempt.getAppAttemptId(),
|
|
|
- RMAppAttemptEventType.APP_ACCEPTED));
|
|
|
- // Mock the allocation of AM container
|
|
|
- Container container = mock(Container.class);
|
|
|
- Resource resource = BuilderUtils.newResource(2048, 1);
|
|
|
- when(container.getId()).thenReturn(
|
|
|
- BuilderUtils.newContainerId(attempt.getAppAttemptId(), 1));
|
|
|
- when(container.getResource()).thenReturn(resource);
|
|
|
- Allocation allocation = mock(Allocation.class);
|
|
|
- when(allocation.getContainers()).thenReturn(
|
|
|
- Collections.singletonList(container));
|
|
|
- when(allocation.getContainers()).
|
|
|
- thenReturn(Collections.singletonList(container));
|
|
|
- when(
|
|
|
- scheduler.allocate(any(ApplicationAttemptId.class), any(List.class),
|
|
|
- any(List.class), any(List.class), any(List.class))).thenReturn(
|
|
|
- allocation);
|
|
|
- attempt.handle(new RMAppAttemptContainerAllocatedEvent(attempt
|
|
|
- .getAppAttemptId(), container));
|
|
|
- attempt
|
|
|
- .handle(new RMAppAttemptNewSavedEvent(attempt.getAppAttemptId(), null));
|
|
|
- attempt.handle(new RMAppAttemptEvent(attempt.getAppAttemptId(),
|
|
|
- RMAppAttemptEventType.LAUNCHED));
|
|
|
-
|
|
|
- assertEquals(RMAppAttemptState.LAUNCHED, attempt.getAppAttemptState());
|
|
|
- }
|
|
|
}
|