|
@@ -38,6 +38,8 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.Container;
|
|
@@ -67,6 +69,8 @@ import org.mockito.stubbing.Answer;
|
|
|
|
|
|
public class TestLeafQueue {
|
|
|
|
|
|
+ private static final Log LOG = LogFactory.getLog(TestLeafQueue.class);
|
|
|
+
|
|
|
private final RecordFactory recordFactory =
|
|
|
RecordFactoryProvider.getRecordFactory(null);
|
|
|
|
|
@@ -472,6 +476,115 @@ public class TestLeafQueue {
|
|
|
assertEquals(2*GB, app_1.getCurrentConsumption().getMemory());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testHeadroomWithMaxCap() throws Exception {
|
|
|
+ // Mock the queue
|
|
|
+ LeafQueue a = stubLeafQueue((LeafQueue)queues.get(A));
|
|
|
+ //unset maxCapacity
|
|
|
+ a.setMaxCapacity(1.0f);
|
|
|
+
|
|
|
+ // Users
|
|
|
+ final String user_0 = "user_0";
|
|
|
+ final String user_1 = "user_1";
|
|
|
+
|
|
|
+ // Submit applications
|
|
|
+ final ApplicationAttemptId appAttemptId_0 =
|
|
|
+ TestUtils.getMockApplicationAttemptId(0, 0);
|
|
|
+ SchedulerApp app_0 =
|
|
|
+ new SchedulerApp(appAttemptId_0, user_0, a,
|
|
|
+ a.getActiveUsersManager(), rmContext, null);
|
|
|
+ a.submitApplication(app_0, user_0, A);
|
|
|
+
|
|
|
+ final ApplicationAttemptId appAttemptId_1 =
|
|
|
+ TestUtils.getMockApplicationAttemptId(1, 0);
|
|
|
+ SchedulerApp app_1 =
|
|
|
+ new SchedulerApp(appAttemptId_1, user_0, a,
|
|
|
+ a.getActiveUsersManager(), rmContext, null);
|
|
|
+ a.submitApplication(app_1, user_0, A); // same user
|
|
|
+
|
|
|
+ final ApplicationAttemptId appAttemptId_2 =
|
|
|
+ TestUtils.getMockApplicationAttemptId(2, 0);
|
|
|
+ SchedulerApp app_2 =
|
|
|
+ new SchedulerApp(appAttemptId_2, user_1, a,
|
|
|
+ a.getActiveUsersManager(), rmContext, null);
|
|
|
+ a.submitApplication(app_2, user_1, A);
|
|
|
+
|
|
|
+ // Setup some nodes
|
|
|
+ String host_0 = "host_0";
|
|
|
+ SchedulerNode node_0 = TestUtils.getMockNode(host_0, DEFAULT_RACK, 0, 8*GB);
|
|
|
+ String host_1 = "host_1";
|
|
|
+ SchedulerNode node_1 = TestUtils.getMockNode(host_1, DEFAULT_RACK, 0, 8*GB);
|
|
|
+
|
|
|
+ final int numNodes = 2;
|
|
|
+ Resource clusterResource = Resources.createResource(numNodes * (8*GB));
|
|
|
+ when(csContext.getNumClusterNodes()).thenReturn(numNodes);
|
|
|
+
|
|
|
+ // Setup resource-requests
|
|
|
+ Priority priority = TestUtils.createMockPriority(1);
|
|
|
+ app_0.updateResourceRequests(Collections.singletonList(
|
|
|
+ TestUtils.createResourceRequest(RMNodeImpl.ANY, 2*GB, 1, priority,
|
|
|
+ recordFactory)));
|
|
|
+
|
|
|
+ app_1.updateResourceRequests(Collections.singletonList(
|
|
|
+ TestUtils.createResourceRequest(RMNodeImpl.ANY, 1*GB, 2, priority,
|
|
|
+ recordFactory)));
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Start testing...
|
|
|
+ */
|
|
|
+
|
|
|
+ // Set user-limit
|
|
|
+ a.setUserLimit(50);
|
|
|
+ a.setUserLimitFactor(2);
|
|
|
+
|
|
|
+ // Now, only user_0 should be active since he is the only one with
|
|
|
+ // outstanding requests
|
|
|
+ assertEquals("There should only be 1 active user!",
|
|
|
+ 1, a.getActiveUsersManager().getNumActiveUsers());
|
|
|
+
|
|
|
+ // 1 container to user_0
|
|
|
+ a.assignContainers(clusterResource, node_0);
|
|
|
+ assertEquals(2*GB, a.getUsedResources().getMemory());
|
|
|
+ assertEquals(2*GB, app_0.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(0*GB, app_1.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(0*GB, app_0.getHeadroom().getMemory()); // User limit = 2G
|
|
|
+ assertEquals(0*GB, app_0.getHeadroom().getMemory()); // User limit = 2G
|
|
|
+
|
|
|
+ // Again one to user_0 since he hasn't exceeded user limit yet
|
|
|
+ a.assignContainers(clusterResource, node_0);
|
|
|
+ assertEquals(3*GB, a.getUsedResources().getMemory());
|
|
|
+ assertEquals(2*GB, app_0.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(1*GB, app_1.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(0*GB, app_0.getHeadroom().getMemory()); // 3G - 2G
|
|
|
+ assertEquals(0*GB, app_0.getHeadroom().getMemory()); // 3G - 2G
|
|
|
+
|
|
|
+ // Submit requests for app_1 and set max-cap
|
|
|
+ a.setMaxCapacity(.1f);
|
|
|
+ app_2.updateResourceRequests(Collections.singletonList(
|
|
|
+ TestUtils.createResourceRequest(RMNodeImpl.ANY, 1*GB, 1, priority,
|
|
|
+ recordFactory)));
|
|
|
+ assertEquals(2, a.getActiveUsersManager().getNumActiveUsers());
|
|
|
+
|
|
|
+ // No more to user_0 since he is already over user-limit
|
|
|
+ // and no more containers to queue since it's already at max-cap
|
|
|
+ a.assignContainers(clusterResource, node_1);
|
|
|
+ assertEquals(3*GB, a.getUsedResources().getMemory());
|
|
|
+ assertEquals(2*GB, app_0.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(1*GB, app_1.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(0*GB, app_2.getCurrentConsumption().getMemory());
|
|
|
+ assertEquals(0*GB, app_0.getHeadroom().getMemory());
|
|
|
+ assertEquals(0*GB, app_1.getHeadroom().getMemory());
|
|
|
+
|
|
|
+ // Check headroom for app_2
|
|
|
+ LOG.info("here");
|
|
|
+ app_1.updateResourceRequests(Collections.singletonList( // unset
|
|
|
+ TestUtils.createResourceRequest(RMNodeImpl.ANY, 1*GB, 0, priority,
|
|
|
+ recordFactory)));
|
|
|
+ assertEquals(1, a.getActiveUsersManager().getNumActiveUsers());
|
|
|
+ a.assignContainers(clusterResource, node_1);
|
|
|
+ assertEquals(1*GB, app_2.getHeadroom().getMemory()); // hit queue max-cap
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testSingleQueueWithMultipleUsers() throws Exception {
|
|
|
|