YARN-3395. FairScheduler: Trim whitespaces when using username for queuename. (Zhihai Xu via kasha)

(cherry picked from commit a60f78e98e)
This commit is contained in:
Karthik Kambatla 2015-05-09 15:41:20 -07:00
parent 52469b10dd
commit 3cf4f24a9f
3 changed files with 41 additions and 1 deletions

View File

@ -176,6 +176,9 @@ Release 2.8.0 - UNRELEASED
YARN-1287. Consolidate MockClocks.
(Sebastian Wong and Anubhav Dhoot via kasha)
YARN-3395. FairScheduler: Trim whitespaces when using username for
queuename. (Zhihai Xu via kasha)
OPTIMIZATIONS
YARN-3339. TestDockerContainerExecutor should pull a single image and not

View File

@ -345,9 +345,11 @@ public abstract class QueuePlacementRule {
}
/**
* Replace the periods in the username or groupname with "_dot_".
* Replace the periods in the username or groupname with "_dot_" and
* remove trailing and leading whitespace.
*/
protected String cleanName(String name) {
name = name.trim();
if (name.contains(".")) {
String converted = name.replaceAll("\\.", "_dot_");
LOG.warn("Name " + name + " is converted to " + converted

View File

@ -4335,4 +4335,39 @@ public class TestFairScheduler extends FairSchedulerTestBase {
"Failed to initialize FairScheduler"));
}
}
@Test
public void testUserAsDefaultQueueWithLeadingTrailingSpaceUserName()
throws Exception {
conf.set(FairSchedulerConfiguration.USER_AS_DEFAULT_QUEUE, "true");
scheduler.init(conf);
scheduler.start();
scheduler.reinitialize(conf, resourceManager.getRMContext());
ApplicationAttemptId appAttemptId = createAppAttemptId(1, 1);
createApplicationWithAMResource(appAttemptId, "default", " user1", null);
assertEquals(1, scheduler.getQueueManager().getLeafQueue("user1", true)
.getNumRunnableApps());
assertEquals(0, scheduler.getQueueManager().getLeafQueue("default", true)
.getNumRunnableApps());
assertEquals("root.user1", resourceManager.getRMContext().getRMApps()
.get(appAttemptId.getApplicationId()).getQueue());
ApplicationAttemptId attId2 = createAppAttemptId(2, 1);
createApplicationWithAMResource(attId2, "default", "user1 ", null);
assertEquals(2, scheduler.getQueueManager().getLeafQueue("user1", true)
.getNumRunnableApps());
assertEquals(0, scheduler.getQueueManager().getLeafQueue("default", true)
.getNumRunnableApps());
assertEquals("root.user1", resourceManager.getRMContext().getRMApps()
.get(attId2.getApplicationId()).getQueue());
ApplicationAttemptId attId3 = createAppAttemptId(3, 1);
createApplicationWithAMResource(attId3, "default", "user1", null);
assertEquals(3, scheduler.getQueueManager().getLeafQueue("user1", true)
.getNumRunnableApps());
assertEquals(0, scheduler.getQueueManager().getLeafQueue("default", true)
.getNumRunnableApps());
assertEquals("root.user1", resourceManager.getRMContext().getRMApps()
.get(attId3.getApplicationId()).getQueue());
}
}