public virtual void TestOffSwitchSchedulingMultiLevelQueues() { // Setup queue configs SetupMultiLevelQueues(csConf); //B3 IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 10; int numNodes = 2; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); FiCaSchedulerNode node_1 = TestUtils.GetMockNode("host_1", DefaultRack, 0, memoryPerNode * Gb); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing LeafQueue b3 = (LeafQueue)queues[B3]; LeafQueue b2 = (LeafQueue)queues[B2]; // Simulate B3 returning a container on node_0 StubQueueAllocation(b2, clusterResource, node_0, 0 * Gb, NodeType.OffSwitch); StubQueueAllocation(b3, clusterResource, node_0, 1 * Gb, NodeType.OffSwitch); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(b2, 0 * Gb, clusterResource); VerifyQueueMetrics(b3, 1 * Gb, clusterResource); // Now, B2 should get the scheduling opportunity since B2=0G/2G, B3=1G/7G // also, B3 gets a scheduling opportunity since B2 allocates RACK_LOCAL StubQueueAllocation(b2, clusterResource, node_1, 1 * Gb, NodeType.RackLocal); StubQueueAllocation(b3, clusterResource, node_1, 1 * Gb, NodeType.OffSwitch); root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(b2, b3); allocationOrder.Verify(b2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(b3).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(b2, 1 * Gb, clusterResource); VerifyQueueMetrics(b3, 2 * Gb, clusterResource); // Now, B3 should get the scheduling opportunity // since B2 has 1/2G while B3 has 2/7G, // However, since B3 returns off-switch, B2 won't get an opportunity StubQueueAllocation(b2, clusterResource, node_0, 1 * Gb, NodeType.NodeLocal); StubQueueAllocation(b3, clusterResource, node_0, 1 * Gb, NodeType.OffSwitch); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); allocationOrder = Org.Mockito.Mockito.InOrder(b3, b2); allocationOrder.Verify(b3).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(b2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(b2, 1 * Gb, clusterResource); VerifyQueueMetrics(b3, 3 * Gb, clusterResource); }
public virtual void TestQueueCapacityZero() { // Setup queue configs SetupMultiLevelQueues(csConf); // set parent and child capacity to 0 string QB = CapacitySchedulerConfiguration.Root + "." + B; csConf.SetCapacity(QB, 0); csConf.SetCapacity(QB + "." + B1, 0); csConf.SetCapacity(QB + "." + B2, 0); csConf.SetCapacity(QB + "." + B3, 0); string QA = CapacitySchedulerConfiguration.Root + "." + A; csConf.SetCapacity(QA, 60); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); try { CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); } catch (ArgumentException e) { NUnit.Framework.Assert.Fail("Failed to create queues with 0 capacity: " + e); } NUnit.Framework.Assert.IsTrue("Failed to create queues with 0 capacity", true); }
/// <exception cref="System.Exception"/> public virtual void TestQueueCapacitySettingChildZero() { // Setup queue configs SetupMultiLevelQueues(csConf); // set child queues capacity to 0 when parents not 0 string QB = CapacitySchedulerConfiguration.Root + "." + B; csConf.SetCapacity(QB + "." + B1, 0); csConf.SetCapacity(QB + "." + B2, 0); csConf.SetCapacity(QB + "." + B3, 0); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); }
public virtual void SetUp() { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); YarnConfiguration conf = new YarnConfiguration(); SetupQueueConfiguration(csConf); rmContext = TestUtils.GetMockRMContext(); CapacitySchedulerContext csContext = Org.Mockito.Mockito.Mock <CapacitySchedulerContext >(); Org.Mockito.Mockito.When(csContext.GetConfiguration()).ThenReturn(csConf); Org.Mockito.Mockito.When(csContext.GetConf()).ThenReturn(conf); Org.Mockito.Mockito.When(csContext.GetMinimumResourceCapability()).ThenReturn(Resources .CreateResource(Gb, 1)); Org.Mockito.Mockito.When(csContext.GetMaximumResourceCapability()).ThenReturn(Resources .CreateResource(16 * Gb, 32)); Org.Mockito.Mockito.When(csContext.GetClusterResource()).ThenReturn(Resources.CreateResource (10 * 16 * Gb, 10 * 32)); Org.Mockito.Mockito.When(csContext.GetApplicationComparator()).ThenReturn(CapacityScheduler .applicationComparator); Org.Mockito.Mockito.When(csContext.GetQueueComparator()).ThenReturn(CapacityScheduler .queueComparator); Org.Mockito.Mockito.When(csContext.GetResourceCalculator()).ThenReturn(resourceCalculator ); Org.Mockito.Mockito.When(csContext.GetRMContext()).ThenReturn(rmContext); RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager (conf); containerTokenSecretManager.RollMasterKey(); Org.Mockito.Mockito.When(csContext.GetContainerTokenSecretManager()).ThenReturn(containerTokenSecretManager ); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues , queues, TestUtils.spyHook); queue = Org.Mockito.Mockito.Spy(new LeafQueue(csContext, A, root, null)); // Stub out ACL checks Org.Mockito.Mockito.DoReturn(true).When(queue).HasAccess(Matchers.Any <QueueACL>() , Matchers.Any <UserGroupInformation>()); // Some default values Org.Mockito.Mockito.DoReturn(100).When(queue).GetMaxApplications(); Org.Mockito.Mockito.DoReturn(25).When(queue).GetMaxApplicationsPerUser(); }
public virtual void TestQueueAcl() { SetupMultiLevelQueues(csConf); csConf.SetAcl(CapacitySchedulerConfiguration.Root, QueueACL.SubmitApplications, " " ); csConf.SetAcl(CapacitySchedulerConfiguration.Root, QueueACL.AdministerQueue, " "); string QC = CapacitySchedulerConfiguration.Root + "." + C; csConf.SetAcl(QC, QueueACL.AdministerQueue, "*"); string QC11 = QC + "." + C1 + "." + C11; csConf.SetAcl(QC11, QueueACL.SubmitApplications, "*"); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); YarnAuthorizationProvider authorizer = YarnAuthorizationProvider.GetInstance(conf ); CapacityScheduler.SetQueueAcls(authorizer, queues); UserGroupInformation user = UserGroupInformation.GetCurrentUser(); // Setup queue configs ParentQueue c = (ParentQueue)queues[C]; ParentQueue c1 = (ParentQueue)queues[C1]; ParentQueue c11 = (ParentQueue)queues[C11]; ParentQueue c111 = (ParentQueue)queues[C111]; NUnit.Framework.Assert.IsFalse(root.HasAccess(QueueACL.AdministerQueue, user)); IList <QueueUserACLInfo> aclInfos = root.GetQueueUserAclInfo(user); NUnit.Framework.Assert.IsFalse(HasQueueACL(aclInfos, QueueACL.AdministerQueue, "root" )); NUnit.Framework.Assert.IsFalse(root.HasAccess(QueueACL.SubmitApplications, user)); NUnit.Framework.Assert.IsFalse(HasQueueACL(aclInfos, QueueACL.SubmitApplications, "root")); // c has no SA, but QA NUnit.Framework.Assert.IsTrue(c.HasAccess(QueueACL.AdministerQueue, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.AdministerQueue, "c" )); NUnit.Framework.Assert.IsFalse(c.HasAccess(QueueACL.SubmitApplications, user)); NUnit.Framework.Assert.IsFalse(HasQueueACL(aclInfos, QueueACL.SubmitApplications, "c")); //Queue c1 has QA, no SA (gotten perm from parent) NUnit.Framework.Assert.IsTrue(c1.HasAccess(QueueACL.AdministerQueue, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.AdministerQueue, "c1" )); NUnit.Framework.Assert.IsFalse(c1.HasAccess(QueueACL.SubmitApplications, user)); NUnit.Framework.Assert.IsFalse(HasQueueACL(aclInfos, QueueACL.SubmitApplications, "c1")); //Queue c11 has permissions from parent queue and SA NUnit.Framework.Assert.IsTrue(c11.HasAccess(QueueACL.AdministerQueue, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.AdministerQueue, "c11" )); NUnit.Framework.Assert.IsTrue(c11.HasAccess(QueueACL.SubmitApplications, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.SubmitApplications, "c11")); //Queue c111 has SA and AQ, both from parent NUnit.Framework.Assert.IsTrue(c111.HasAccess(QueueACL.AdministerQueue, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.AdministerQueue, "c111" )); NUnit.Framework.Assert.IsTrue(c111.HasAccess(QueueACL.SubmitApplications, user)); NUnit.Framework.Assert.IsTrue(HasQueueACL(aclInfos, QueueACL.SubmitApplications, "c111")); Org.Mockito.Mockito.Reset(c); }
public virtual void TestMultiLevelQueues() { /* * Structure of queue: * Root * ____________ * / | \ \ * A B C D * / | / | \ \ * A1 A2 B1 B2 B3 C1 * \ * C11 * \ * C111 * \ * C1111 */ // Setup queue configs SetupMultiLevelQueues(csConf); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 16; int numNodes = 3; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); FiCaSchedulerNode node_1 = TestUtils.GetMockNode("host_1", DefaultRack, 0, memoryPerNode * Gb); FiCaSchedulerNode node_2 = TestUtils.GetMockNode("host_2", DefaultRack, 0, memoryPerNode * Gb); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing CSQueue a = queues[A]; CSQueue b = queues[B]; CSQueue c = queues[C]; CSQueue d = queues[D]; CSQueue a1 = queues[A1]; CSQueue a2 = queues[A2]; CSQueue b1 = queues[B1]; CSQueue b2 = queues[B2]; CSQueue b3 = queues[B3]; // Simulate C returning a container on node_0 StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 1 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 0 * Gb, clusterResource); VerifyQueueMetrics(b, 0 * Gb, clusterResource); VerifyQueueMetrics(c, 1 * Gb, clusterResource); VerifyQueueMetrics(d, 0 * Gb, clusterResource); Org.Mockito.Mockito.Reset(a); Org.Mockito.Mockito.Reset(b); Org.Mockito.Mockito.Reset(c); // Now get B2 to allocate // A = 0/3, B = 0/15, C = 1/6, D=0/6 StubQueueAllocation(a, clusterResource, node_1, 0 * Gb); StubQueueAllocation(b2, clusterResource, node_1, 4 * Gb); StubQueueAllocation(c, clusterResource, node_1, 0 * Gb); root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 0 * Gb, clusterResource); VerifyQueueMetrics(b, 4 * Gb, clusterResource); VerifyQueueMetrics(c, 1 * Gb, clusterResource); Org.Mockito.Mockito.Reset(a); Org.Mockito.Mockito.Reset(b); Org.Mockito.Mockito.Reset(c); // Now get both A1, C & B3 to allocate in right order // A = 0/3, B = 4/15, C = 1/6, D=0/6 StubQueueAllocation(a1, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b3, clusterResource, node_0, 2 * Gb); StubQueueAllocation(c, clusterResource, node_0, 2 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(a, c, b); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(c).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 6 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); Org.Mockito.Mockito.Reset(a); Org.Mockito.Mockito.Reset(b); Org.Mockito.Mockito.Reset(c); // Now verify max-capacity // A = 1/3, B = 6/15, C = 3/6, D=0/6 // Ensure a1 won't alloc above max-cap although it should get // scheduling opportunity now, right after a2 Log.Info("here"); ((ParentQueue)a).SetMaxCapacity(.1f); // a should be capped at 3/30 StubQueueAllocation(a1, clusterResource, node_2, 1 * Gb); // shouldn't be // allocated due // to max-cap StubQueueAllocation(a2, clusterResource, node_2, 2 * Gb); StubQueueAllocation(b3, clusterResource, node_2, 1 * Gb); StubQueueAllocation(b1, clusterResource, node_2, 1 * Gb); StubQueueAllocation(c, clusterResource, node_2, 1 * Gb); root.AssignContainers(clusterResource, node_2, new ResourceLimits(clusterResource )); allocationOrder = Org.Mockito.Mockito.InOrder(a, a2, a1, b, c); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(a2).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(c).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 8 * Gb, clusterResource); VerifyQueueMetrics(c, 4 * Gb, clusterResource); Org.Mockito.Mockito.Reset(a); Org.Mockito.Mockito.Reset(b); Org.Mockito.Mockito.Reset(c); }
public virtual void TestSingleLevelQueuesPrecision() { // Setup queue configs SetupSingleLevelQueues(csConf); string QA = CapacitySchedulerConfiguration.Root + "." + "a"; csConf.SetCapacity(QA, 30); string QB = CapacitySchedulerConfiguration.Root + "." + "b"; csConf.SetCapacity(QB, 70.5F); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); bool exceptionOccured = false; try { CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); } catch (ArgumentException) { exceptionOccured = true; } if (!exceptionOccured) { NUnit.Framework.Assert.Fail("Capacity is more then 100% so should be failed."); } csConf.SetCapacity(QA, 30); csConf.SetCapacity(QB, 70); exceptionOccured = false; queues.Clear(); try { CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); } catch (ArgumentException) { exceptionOccured = true; } if (exceptionOccured) { NUnit.Framework.Assert.Fail("Capacity is 100% so should not be failed."); } csConf.SetCapacity(QA, 30); csConf.SetCapacity(QB, 70.005F); exceptionOccured = false; queues.Clear(); try { CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); } catch (ArgumentException) { exceptionOccured = true; } if (exceptionOccured) { NUnit.Framework.Assert.Fail("Capacity is under PRECISION which is .05% so should not be failed." ); } }
public virtual void TestSingleLevelQueues() { // Setup queue configs SetupSingleLevelQueues(csConf); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 16; int numNodes = 2; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); FiCaSchedulerNode node_1 = TestUtils.GetMockNode("host_1", DefaultRack, 0, memoryPerNode * Gb); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing LeafQueue a = (LeafQueue)queues[A]; LeafQueue b = (LeafQueue)queues[B]; // Simulate B returning a container on node_0 StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 0 * Gb, clusterResource); VerifyQueueMetrics(b, 1 * Gb, clusterResource); // Now, A should get the scheduling opportunity since A=0G/6G, B=1G/14G StubQueueAllocation(a, clusterResource, node_1, 2 * Gb); StubQueueAllocation(b, clusterResource, node_1, 1 * Gb); root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(a, b); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); // Now, B should get the scheduling opportunity // since A has 2/6G while B has 2/14G StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 2 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); allocationOrder = Org.Mockito.Mockito.InOrder(b, a); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 4 * Gb, clusterResource); // Now, B should still get the scheduling opportunity // since A has 3/6G while B has 4/14G StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 4 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); allocationOrder = Org.Mockito.Mockito.InOrder(b, a); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 8 * Gb, clusterResource); // Now, A should get the scheduling opportunity // since A has 3/6G while B has 8/14G StubQueueAllocation(a, clusterResource, node_1, 1 * Gb); StubQueueAllocation(b, clusterResource, node_1, 1 * Gb); root.AssignContainers(clusterResource, node_1, new ResourceLimits(clusterResource )); allocationOrder = Org.Mockito.Mockito.InOrder(a, b); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); allocationOrder.Verify(a).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), AnyResourceLimits()); VerifyQueueMetrics(a, 4 * Gb, clusterResource); VerifyQueueMetrics(b, 9 * Gb, clusterResource); }
public virtual void TestSortedQueues() { // Setup queue configs SetupSortedQueues(csConf); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 16; int numNodes = 1; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); Org.Mockito.Mockito.DoNothing().When(node_0).ReleaseContainer(Matchers.Any <Container >()); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing CSQueue a = queues[A]; CSQueue b = queues[B]; CSQueue c = queues[C]; CSQueue d = queues[D]; string user_0 = "user_0"; // Stub an App and its containerCompleted FiCaSchedulerApp app_0 = GetMockApplication(0, user_0); Org.Mockito.Mockito.DoReturn(true).When(app_0).ContainerCompleted(Matchers.Any <RMContainer >(), Matchers.Any <ContainerStatus>(), Matchers.Any <RMContainerEventType>()); Priority priority = TestUtils.CreateMockPriority(1); ContainerAllocationExpirer expirer = Org.Mockito.Mockito.Mock <ContainerAllocationExpirer >(); DrainDispatcher drainDispatcher = new DrainDispatcher(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); SystemMetricsPublisher publisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher >(); RMContext rmContext = Org.Mockito.Mockito.Mock <RMContext>(); Org.Mockito.Mockito.When(rmContext.GetContainerAllocationExpirer()).ThenReturn(expirer ); Org.Mockito.Mockito.When(rmContext.GetDispatcher()).ThenReturn(drainDispatcher); Org.Mockito.Mockito.When(rmContext.GetRMApplicationHistoryWriter()).ThenReturn(writer ); Org.Mockito.Mockito.When(rmContext.GetSystemMetricsPublisher()).ThenReturn(publisher ); Org.Mockito.Mockito.When(rmContext.GetYarnConfiguration()).ThenReturn(new YarnConfiguration ()); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(app_0.GetApplicationId (), 1); ContainerId containerId = BuilderUtils.NewContainerId(appAttemptId, 1); Container container = TestUtils.GetMockContainer(containerId, node_0.GetNodeID(), Resources.CreateResource(1 * Gb), priority); RMContainer rmContainer = new RMContainerImpl(container, appAttemptId, node_0.GetNodeID (), "user", rmContext); // Assign {1,2,3,4} 1GB containers respectively to queues StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); for (int i = 0; i < 2; i++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_1 = 0; i_1 < 3; i_1++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 1 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_2 = 0; i_2 < 4; i_2++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 4 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 3 x 1GB containers from D for (int i_3 = 0; i_3 < 3; i_3++) { d.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 1 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 2 x 1GB Containers to A for (int i_4 = 0; i_4 < 2; i_4++) { StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB Container from A a.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to B StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 3 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB container resources from B b.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to A StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Now do the real test, where B and D request a 1GB container // D should should get the next container if the order is correct StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(d, b); allocationOrder.Verify(d).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 2 * Gb, clusterResource); //D got the container Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); }
public virtual void TestHeadroom() { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); csConf.SetUserLimit(CapacitySchedulerConfiguration.Root + "." + A, 25); SetupQueueConfiguration(csConf); YarnConfiguration conf = new YarnConfiguration(); CapacitySchedulerContext csContext = Org.Mockito.Mockito.Mock <CapacitySchedulerContext >(); Org.Mockito.Mockito.When(csContext.GetConfiguration()).ThenReturn(csConf); Org.Mockito.Mockito.When(csContext.GetConf()).ThenReturn(conf); Org.Mockito.Mockito.When(csContext.GetMinimumResourceCapability()).ThenReturn(Resources .CreateResource(Gb)); Org.Mockito.Mockito.When(csContext.GetMaximumResourceCapability()).ThenReturn(Resources .CreateResource(16 * Gb)); Org.Mockito.Mockito.When(csContext.GetApplicationComparator()).ThenReturn(CapacityScheduler .applicationComparator); Org.Mockito.Mockito.When(csContext.GetQueueComparator()).ThenReturn(CapacityScheduler .queueComparator); Org.Mockito.Mockito.When(csContext.GetResourceCalculator()).ThenReturn(resourceCalculator ); Org.Mockito.Mockito.When(csContext.GetRMContext()).ThenReturn(rmContext); // Say cluster has 100 nodes of 16G each Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (100 * 16 * Gb); Org.Mockito.Mockito.When(csContext.GetClusterResource()).ThenReturn(clusterResource ); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues, queues, TestUtils .spyHook); // Manipulate queue 'a' LeafQueue queue = TestLeafQueue.StubLeafQueue((LeafQueue)queues[A]); string host_0 = "host_0"; string rack_0 = "rack_0"; FiCaSchedulerNode node_0 = TestUtils.GetMockNode(host_0, rack_0, 0, 16 * Gb); string user_0 = "user_0"; string user_1 = "user_1"; RecordFactory recordFactory = RecordFactoryProvider.GetRecordFactory(null); RMContext rmContext = TestUtils.GetMockRMContext(); RMContext spyRMContext = Org.Mockito.Mockito.Spy(rmContext); ConcurrentMap <ApplicationId, RMApp> spyApps = Org.Mockito.Mockito.Spy(new ConcurrentHashMap <ApplicationId, RMApp>()); RMApp rmApp = Org.Mockito.Mockito.Mock <RMApp>(); ResourceRequest amResourceRequest = Org.Mockito.Mockito.Mock <ResourceRequest>(); Org.Apache.Hadoop.Yarn.Api.Records.Resource amResource = Resources.CreateResource (0, 0); Org.Mockito.Mockito.When(amResourceRequest.GetCapability()).ThenReturn(amResource ); Org.Mockito.Mockito.When(rmApp.GetAMResourceRequest()).ThenReturn(amResourceRequest ); Org.Mockito.Mockito.DoReturn(rmApp).When(spyApps)[(ApplicationId)Matchers.Any()]; Org.Mockito.Mockito.When(spyRMContext.GetRMApps()).ThenReturn(spyApps); Priority priority_1 = TestUtils.CreateMockPriority(1); // Submit first application with some resource-requests from user_0, // and check headroom ApplicationAttemptId appAttemptId_0_0 = TestUtils.GetMockApplicationAttemptId(0, 0); FiCaSchedulerApp app_0_0 = new FiCaSchedulerApp(appAttemptId_0_0, user_0, queue, queue.GetActiveUsersManager(), spyRMContext); queue.SubmitApplicationAttempt(app_0_0, user_0); IList <ResourceRequest> app_0_0_requests = new AList <ResourceRequest>(); app_0_0_requests.AddItem(TestUtils.CreateResourceRequest(ResourceRequest.Any, 1 * Gb, 2, true, priority_1, recordFactory)); app_0_0.UpdateResourceRequests(app_0_0_requests); // Schedule to compute queue.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); Org.Apache.Hadoop.Yarn.Api.Records.Resource expectedHeadroom = Resources.CreateResource (10 * 16 * Gb, 1); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_0.GetHeadroom()); // Submit second application from user_0, check headroom ApplicationAttemptId appAttemptId_0_1 = TestUtils.GetMockApplicationAttemptId(1, 0); FiCaSchedulerApp app_0_1 = new FiCaSchedulerApp(appAttemptId_0_1, user_0, queue, queue.GetActiveUsersManager(), spyRMContext); queue.SubmitApplicationAttempt(app_0_1, user_0); IList <ResourceRequest> app_0_1_requests = new AList <ResourceRequest>(); app_0_1_requests.AddItem(TestUtils.CreateResourceRequest(ResourceRequest.Any, 1 * Gb, 2, true, priority_1, recordFactory)); app_0_1.UpdateResourceRequests(app_0_1_requests); // Schedule to compute queue.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); // Schedule to compute NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_0.GetHeadroom()); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_1.GetHeadroom()); // no change // Submit first application from user_1, check for new headroom ApplicationAttemptId appAttemptId_1_0 = TestUtils.GetMockApplicationAttemptId(2, 0); FiCaSchedulerApp app_1_0 = new FiCaSchedulerApp(appAttemptId_1_0, user_1, queue, queue.GetActiveUsersManager(), spyRMContext); queue.SubmitApplicationAttempt(app_1_0, user_1); IList <ResourceRequest> app_1_0_requests = new AList <ResourceRequest>(); app_1_0_requests.AddItem(TestUtils.CreateResourceRequest(ResourceRequest.Any, 1 * Gb, 2, true, priority_1, recordFactory)); app_1_0.UpdateResourceRequests(app_1_0_requests); // Schedule to compute queue.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); // Schedule to compute expectedHeadroom = Resources.CreateResource(10 * 16 * Gb / 2, 1); // changes NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_0.GetHeadroom()); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_1.GetHeadroom()); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_1_0.GetHeadroom()); // Now reduce cluster size and check for the smaller headroom clusterResource = Resources.CreateResource(90 * 16 * Gb); queue.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); // Schedule to compute expectedHeadroom = Resources.CreateResource(9 * 16 * Gb / 2, 1); // changes NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_0.GetHeadroom()); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_0_1.GetHeadroom()); NUnit.Framework.Assert.AreEqual(expectedHeadroom, app_1_0.GetHeadroom()); }
public virtual void TestLimitsComputation() { CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); SetupQueueConfiguration(csConf); YarnConfiguration conf = new YarnConfiguration(); CapacitySchedulerContext csContext = Org.Mockito.Mockito.Mock <CapacitySchedulerContext >(); Org.Mockito.Mockito.When(csContext.GetConfiguration()).ThenReturn(csConf); Org.Mockito.Mockito.When(csContext.GetConf()).ThenReturn(conf); Org.Mockito.Mockito.When(csContext.GetMinimumResourceCapability()).ThenReturn(Resources .CreateResource(Gb, 1)); Org.Mockito.Mockito.When(csContext.GetMaximumResourceCapability()).ThenReturn(Resources .CreateResource(16 * Gb, 16)); Org.Mockito.Mockito.When(csContext.GetApplicationComparator()).ThenReturn(CapacityScheduler .applicationComparator); Org.Mockito.Mockito.When(csContext.GetQueueComparator()).ThenReturn(CapacityScheduler .queueComparator); Org.Mockito.Mockito.When(csContext.GetResourceCalculator()).ThenReturn(resourceCalculator ); Org.Mockito.Mockito.When(csContext.GetRMContext()).ThenReturn(rmContext); // Say cluster has 100 nodes of 16G each Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (100 * 16 * Gb, 100 * 16); Org.Mockito.Mockito.When(csContext.GetClusterResource()).ThenReturn(clusterResource ); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues , queues, TestUtils.spyHook); LeafQueue queue = (LeafQueue)queues[A]; Log.Info("Queue 'A' -" + " AMResourceLimit=" + queue.GetAMResourceLimit() + " UserAMResourceLimit=" + queue.GetUserAMResourceLimit()); NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(160 * Gb, 1)); NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(80 * Gb, 1)); NUnit.Framework.Assert.AreEqual((int)(clusterResource.GetMemory() * queue.GetAbsoluteCapacity ()), queue.GetMetrics().GetAvailableMB()); // Add some nodes to the cluster & test new limits clusterResource = Resources.CreateResource(120 * 16 * Gb); root.UpdateClusterResource(clusterResource, new ResourceLimits(clusterResource)); NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(192 * Gb, 1)); NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(96 * Gb, 1)); NUnit.Framework.Assert.AreEqual((int)(clusterResource.GetMemory() * queue.GetAbsoluteCapacity ()), queue.GetMetrics().GetAvailableMB()); // should return -1 if per queue setting not set NUnit.Framework.Assert.AreEqual((int)CapacitySchedulerConfiguration.Undefined, csConf .GetMaximumApplicationsPerQueue(queue.GetQueuePath())); int expectedMaxApps = (int)(CapacitySchedulerConfiguration.DefaultMaximumSystemApplicatiions * queue.GetAbsoluteCapacity()); NUnit.Framework.Assert.AreEqual(expectedMaxApps, queue.GetMaxApplications()); int expectedMaxAppsPerUser = (int)(expectedMaxApps * (queue.GetUserLimit() / 100.0f ) * queue.GetUserLimitFactor()); NUnit.Framework.Assert.AreEqual(expectedMaxAppsPerUser, queue.GetMaxApplicationsPerUser ()); // should default to global setting if per queue setting not set NUnit.Framework.Assert.AreEqual((long)CapacitySchedulerConfiguration.DefaultMaximumApplicationmastersResourcePercent , (long)csConf.GetMaximumApplicationMasterResourcePerQueuePercent(queue.GetQueuePath ())); // Change the per-queue max AM resources percentage. csConf.SetFloat("yarn.scheduler.capacity." + queue.GetQueuePath() + ".maximum-am-resource-percent" , 0.5f); // Re-create queues to get new configs. queues = new Dictionary <string, CSQueue>(); root = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues, queues , TestUtils.spyHook); clusterResource = Resources.CreateResource(100 * 16 * Gb); queue = (LeafQueue)queues[A]; NUnit.Framework.Assert.AreEqual((long)0.5, (long)csConf.GetMaximumApplicationMasterResourcePerQueuePercent (queue.GetQueuePath())); NUnit.Framework.Assert.AreEqual(queue.GetAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(800 * Gb, 1)); NUnit.Framework.Assert.AreEqual(queue.GetUserAMResourceLimit(), Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(400 * Gb, 1)); // Change the per-queue max applications. csConf.SetInt("yarn.scheduler.capacity." + queue.GetQueuePath() + ".maximum-applications" , 9999); // Re-create queues to get new configs. queues = new Dictionary <string, CSQueue>(); root = CapacityScheduler.ParseQueue(csContext, csConf, null, "root", queues, queues , TestUtils.spyHook); queue = (LeafQueue)queues[A]; NUnit.Framework.Assert.AreEqual(9999, (int)csConf.GetMaximumApplicationsPerQueue( queue.GetQueuePath())); NUnit.Framework.Assert.AreEqual(9999, queue.GetMaxApplications()); expectedMaxAppsPerUser = (int)(9999 * (queue.GetUserLimit() / 100.0f) * queue.GetUserLimitFactor ()); NUnit.Framework.Assert.AreEqual(expectedMaxAppsPerUser, queue.GetMaxApplicationsPerUser ()); }