|
@@ -19,6 +19,8 @@ package org.apache.hadoop.yarn.sls.nodemanager;
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
import java.util.function.Supplier;
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.Container;
|
|
import org.apache.hadoop.yarn.api.records.Container;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
@@ -109,7 +111,7 @@ public class TestNMSimulator {
|
|
ContainerId cId1 = newContainerId(1, 1, 1);
|
|
ContainerId cId1 = newContainerId(1, 1, 1);
|
|
Container container1 = Container.newInstance(cId1, null, null,
|
|
Container container1 = Container.newInstance(cId1, null, null,
|
|
Resources.createResource(GB, 1), null, null);
|
|
Resources.createResource(GB, 1), null, null);
|
|
- node1.addNewContainer(container1, 100000l);
|
|
|
|
|
|
+ node1.addNewContainer(container1, 100000l, null);
|
|
Assert.assertTrue("Node1 should have one running container.",
|
|
Assert.assertTrue("Node1 should have one running container.",
|
|
node1.getRunningContainers().containsKey(cId1));
|
|
node1.getRunningContainers().containsKey(cId1));
|
|
|
|
|
|
@@ -117,7 +119,7 @@ public class TestNMSimulator {
|
|
ContainerId cId2 = newContainerId(2, 1, 1);
|
|
ContainerId cId2 = newContainerId(2, 1, 1);
|
|
Container container2 = Container.newInstance(cId2, null, null,
|
|
Container container2 = Container.newInstance(cId2, null, null,
|
|
Resources.createResource(GB, 1), null, null);
|
|
Resources.createResource(GB, 1), null, null);
|
|
- node1.addNewContainer(container2, -1l);
|
|
|
|
|
|
+ node1.addNewContainer(container2, -1l, null);
|
|
Assert.assertTrue("Node1 should have one running AM container",
|
|
Assert.assertTrue("Node1 should have one running AM container",
|
|
node1.getAMContainers().contains(cId2));
|
|
node1.getAMContainers().contains(cId2));
|
|
|
|
|
|
@@ -137,6 +139,100 @@ public class TestNMSimulator {
|
|
appAttemptId), cId);
|
|
appAttemptId), cId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testNMSimAppAddedAndRemoved() throws Exception {
|
|
|
|
+ // Register one node
|
|
|
|
+ NMSimulator node = new NMSimulator();
|
|
|
|
+ node.init("/rack1/node1", Resources.createResource(GB * 10, 10), 0, 1000,
|
|
|
|
+ rm, -1f);
|
|
|
|
+ node.middleStep();
|
|
|
|
+
|
|
|
|
+ int numClusterNodes = rm.getResourceScheduler().getNumClusterNodes();
|
|
|
|
+ int cumulativeSleepTime = 0;
|
|
|
|
+ int sleepInterval = 100;
|
|
|
|
+
|
|
|
|
+ while (numClusterNodes != 1 && cumulativeSleepTime < 5000) {
|
|
|
|
+ Thread.sleep(sleepInterval);
|
|
|
|
+ cumulativeSleepTime = cumulativeSleepTime + sleepInterval;
|
|
|
|
+ numClusterNodes = rm.getResourceScheduler().getNumClusterNodes();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GenericTestUtils.waitFor(new com.google.common.base.Supplier<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean get() {
|
|
|
|
+ return rm.getResourceScheduler().getRootQueueMetrics()
|
|
|
|
+ .getAvailableMB() > 0;
|
|
|
|
+ }
|
|
|
|
+ }, 500, 10000);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("Node should have no runningApps.",
|
|
|
|
+ node.getNode().getRunningApps().size(), 0);
|
|
|
|
+
|
|
|
|
+ // Allocate one app container on node
|
|
|
|
+ ApplicationId appId = BuilderUtils.newApplicationId(1, 1);
|
|
|
|
+ ApplicationAttemptId appAttemptId =
|
|
|
|
+ BuilderUtils.newApplicationAttemptId(appId, 1);
|
|
|
|
+ ContainerId cId = BuilderUtils.newContainerId(appAttemptId, 1);
|
|
|
|
+ Container container = Container.newInstance(cId, null, null,
|
|
|
|
+ Resources.createResource(GB, 1), null, null);
|
|
|
|
+ node.addNewContainer(container, 100000l, appId);
|
|
|
|
+ Assert.assertTrue("Node should have app: "
|
|
|
|
+ + appId + " in runningApps list.",
|
|
|
|
+ node.getNode().getRunningApps().contains(appId));
|
|
|
|
+
|
|
|
|
+ // Finish the app on the node.
|
|
|
|
+ node.finishApplication(appId);
|
|
|
|
+ Assert.assertFalse("Node should not have app: "
|
|
|
|
+ + appId + " in runningApps list.",
|
|
|
|
+ node.getNode().getRunningApps().contains(appId));
|
|
|
|
+ Assert.assertEquals("Node should have no runningApps.",
|
|
|
|
+ node.getNode().getRunningApps().size(), 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNMSimNullAppAddedAndRemoved() throws Exception {
|
|
|
|
+ // Register one node
|
|
|
|
+ NMSimulator node = new NMSimulator();
|
|
|
|
+ node.init("/rack1/node1", Resources.createResource(GB * 10, 10), 0, 1000,
|
|
|
|
+ rm, -1f);
|
|
|
|
+ node.middleStep();
|
|
|
|
+
|
|
|
|
+ int numClusterNodes = rm.getResourceScheduler().getNumClusterNodes();
|
|
|
|
+ int cumulativeSleepTime = 0;
|
|
|
|
+ int sleepInterval = 100;
|
|
|
|
+
|
|
|
|
+ while (numClusterNodes != 1 && cumulativeSleepTime < 5000) {
|
|
|
|
+ Thread.sleep(sleepInterval);
|
|
|
|
+ cumulativeSleepTime = cumulativeSleepTime + sleepInterval;
|
|
|
|
+ numClusterNodes = rm.getResourceScheduler().getNumClusterNodes();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GenericTestUtils.waitFor(new com.google.common.base.Supplier<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean get() {
|
|
|
|
+ return rm.getResourceScheduler().getRootQueueMetrics()
|
|
|
|
+ .getAvailableMB() > 0;
|
|
|
|
+ }
|
|
|
|
+ }, 500, 10000);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("Node should have no runningApps.",
|
|
|
|
+ node.getNode().getRunningApps().size(), 0);
|
|
|
|
+
|
|
|
|
+ // Allocate null app container on node
|
|
|
|
+ ContainerId cId = newContainerId(1, 1, 1);
|
|
|
|
+ Container container = Container.newInstance(cId, null, null,
|
|
|
|
+ Resources.createResource(GB, 1), null, null);
|
|
|
|
+ node.addNewContainer(container, 100000l, null);
|
|
|
|
+ Assert.assertEquals("Node should have no runningApps if appId is null.",
|
|
|
|
+ node.getNode().getRunningApps().size(), 0);
|
|
|
|
+
|
|
|
|
+ // Finish non-existent app on the node.
|
|
|
|
+ ApplicationId appId = BuilderUtils.newApplicationId(1, 1);
|
|
|
|
+ node.finishApplication(appId);
|
|
|
|
+ Assert.assertEquals("Node should have no runningApps.",
|
|
|
|
+ node.getNode().getRunningApps().size(), 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
@After
|
|
@After
|
|
public void tearDown() throws Exception {
|
|
public void tearDown() throws Exception {
|
|
rm.stop();
|
|
rm.stop();
|