public virtual void TearDown() { if (scheduler != null) { cs.Stop(); } }
/// <exception cref="System.Exception"/> public virtual void TestMaxCapacity() { CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration(); conf.SetQueues(CapacitySchedulerConfiguration.Root, new string[] { "a", "b", "c" } ); string A = CapacitySchedulerConfiguration.Root + ".a"; conf.SetCapacity(A, 50); conf.SetMaximumCapacity(A, 60); string B = CapacitySchedulerConfiguration.Root + ".b"; conf.SetCapacity(B, 50); conf.SetMaximumCapacity(B, 45); // Should throw an exception bool fail = false; CapacityScheduler capacityScheduler; try { capacityScheduler = new CapacityScheduler(); capacityScheduler.SetConf(new YarnConfiguration()); capacityScheduler.Init(conf); capacityScheduler.Start(); capacityScheduler.Reinitialize(conf, null); } catch (ArgumentException) { fail = true; } NUnit.Framework.Assert.IsTrue("Didn't throw IllegalArgumentException for wrong maxCap" , fail); conf.SetMaximumCapacity(B, 60); // Now this should work capacityScheduler = new CapacityScheduler(); capacityScheduler.SetConf(new YarnConfiguration()); capacityScheduler.Init(conf); capacityScheduler.Start(); capacityScheduler.Reinitialize(conf, null); fail = false; try { LeafQueue a = (LeafQueue)capacityScheduler.GetQueue(A); a.SetMaxCapacity(45); } catch (ArgumentException) { fail = true; } NUnit.Framework.Assert.IsTrue("Didn't throw IllegalArgumentException for wrong " + "setMaxCap", fail); capacityScheduler.Stop(); }
public virtual void TestCompareRMNodeAfterReconnect() { Configuration yarnConf = new YarnConfiguration(); CapacityScheduler scheduler = new CapacityScheduler(); scheduler.SetConf(yarnConf); ConfigurationProvider configurationProvider = ConfigurationProviderFactory.GetConfigurationProvider (yarnConf); configurationProvider.Init(yarnConf); context.SetConfigurationProvider(configurationProvider); RMNodeLabelsManager nlm = new RMNodeLabelsManager(); nlm.Init(yarnConf); nlm.Start(); context.SetNodeLabelManager(nlm); scheduler.SetRMContext(context); scheduler.Init(yarnConf); scheduler.Start(); dispatcher.Register(typeof(SchedulerEventType), scheduler); string hostname1 = "localhost1"; Resource capability = BuilderUtils.NewResource(4096, 4); RegisterNodeManagerRequest request1 = recordFactory.NewRecordInstance <RegisterNodeManagerRequest >(); NodeId nodeId1 = NodeId.NewInstance(hostname1, 0); request1.SetNodeId(nodeId1); request1.SetHttpPort(0); request1.SetResource(capability); resourceTrackerService.RegisterNodeManager(request1); NUnit.Framework.Assert.IsNotNull(context.GetRMNodes()[nodeId1]); // verify Scheduler and RMContext use same RMNode reference. NUnit.Framework.Assert.IsTrue(scheduler.GetSchedulerNode(nodeId1).GetRMNode() == context.GetRMNodes()[nodeId1]); NUnit.Framework.Assert.AreEqual(context.GetRMNodes()[nodeId1].GetTotalCapability( ), capability); Resource capability1 = BuilderUtils.NewResource(2048, 2); request1.SetResource(capability1); resourceTrackerService.RegisterNodeManager(request1); NUnit.Framework.Assert.IsNotNull(context.GetRMNodes()[nodeId1]); // verify Scheduler and RMContext use same RMNode reference // after reconnect. NUnit.Framework.Assert.IsTrue(scheduler.GetSchedulerNode(nodeId1).GetRMNode() == context.GetRMNodes()[nodeId1]); // verify RMNode's capability is changed. NUnit.Framework.Assert.AreEqual(context.GetRMNodes()[nodeId1].GetTotalCapability( ), capability1); nlm.Stop(); scheduler.Stop(); }
public virtual void TestQueueParsingWithUnusedLabels() { ImmutableSet <string> labels = ImmutableSet.Of("red", "blue"); // Initialize a cluster with labels, but doesn't use them, reinitialize // shouldn't fail nodeLabelManager.AddToCluserNodeLabels(labels); CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration(); SetupQueueConfiguration(csConf); csConf.SetAccessibleNodeLabels(CapacitySchedulerConfiguration.Root, labels); YarnConfiguration conf = new YarnConfiguration(csConf); CapacityScheduler capacityScheduler = new CapacityScheduler(); capacityScheduler.SetConf(conf); RMContextImpl rmContext = new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(csConf), new NMTokenSecretManagerInRM(csConf), new ClientToAMTokenSecretManagerInRM(), null); rmContext.SetNodeLabelManager(nodeLabelManager); capacityScheduler.SetRMContext(rmContext); capacityScheduler.Init(conf); capacityScheduler.Start(); capacityScheduler.Reinitialize(conf, rmContext); // check root queue's capacity by label -- they should be all zero CSQueue root = capacityScheduler.GetQueue(CapacitySchedulerConfiguration.Root); NUnit.Framework.Assert.AreEqual(0, root.GetQueueCapacities().GetCapacity("red"), Delta); NUnit.Framework.Assert.AreEqual(0, root.GetQueueCapacities().GetCapacity("blue"), Delta); CSQueue a = capacityScheduler.GetQueue("a"); NUnit.Framework.Assert.AreEqual(0.10, a.GetAbsoluteCapacity(), Delta); NUnit.Framework.Assert.AreEqual(0.15, a.GetAbsoluteMaximumCapacity(), Delta); CSQueue b1 = capacityScheduler.GetQueue("b1"); NUnit.Framework.Assert.AreEqual(0.2 * 0.5, b1.GetAbsoluteCapacity(), Delta); NUnit.Framework.Assert.AreEqual("Parent B has no MAX_CAP", 0.85, b1.GetAbsoluteMaximumCapacity (), Delta); CSQueue c12 = capacityScheduler.GetQueue("c12"); NUnit.Framework.Assert.AreEqual(0.7 * 0.5 * 0.45, c12.GetAbsoluteCapacity(), Delta ); NUnit.Framework.Assert.AreEqual(0.7 * 0.55 * 0.7, c12.GetAbsoluteMaximumCapacity( ), Delta); capacityScheduler.Stop(); }
public virtual void TestAddQueueFailCases() { CapacityScheduler cs = (CapacityScheduler)rm.GetResourceScheduler(); try { // Test invalid addition (adding non-zero size queue) ReservationQueue a1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a")); a1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); cs.AddQueue(a1); NUnit.Framework.Assert.Fail(); } catch (Exception) { } // expected // Test add one reservation dynamically and manually modify capacity ReservationQueue a1_1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a" )); cs.AddQueue(a1_1); a1_1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); // Test add another reservation queue and use setEntitlement to modify // capacity ReservationQueue a2 = new ReservationQueue(cs, "a2", (PlanQueue)cs.GetQueue("a")); cs.AddQueue(a2); try { // Test invalid entitlement (sum of queues exceed 100%) cs.SetEntitlement("a2", new QueueEntitlement(A2Capacity / 100 + 0.1f, 1.0f)); NUnit.Framework.Assert.Fail(); } catch (Exception) { } // expected cs.SetEntitlement("a2", new QueueEntitlement(A2Capacity / 100, 1.0f)); // Verify all allocations match tcs.CheckQueueCapacities(cs, ACapacity, BCapacity); cs.Stop(); }