|
@@ -26,6 +26,9 @@ import java.util.Map;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.io.DataOutputBuffer;
|
|
|
+import org.apache.hadoop.security.Credentials;
|
|
|
import org.apache.hadoop.yarn.api.ApplicationConstants;
|
|
|
import org.apache.hadoop.yarn.api.ContainerManagementProtocol;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
|
@@ -38,6 +41,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest;
|
|
|
import org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerState;
|
|
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
|
import org.apache.hadoop.yarn.api.records.SerializedException;
|
|
@@ -47,7 +51,10 @@ import org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException;
|
|
|
import org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.ipc.RPCUtil;
|
|
|
+import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
|
|
|
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.amlauncher.AMLauncher;
|
|
|
+import org.apache.hadoop.yarn.server.resourcemanager.amlauncher.AMLauncherEventType;
|
|
|
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.RMAppAttemptState;
|
|
@@ -238,4 +245,61 @@ public class TestApplicationMasterLauncher {
|
|
|
} catch (ApplicationAttemptNotFoundException e) {
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testSetupTokens() throws Exception {
|
|
|
+ MockRM rm = new MockRM();
|
|
|
+ rm.start();
|
|
|
+ MockNM nm1 = rm.registerNode("h1:1234", 5000);
|
|
|
+ RMApp app = rm.submitApp(2000);
|
|
|
+ /// kick the scheduling
|
|
|
+ nm1.nodeHeartbeat(true);
|
|
|
+ RMAppAttempt attempt = app.getCurrentAppAttempt();
|
|
|
+ MyAMLauncher launcher = new MyAMLauncher(rm.getRMContext(),
|
|
|
+ attempt, AMLauncherEventType.LAUNCH, rm.getConfig());
|
|
|
+ DataOutputBuffer dob = new DataOutputBuffer();
|
|
|
+ Credentials ts = new Credentials();
|
|
|
+ ts.writeTokenStorageToStream(dob);
|
|
|
+ ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(),
|
|
|
+ 0, dob.getLength());
|
|
|
+ ContainerLaunchContext amContainer =
|
|
|
+ ContainerLaunchContext.newInstance(null, null,
|
|
|
+ null, null, securityTokens, null);
|
|
|
+ ContainerId containerId = ContainerId.newContainerId(
|
|
|
+ attempt.getAppAttemptId(), 0L);
|
|
|
+
|
|
|
+ try {
|
|
|
+ launcher.setupTokens(amContainer, containerId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // ignore the first fake exception
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ launcher.setupTokens(amContainer, containerId);
|
|
|
+ } catch (java.io.EOFException e) {
|
|
|
+ Assert.fail("EOFException should not happen.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static class MyAMLauncher extends AMLauncher {
|
|
|
+ int count;
|
|
|
+ public MyAMLauncher(RMContext rmContext, RMAppAttempt application,
|
|
|
+ AMLauncherEventType eventType, Configuration conf) {
|
|
|
+ super(rmContext, application, eventType, conf);
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected org.apache.hadoop.security.token.Token<AMRMTokenIdentifier>
|
|
|
+ createAndSetAMRMToken() {
|
|
|
+ count++;
|
|
|
+ if (count == 1) {
|
|
|
+ throw new RuntimeException("createAndSetAMRMToken failure");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setupTokens(ContainerLaunchContext container,
|
|
|
+ ContainerId containerID) throws IOException {
|
|
|
+ super.setupTokens(container, containerID);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|