|
@@ -25,20 +25,29 @@ import junit.framework.Assert;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.security.SecurityUtilTestHelper;
|
|
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
|
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
|
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.api.records.NodeId;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.Resource;
|
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.Token;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockAM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockAM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockNM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockNM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.MockRM;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.RMContextImpl;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.RMSecretManagerService;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.TestFifoScheduler;
|
|
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.RMApp;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
|
|
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.rmcontainer.RMContainerState;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
|
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.security.RMContainerTokenSecretManager;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
@@ -149,4 +158,92 @@ public class TestContainerAllocation {
|
|
Assert.assertNotNull(containers.get(0).getContainerToken());
|
|
Assert.assertNotNull(containers.get(0).getContainerToken());
|
|
rm1.stop();
|
|
rm1.stop();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testNormalContainerAllocationWhenDNSUnavailable() throws Exception{
|
|
|
|
+ YarnConfiguration conf = new YarnConfiguration();
|
|
|
|
+ MockRM rm1 = new MockRM(conf);
|
|
|
|
+ rm1.start();
|
|
|
|
+ MockNM nm1 = rm1.registerNode("unknownhost: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);
|
|
|
|
+
|
|
|
|
+ // acquire the container.
|
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(true);
|
|
|
|
+ List<Container> containers =
|
|
|
|
+ am1.allocate(new ArrayList<ResourceRequest>(),
|
|
|
|
+ new ArrayList<ContainerId>()).getAllocatedContainers();
|
|
|
|
+ // not able to fetch the container;
|
|
|
|
+ Assert.assertEquals(0, containers.size());
|
|
|
|
+
|
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(false);
|
|
|
|
+ containers =
|
|
|
|
+ am1.allocate(new ArrayList<ResourceRequest>(),
|
|
|
|
+ new ArrayList<ContainerId>()).getAllocatedContainers();
|
|
|
|
+ // should be able to fetch the container;
|
|
|
|
+ Assert.assertEquals(1, containers.size());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private volatile int numRetries = 0;
|
|
|
|
+ private class TestRMSecretManagerService extends RMSecretManagerService {
|
|
|
|
+
|
|
|
|
+ public TestRMSecretManagerService(Configuration conf,
|
|
|
|
+ RMContextImpl rmContext) {
|
|
|
|
+ super(conf, rmContext);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ protected RMContainerTokenSecretManager createContainerTokenSecretManager(
|
|
|
|
+ Configuration conf) {
|
|
|
|
+ return new RMContainerTokenSecretManager(conf) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Token createContainerToken(ContainerId containerId,
|
|
|
|
+ NodeId nodeId, String appSubmitter, Resource capability) {
|
|
|
|
+ numRetries++;
|
|
|
|
+ return super.createContainerToken(containerId, nodeId, appSubmitter,
|
|
|
|
+ capability);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // This is to test fetching AM container will be retried, if AM container is
|
|
|
|
+ // not fetchable since DNS is unavailable causing container token/NMtoken
|
|
|
|
+ // creation failure.
|
|
|
|
+ @Test(timeout = 20000)
|
|
|
|
+ public void testAMContainerAllocationWhenDNSUnavailable() throws Exception {
|
|
|
|
+ final YarnConfiguration conf = new YarnConfiguration();
|
|
|
|
+ MockRM rm1 = new MockRM(conf) {
|
|
|
|
+ @Override
|
|
|
|
+ protected RMSecretManagerService createRMSecretManagerService() {
|
|
|
|
+ return new TestRMSecretManagerService(conf, rmContext);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ rm1.start();
|
|
|
|
+
|
|
|
|
+ MockNM nm1 = rm1.registerNode("unknownhost:1234", 8000);
|
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(true);
|
|
|
|
+ RMApp app1 = rm1.submitApp(200);
|
|
|
|
+ RMAppAttempt attempt = app1.getCurrentAppAttempt();
|
|
|
|
+ nm1.nodeHeartbeat(true);
|
|
|
|
+
|
|
|
|
+ // fetching am container will fail, keep retrying 5 times.
|
|
|
|
+ while (numRetries <= 5) {
|
|
|
|
+ nm1.nodeHeartbeat(true);
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ Assert.assertEquals(RMAppAttemptState.SCHEDULED,
|
|
|
|
+ attempt.getAppAttemptState());
|
|
|
|
+ System.out.println("Waiting for am container to be allocated.");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(false);
|
|
|
|
+ rm1.waitForState(attempt.getAppAttemptId(), RMAppAttemptState.ALLOCATED);
|
|
|
|
+ MockRM.launchAndRegisterAM(app1, rm1, nm1);
|
|
|
|
+ }
|
|
}
|
|
}
|