|
@@ -18,11 +18,17 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import junit.framework.Assert;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
|
|
+import org.apache.hadoop.yarn.api.records.Container;
|
|
|
+import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
+import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockAM;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockNM;
|
|
@@ -30,6 +36,9 @@ import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.TestFifoScheduler;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerState;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
@@ -106,4 +115,38 @@ public class TestContainerAllocation {
|
|
|
|
|
|
rm.stop();
|
|
|
}
|
|
|
+
|
|
|
+ // This is to test container tokens are generated when the containers are
|
|
|
+ // acquired by the AM, not when the containers are allocated
|
|
|
+ @Test
|
|
|
+ public void testContainerTokenGeneratedOnPullRequest() throws Exception {
|
|
|
+ YarnConfiguration conf = new YarnConfiguration();
|
|
|
+ conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
|
|
|
+ ResourceScheduler.class);
|
|
|
+ MockRM rm1 = new MockRM(conf);
|
|
|
+ rm1.start();
|
|
|
+ MockNM nm1 = rm1.registerNode("127.0.0.1:1234", 8000);
|
|
|
+ RMApp app1 = rm1.submitApp(200);
|
|
|
+ MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
|
|
|
+ // request a container.
|
|
|
+ am1.allocate("127.0.0.1", 1024, 1, new ArrayList<ContainerId>());
|
|
|
+ ContainerId containerId2 =
|
|
|
+ ContainerId.newInstance(am1.getApplicationAttemptId(), 2);
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED);
|
|
|
+
|
|
|
+ RMContainer container =
|
|
|
+ rm1.getResourceScheduler().getRMContainer(containerId2);
|
|
|
+ // no container token is generated.
|
|
|
+ Assert.assertEquals(containerId2, container.getContainerId());
|
|
|
+ Assert.assertNull(container.getContainer().getContainerToken());
|
|
|
+
|
|
|
+ // acquire the container.
|
|
|
+ List<Container> containers =
|
|
|
+ am1.allocate(new ArrayList<ResourceRequest>(),
|
|
|
+ new ArrayList<ContainerId>()).getAllocatedContainers();
|
|
|
+ Assert.assertEquals(containerId2, containers.get(0).getId());
|
|
|
+ // container token is generated.
|
|
|
+ Assert.assertNotNull(containers.get(0).getContainerToken());
|
|
|
+ rm1.stop();
|
|
|
+ }
|
|
|
}
|