|
@@ -21,15 +21,19 @@ package org.apache.hadoop.yarn.server.resourcemanager;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
+import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
|
|
|
import org.apache.hadoop.yarn.api.records.Container;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerStatus;
|
|
|
+import org.apache.hadoop.yarn.api.records.NodeId;
|
|
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.InvalidApplicationMasterRequestException;
|
|
@@ -71,6 +75,7 @@ public class TestWorkPreservingUnmanagedAM
|
|
|
MockNM nm =
|
|
|
new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
|
|
|
nm.registerNode();
|
|
|
+ Set<NodeId> tokenCacheClientSide = new HashSet();
|
|
|
|
|
|
// create app and launch the UAM
|
|
|
boolean unamanged = true;
|
|
@@ -98,14 +103,19 @@ public class TestWorkPreservingUnmanagedAM
|
|
|
|
|
|
// Allocate two containers to UAM
|
|
|
int numContainers = 3;
|
|
|
- List<Container> conts = am.allocate("127.0.0.1", 1000, numContainers,
|
|
|
- new ArrayList<ContainerId>()).getAllocatedContainers();
|
|
|
+ AllocateResponse allocateResponse =
|
|
|
+ am.allocate("127.0.0.1", 1000, numContainers, new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ List<Container> conts = allocateResponse.getAllocatedContainers();
|
|
|
while (conts.size() < numContainers) {
|
|
|
nm.nodeHeartbeat(true);
|
|
|
- conts.addAll(am.allocate(new ArrayList<ResourceRequest>(),
|
|
|
- new ArrayList<ContainerId>()).getAllocatedContainers());
|
|
|
+ allocateResponse =
|
|
|
+ am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts.addAll(allocateResponse.getAllocatedContainers());
|
|
|
Thread.sleep(100);
|
|
|
}
|
|
|
+ checkNMTokenForContainer(tokenCacheClientSide, conts);
|
|
|
|
|
|
// Release one container
|
|
|
List<ContainerId> releaseList =
|
|
@@ -127,6 +137,10 @@ public class TestWorkPreservingUnmanagedAM
|
|
|
RegisterApplicationMasterResponse response = null;
|
|
|
try {
|
|
|
response = am.registerAppAttempt(false);
|
|
|
+ // When AM restart, it means nmToken in client side should be missing
|
|
|
+ tokenCacheClientSide.clear();
|
|
|
+ response.getNMTokensFromPreviousAttempts()
|
|
|
+ .forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
} catch (InvalidApplicationMasterRequestException e) {
|
|
|
Assert.assertEquals(false, keepContainers);
|
|
|
return;
|
|
@@ -142,14 +156,124 @@ public class TestWorkPreservingUnmanagedAM
|
|
|
numContainers = 1;
|
|
|
am.allocate("127.0.0.1", 1000, numContainers, new ArrayList<ContainerId>());
|
|
|
nm.nodeHeartbeat(true);
|
|
|
- conts = am.allocate(new ArrayList<ResourceRequest>(),
|
|
|
- new ArrayList<ContainerId>()).getAllocatedContainers();
|
|
|
+ allocateResponse = am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts = allocateResponse.getAllocatedContainers();
|
|
|
while (conts.size() < numContainers) {
|
|
|
nm.nodeHeartbeat(true);
|
|
|
- conts.addAll(am.allocate(new ArrayList<ResourceRequest>(),
|
|
|
- new ArrayList<ContainerId>()).getAllocatedContainers());
|
|
|
+ allocateResponse =
|
|
|
+ am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts.addAll(allocateResponse.getAllocatedContainers());
|
|
|
Thread.sleep(100);
|
|
|
}
|
|
|
+ checkNMTokenForContainer(tokenCacheClientSide, conts);
|
|
|
+
|
|
|
+ rm.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void testUAMRestartWithoutTransferContainer(boolean keepContainers) throws Exception {
|
|
|
+ // start RM
|
|
|
+ MockRM rm = new MockRM();
|
|
|
+ rm.start();
|
|
|
+ MockNM nm =
|
|
|
+ new MockNM("127.0.0.1:1234", 15120, rm.getResourceTrackerService());
|
|
|
+ nm.registerNode();
|
|
|
+ Set<NodeId> tokenCacheClientSide = new HashSet();
|
|
|
+
|
|
|
+ // create app and launch the UAM
|
|
|
+ boolean unamanged = true;
|
|
|
+ int maxAttempts = 1;
|
|
|
+ boolean waitForAccepted = true;
|
|
|
+ MockRMAppSubmissionData data =
|
|
|
+ MockRMAppSubmissionData.Builder.createWithMemory(200, rm)
|
|
|
+ .withAppName("")
|
|
|
+ .withUser(UserGroupInformation.getCurrentUser().getShortUserName())
|
|
|
+ .withAcls(null)
|
|
|
+ .withUnmanagedAM(unamanged)
|
|
|
+ .withQueue(null)
|
|
|
+ .withMaxAppAttempts(maxAttempts)
|
|
|
+ .withCredentials(null)
|
|
|
+ .withAppType(null)
|
|
|
+ .withWaitForAppAcceptedState(waitForAccepted)
|
|
|
+ .withKeepContainers(keepContainers)
|
|
|
+ .build();
|
|
|
+ RMApp app = MockRMAppSubmitter.submit(rm, data);
|
|
|
+
|
|
|
+ MockAM am = MockRM.launchUAM(app, rm, nm);
|
|
|
+
|
|
|
+ // Register for the first time
|
|
|
+ am.registerAppAttempt();
|
|
|
+
|
|
|
+ // Allocate two containers to UAM
|
|
|
+ int numContainers = 3;
|
|
|
+ AllocateResponse allocateResponse =
|
|
|
+ am.allocate("127.0.0.1", 1000, numContainers, new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ List<Container> conts = allocateResponse.getAllocatedContainers();
|
|
|
+ while (conts.size() < numContainers) {
|
|
|
+ nm.nodeHeartbeat(true);
|
|
|
+ allocateResponse =
|
|
|
+ am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts.addAll(allocateResponse.getAllocatedContainers());
|
|
|
+ Thread.sleep(100);
|
|
|
+ }
|
|
|
+ checkNMTokenForContainer(tokenCacheClientSide, conts);
|
|
|
+
|
|
|
+ // Release all containers, then there are no transfer containfer app attempt
|
|
|
+ List<ContainerId> releaseList = new ArrayList();
|
|
|
+ releaseList.add(conts.get(0).getId());
|
|
|
+ releaseList.add(conts.get(1).getId());
|
|
|
+ releaseList.add(conts.get(2).getId());
|
|
|
+ List<ContainerStatus> finishedConts =
|
|
|
+ am.allocate(new ArrayList<ResourceRequest>(), releaseList)
|
|
|
+ .getCompletedContainersStatuses();
|
|
|
+ while (finishedConts.size() < releaseList.size()) {
|
|
|
+ nm.nodeHeartbeat(true);
|
|
|
+ finishedConts
|
|
|
+ .addAll(am
|
|
|
+ .allocate(new ArrayList<ResourceRequest>(),
|
|
|
+ new ArrayList<ContainerId>())
|
|
|
+ .getCompletedContainersStatuses());
|
|
|
+ Thread.sleep(100);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Register for the second time
|
|
|
+ RegisterApplicationMasterResponse response = null;
|
|
|
+ try {
|
|
|
+ response = am.registerAppAttempt(false);
|
|
|
+ // When AM restart, it means nmToken in client side should be missing
|
|
|
+ tokenCacheClientSide.clear();
|
|
|
+ response.getNMTokensFromPreviousAttempts()
|
|
|
+ .forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ } catch (InvalidApplicationMasterRequestException e) {
|
|
|
+ Assert.assertEquals(false, keepContainers);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Assert.assertEquals("RM should not allow second register"
|
|
|
+ + " for UAM without keep container flag ", true, keepContainers);
|
|
|
+
|
|
|
+ // Expecting the zero running containers previously
|
|
|
+ Assert.assertEquals(0, response.getContainersFromPreviousAttempts().size());
|
|
|
+ Assert.assertEquals(0, response.getNMTokensFromPreviousAttempts().size());
|
|
|
+
|
|
|
+ // Allocate one more containers to UAM, just to be safe
|
|
|
+ numContainers = 1;
|
|
|
+ am.allocate("127.0.0.1", 1000, numContainers, new ArrayList<ContainerId>());
|
|
|
+ nm.nodeHeartbeat(true);
|
|
|
+ allocateResponse = am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts = allocateResponse.getAllocatedContainers();
|
|
|
+ while (conts.size() < numContainers) {
|
|
|
+ nm.nodeHeartbeat(true);
|
|
|
+ allocateResponse =
|
|
|
+ am.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>());
|
|
|
+ allocateResponse.getNMTokens().forEach(token -> tokenCacheClientSide.add(token.getNodeId()));
|
|
|
+ conts.addAll(allocateResponse.getAllocatedContainers());
|
|
|
+ Thread.sleep(100);
|
|
|
+ }
|
|
|
+ checkNMTokenForContainer(tokenCacheClientSide, conts);
|
|
|
|
|
|
rm.stop();
|
|
|
}
|
|
@@ -164,4 +288,19 @@ public class TestWorkPreservingUnmanagedAM
|
|
|
testUAMRestart(false);
|
|
|
}
|
|
|
|
|
|
+ @Test(timeout = 600000)
|
|
|
+ public void testUAMRestartKeepContainersWithoutTransferContainer() throws Exception {
|
|
|
+ testUAMRestartWithoutTransferContainer(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(timeout = 600000)
|
|
|
+ public void testUAMRestartNoKeepContainersWithoutTransferContainer() throws Exception {
|
|
|
+ testUAMRestartWithoutTransferContainer(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkNMTokenForContainer(Set<NodeId> cacheToken, List<Container> containers) {
|
|
|
+ for (Container container : containers) {
|
|
|
+ Assert.assertTrue(cacheToken.contains(container.getNodeId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|