YARN-2254. TestRMWebServicesAppsModification should run against both CS and FS. (Zhihai Xu via kasha)

(cherry picked from commit 5e0b49da9c)
This commit is contained in:
Karthik Kambatla 2014-10-01 15:47:40 -07:00
parent 61c7ceaf82
commit b6f4d1ef42
2 changed files with 104 additions and 18 deletions

View File

@ -18,6 +18,9 @@ Release 2.7.0 - UNRELEASED
BUG FIXES BUG FIXES
YARN-2254. TestRMWebServicesAppsModification should run against both
CS and FS. (Zhihai Xu via kasha)
Release 2.6.0 - UNRELEASED Release 2.6.0 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -67,6 +67,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
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.security.QueueACLsManager; import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState;
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo; import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo;
@ -117,6 +119,11 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
private boolean setAuthFilter = false; private boolean setAuthFilter = false;
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();
public static class GuiceServletConfig extends GuiceServletContextListener { public static class GuiceServletConfig extends GuiceServletContextListener {
@Override @Override
@ -153,11 +160,14 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
} }
private class TestServletModule extends ServletModule { private abstract class TestServletModule extends ServletModule {
public Configuration conf = new Configuration(); public Configuration conf = new Configuration();
public abstract void configureScheduler();
@Override @Override
protected void configureServlets() { protected void configureServlets() {
configureScheduler();
bind(JAXBContextResolver.class); bind(JAXBContextResolver.class);
bind(RMWebServices.class); bind(RMWebServices.class);
bind(GenericExceptionHandler.class); bind(GenericExceptionHandler.class);
@ -176,8 +186,39 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
} }
} }
private Injector getNoAuthInjector() { private class CapTestServletModule extends TestServletModule {
return Guice.createInjector(new TestServletModule() { @Override
public void configureScheduler() {
conf.set("yarn.resourcemanager.scheduler.class",
CapacityScheduler.class.getName());
}
}
private class FairTestServletModule extends TestServletModule {
@Override
public void configureScheduler() {
try {
PrintWriter out = new PrintWriter(new FileWriter(FS_ALLOC_FILE));
out.println("<?xml version=\"1.0\"?>");
out.println("<allocations>");
out.println("<queue name=\"root\">");
out.println(" <aclAdministerApps>someuser </aclAdministerApps>");
out.println(" <queue name=\"default\">");
out.println(" <aclAdministerApps>someuser </aclAdministerApps>");
out.println(" </queue>");
out.println("</queue>");
out.println("</allocations>");
out.close();
} catch(IOException e) {
}
conf.set(FairSchedulerConfiguration.ALLOCATION_FILE, FS_ALLOC_FILE);
conf.set("yarn.resourcemanager.scheduler.class",
FairScheduler.class.getName());
}
}
private Injector getNoAuthInjectorCap() {
return Guice.createInjector(new CapTestServletModule() {
@Override @Override
protected void configureServlets() { protected void configureServlets() {
setAuthFilter = false; setAuthFilter = false;
@ -186,8 +227,32 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
}); });
} }
private Injector getSimpleAuthInjector() { private Injector getSimpleAuthInjectorCap() {
return Guice.createInjector(new TestServletModule() { return Guice.createInjector(new CapTestServletModule() {
@Override
protected void configureServlets() {
setAuthFilter = true;
conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
// set the admin acls otherwise all users are considered admins
// and we can't test authorization
conf.setStrings(YarnConfiguration.YARN_ADMIN_ACL, "testuser1");
super.configureServlets();
}
});
}
private Injector getNoAuthInjectorFair() {
return Guice.createInjector(new FairTestServletModule() {
@Override
protected void configureServlets() {
setAuthFilter = false;
super.configureServlets();
}
});
}
private Injector getSimpleAuthInjectorFair() {
return Guice.createInjector(new FairTestServletModule() {
@Override @Override
protected void configureServlets() { protected void configureServlets() {
setAuthFilter = true; setAuthFilter = true;
@ -202,7 +267,7 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
@Parameters @Parameters
public static Collection<Object[]> guiceConfigs() { public static Collection<Object[]> guiceConfigs() {
return Arrays.asList(new Object[][] { { 0 }, { 1 } }); return Arrays.asList(new Object[][] { { 0 }, { 1 }, { 2 }, { 3 } });
} }
@Before @Before
@ -221,10 +286,20 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
switch (run) { switch (run) {
case 0: case 0:
default: default:
injector = getNoAuthInjector(); // No Auth Capacity Scheduler
injector = getNoAuthInjectorCap();
break; break;
case 1: case 1:
injector = getSimpleAuthInjector(); // Simple Auth Capacity Scheduler
injector = getSimpleAuthInjectorCap();
break;
case 2:
// No Auth Fair Scheduler
injector = getNoAuthInjectorFair();
break;
case 3:
// Simple Auth Fair Scheduler
injector = getSimpleAuthInjectorFair();
break; break;
} }
} }
@ -273,7 +348,7 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
rm.stop(); rm.stop();
} }
@Test(timeout = 90000) @Test(timeout = 120000)
public void testSingleAppKill() throws Exception { public void testSingleAppKill() throws Exception {
rm.start(); rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
@ -445,20 +520,25 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
assertTrue(msg, valid); assertTrue(msg, valid);
} }
@Test(timeout = 30000) @Test(timeout = 60000)
public void testSingleAppKillUnauthorized() throws Exception { public void testSingleAppKillUnauthorized() throws Exception {
boolean isCapacityScheduler = boolean isCapacityScheduler =
rm.getResourceScheduler() instanceof CapacityScheduler; rm.getResourceScheduler() instanceof CapacityScheduler;
assumeTrue("Currently this test is only supported on CapacityScheduler", boolean isFairScheduler =
isCapacityScheduler); rm.getResourceScheduler() instanceof FairScheduler;
assumeTrue("This test is only supported on Capacity and Fair Scheduler",
isCapacityScheduler || isFairScheduler);
// FairScheduler use ALLOCATION_FILE to configure ACL
if (isCapacityScheduler) {
// default root queue allows anyone to have admin acl // default root queue allows anyone to have admin acl
CapacitySchedulerConfiguration csconf = CapacitySchedulerConfiguration csconf =
new CapacitySchedulerConfiguration(); new CapacitySchedulerConfiguration();
csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser"); csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser"); csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext()); rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());
}
rm.start(); rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048); MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
@ -733,6 +813,9 @@ public class TestRMWebServicesAppsModification extends JerseyTest {
assertEquals(appName, app.getName()); assertEquals(appName, app.getName());
assertEquals(webserviceUserName, app.getUser()); assertEquals(webserviceUserName, app.getUser());
assertEquals(2, app.getMaxAppAttempts()); assertEquals(2, app.getMaxAppAttempts());
if (app.getQueue().contains("root.")) {
queueName = "root." + queueName;
}
assertEquals(queueName, app.getQueue()); assertEquals(queueName, app.getQueue());
assertEquals(appType, app.getApplicationType()); assertEquals(appType, app.getApplicationType());
assertEquals(tags, app.getApplicationTags()); assertEquals(tags, app.getApplicationTags());