diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java index 0dcd228..963dcf2 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestClientToAMTokens.java @@ -23,14 +23,24 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.io.PrintWriter; import java.lang.annotation.Annotation; import java.net.InetSocketAddress; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; +import java.util.Arrays; +import java.util.Collection; import javax.security.sasl.SaslException; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairSchedulerConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fifo.FifoScheduler; import org.junit.Assert; import org.apache.hadoop.conf.Configuration; @@ -72,9 +82,68 @@ import org.apache.hadoop.yarn.server.utils.BuilderUtils; import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.Records; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +@RunWith(Parameterized.class) public class TestClientToAMTokens { + private static final String TEST_DIR = new File(System.getProperty( + "test.build.data", "/tmp")).getAbsolutePath(); + private static final String FS_ALLOC_FILE = new File(TEST_DIR, + "test-fs-queues.xml").getAbsolutePath(); + private int schedulerType = 0; + private Configuration conf = null; + + @Parameters + public static Collection configRunnings() { + return Arrays.asList(new Object[][]{{0}, {1}, {2}}); + } + + public TestClientToAMTokens(int para) { + this.schedulerType = para; + } + + @Before + public void setup() throws IOException { + conf = new YarnConfiguration(); + + // Configure scheduler + switch (schedulerType) { + case 0: + configFifoScheduler(); + break; + case 1: + configCapacityScheduler(); + break; + case 2: + configFairScheduler(); + break; + } + } + + private void configFifoScheduler() { + conf.set(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class.getName()); + } + + private void configCapacityScheduler() { + conf.set(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class.getName()); + } + + private void configFairScheduler() throws IOException { + // Disable queueMaxAMShare limitation for fair scheduler + PrintWriter out = new PrintWriter(new FileWriter(FS_ALLOC_FILE)); + out.println(""); + out.println(""); + out.println("-1.0"); + out.println(""); + out.close(); + + conf.set(YarnConfiguration.RM_SCHEDULER, FairScheduler.class.getName()); + conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, FS_ALLOC_FILE); + } private interface CustomProtocol { @SuppressWarnings("unused") @@ -151,8 +220,6 @@ protected void serviceStart() throws Exception { @Test public void testClientToAMTokens() throws Exception { - - final Configuration conf = new Configuration(); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); UserGroupInformation.setConfiguration(conf); @@ -267,6 +334,8 @@ public RegisterApplicationMasterResponse run() { // Now for an authenticated user verifyValidToken(conf, am, token); + + rm.stop(); } private void verifyTokenWithTamperedID(final Configuration conf,