public virtual void TestUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); // Try to update a reservation without adding int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = GenerateAllocation (start, alloc, false); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.UpdateReservation(rAllocation); NUnit.Framework.Assert.Fail("Update should fail as it does not exist in the plan" ); } catch (ArgumentException e) { NUnit.Framework.Assert.IsTrue(e.Message.EndsWith("does not exist in the plan")); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); }
public virtual void TestAddReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = GenerateAllocation (start, alloc, false); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } DoAssertions(plan, rAllocation); for (int i = 0; i < alloc.Length; i++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetTotalCommittedResources(start + i)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetConsumptionForUser(user, start + i)); } }
public virtual void Setup() { // 24h window timeWindow = 86400000L; // 1 sec step step = 1000L; // 25% avg cap on capacity avgConstraint = 25; // 70% instantaneous cap on capacity instConstraint = 70; initTime = Runtime.CurrentTimeMillis(); minAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(1024, 1); res = new DefaultResourceCalculator(); maxAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(1024 * 8, 8); mAgent = Org.Mockito.Mockito.Mock <ReservationAgent>(); ReservationSystemTestUtil testUtil = new ReservationSystemTestUtil(); QueueMetrics rootQueueMetrics = Org.Mockito.Mockito.Mock <QueueMetrics>(); string reservationQ = testUtil.GetFullReservationQueueName(); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = ReservationSystemTestUtil .CalculateClusterResource(totCont); ReservationSchedulerConfiguration conf = ReservationSystemTestUtil.CreateConf(reservationQ , timeWindow, instConstraint, avgConstraint); CapacityOverTimePolicy policy = new CapacityOverTimePolicy(); policy.Init(reservationQ, conf); plan = new InMemoryPlan(rootQueueMetrics, policy, mAgent, clusterResource, step, res, minAlloc, maxAlloc, "dedicated", null, true); }
public virtual void TestAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); int[] alloc = new int[] { }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = new Dictionary <ReservationInterval, ReservationRequest>(); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } }
public virtual void Setup() { long seed = rand.NextLong(); rand.SetSeed(seed); Org.Mortbay.Log.Log.Info("Running with seed: " + seed); // setting completely loose quotas long timeWindow = 1000000L; Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterCapacity = Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(100 * 1024, 100); step = 1000L; ReservationSystemTestUtil testUtil = new ReservationSystemTestUtil(); string reservationQ = testUtil.GetFullReservationQueueName(); float instConstraint = 100; float avgConstraint = 100; ReservationSchedulerConfiguration conf = ReservationSystemTestUtil.CreateConf(reservationQ , timeWindow, instConstraint, avgConstraint); CapacityOverTimePolicy policy = new CapacityOverTimePolicy(); policy.Init(reservationQ, conf); agent = new GreedyReservationAgent(); QueueMetrics queueMetrics = Org.Mockito.Mockito.Mock <QueueMetrics>(); plan = new InMemoryPlan(queueMetrics, policy, agent, clusterCapacity, step, res, minAlloc, maxAlloc, "dedicated", null, true); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.PlanningException /// "/> /// <exception cref="System.IO.IOException"/> public virtual void TestStress(int numJobs) { long timeWindow = 1000000L; Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterCapacity = Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(500 * 100 * 1024, 500 * 32); step = 1000L; ReservationSystemTestUtil testUtil = new ReservationSystemTestUtil(); CapacityScheduler scheduler = testUtil.MockCapacityScheduler(500 * 100); string reservationQ = testUtil.GetFullReservationQueueName(); float instConstraint = 100; float avgConstraint = 100; ReservationSchedulerConfiguration conf = ReservationSystemTestUtil.CreateConf(reservationQ , timeWindow, instConstraint, avgConstraint); CapacityOverTimePolicy policy = new CapacityOverTimePolicy(); policy.Init(reservationQ, conf); plan = new InMemoryPlan(scheduler.GetRootQueueMetrics(), policy, agent, clusterCapacity , step, res, minAlloc, maxAlloc, "dedicated", null, true); int acc = 0; IList <ReservationDefinition> list = new AList <ReservationDefinition>(); for (long i = 0; i < numJobs; i++) { list.AddItem(ReservationSystemTestUtil.GenerateRandomRR(rand, i)); } long start = Runtime.CurrentTimeMillis(); for (int i_1 = 0; i_1 < numJobs; i_1++) { try { if (agent.CreateReservation(ReservationSystemTestUtil.GetNewReservationId(), "u" + i_1 % 100, plan, list[i_1])) { acc++; } } catch (PlanningException) { } } // ignore exceptions long end = Runtime.CurrentTimeMillis(); System.Console.Out.WriteLine("Submitted " + numJobs + " jobs " + " accepted " + acc + " in " + (end - start) + "ms"); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> protected internal virtual Plan InitializePlan(string planQueueName) { string planQueuePath = GetPlanQueuePath(planQueueName); SharingPolicy adPolicy = GetAdmissionPolicy(planQueuePath); adPolicy.Init(planQueuePath, GetReservationSchedulerConfiguration()); // Calculate the max plan capacity Resource minAllocation = GetMinAllocation(); Resource maxAllocation = GetMaxAllocation(); ResourceCalculator rescCalc = GetResourceCalculator(); Org.Apache.Hadoop.Yarn.Api.Records.Resource totCap = GetPlanQueueCapacity(planQueueName ); Plan plan = new InMemoryPlan(GetRootQueueMetrics(), adPolicy, GetAgent(planQueuePath ), totCap, planStepSize, rescCalc, minAllocation, maxAllocation, planQueueName, GetReplanner(planQueuePath), GetReservationSchedulerConfiguration().GetMoveOnExpiry (planQueuePath)); Log.Info("Intialized plan {0} based on reservable queue {1}", plan.ToString(), planQueueName ); return(plan); }
public virtual void Setup() { // 1 sec step step = 1000L; initTime = Runtime.CurrentTimeMillis(); minAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(1024, 1); res = new DefaultResourceCalculator(); maxAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(1024 * 8, 8); mAgent = Org.Mockito.Mockito.Mock <ReservationAgent>(); ReservationSystemTestUtil testUtil = new ReservationSystemTestUtil(); string reservationQ = testUtil.GetFullReservationQueueName(); QueueMetrics rootQueueMetrics = Org.Mockito.Mockito.Mock <QueueMetrics>(); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = ReservationSystemTestUtil .CalculateClusterResource(totCont); ReservationSchedulerConfiguration conf = Org.Mockito.Mockito.Mock <ReservationSchedulerConfiguration >(); NoOverCommitPolicy policy = new NoOverCommitPolicy(); policy.Init(reservationQ, conf); plan = new InMemoryPlan(rootQueueMetrics, policy, mAgent, clusterResource, step, res, minAlloc, maxAlloc, "dedicated", null, true); }
public virtual void TestDeleteNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); // Try to delete a reservation without adding NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.DeleteReservation(reservationID); NUnit.Framework.Assert.Fail("Delete should fail as it does not exist in the plan" ); } catch (ArgumentException e) { NUnit.Framework.Assert.IsTrue(e.Message.EndsWith("does not exist in the plan")); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); }
public virtual void TestArchiveCompletedReservations() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID1 = ReservationSystemTestUtil.GetNewReservationId(); // First add a reservation int[] alloc1 = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations1 = GenerateAllocation (start, alloc1, false); ReservationDefinition rDef1 = CreateSimpleReservationDefinition(start, start + alloc1 .Length, alloc1.Length, allocations1.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID1 , rDef1, user, planName, start, start + alloc1.Length, allocations1, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID1)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } DoAssertions(plan, rAllocation); for (int i = 0; i < alloc1.Length; i++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i]), (alloc1[i])), plan.GetTotalCommittedResources(start + i)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i]), (alloc1[i])), plan.GetConsumptionForUser(user, start + i)); } // Now add another one ReservationId reservationID2 = ReservationSystemTestUtil.GetNewReservationId(); int[] alloc2 = new int[] { 0, 5, 10, 5, 0 }; IDictionary <ReservationInterval, ReservationRequest> allocations2 = GenerateAllocation (start, alloc2, true); ReservationDefinition rDef2 = CreateSimpleReservationDefinition(start, start + alloc2 .Length, alloc2.Length, allocations2.Values); rAllocation = new InMemoryReservationAllocation(reservationID2, rDef2, user, planName , start, start + alloc2.Length, allocations2, resCalc, minAlloc); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID2)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(reservationID2)); for (int i_1 = 0; i_1 < alloc2.Length; i_1++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i_1] + alloc2[i_1] + i_1), alloc1[i_1] + alloc2[i_1] + i_1), plan .GetTotalCommittedResources(start + i_1)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i_1] + alloc2[i_1] + i_1), alloc1[i_1] + alloc2[i_1] + i_1), plan .GetConsumptionForUser(user, start + i_1)); } // Now archive completed reservations Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(106L); Org.Mockito.Mockito.When(policy.GetValidWindow()).ThenReturn(1L); try { // will only remove 2nd reservation as only that has fallen out of the // archival window plan.ArchiveCompletedReservations(clock.GetTime()); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(reservationID1)); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID2)); for (int i_2 = 0; i_2 < alloc1.Length; i_2++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i_2]), (alloc1[i_2])), plan.GetTotalCommittedResources(start + i_2 )); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc1[i_2]), (alloc1[i_2])), plan.GetConsumptionForUser(user, start + i_2)); } Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(107L); try { // will remove 1st reservation also as it has fallen out of the archival // window plan.ArchiveCompletedReservations(clock.GetTime()); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID1)); for (int i_3 = 0; i_3 < alloc1.Length; i_3++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (0, 0), plan.GetTotalCommittedResources(start + i_3)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (0, 0), plan.GetConsumptionForUser(user, start + i_3)); } }
public virtual void TestReplanningPlanCapacityLoss() { Resource clusterCapacity = Resource.NewInstance(100 * 1024, 10); Resource minAlloc = Resource.NewInstance(1024, 1); Resource maxAlloc = Resource.NewInstance(1024 * 8, 8); ResourceCalculator res = new DefaultResourceCalculator(); long step = 1L; Clock clock = Org.Mockito.Mockito.Mock <Clock>(); ReservationAgent agent = Org.Mockito.Mockito.Mock <ReservationAgent>(); SharingPolicy policy = new NoOverCommitPolicy(); policy.Init("root.dedicated", null); QueueMetrics queueMetrics = Org.Mockito.Mockito.Mock <QueueMetrics>(); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(0L); SimpleCapacityReplanner enf = new SimpleCapacityReplanner(clock); ReservationSchedulerConfiguration conf = Org.Mockito.Mockito.Mock <ReservationSchedulerConfiguration >(); Org.Mockito.Mockito.When(conf.GetEnforcementWindow(Matchers.Any <string>())).ThenReturn (6L); enf.Init("blah", conf); // Initialize the plan with more resources InMemoryPlan plan = new InMemoryPlan(queueMetrics, policy, agent, clusterCapacity , step, res, minAlloc, maxAlloc, "dedicated", enf, true, clock); // add reservation filling the plan (separating them 1ms, so we are sure // s2 follows s1 on acceptance long ts = Runtime.CurrentTimeMillis(); ReservationId r1 = ReservationId.NewInstance(ts, 1); int[] f5 = new int[] { 20, 20, 20, 20, 20 }; NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r1, null, "u3", "dedicated", 0, 0 + f5.Length, GenerateAllocation(0, f5), res, minAlloc))); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(1L); ReservationId r2 = ReservationId.NewInstance(ts, 2); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r2, null, "u4", "dedicated", 0, 0 + f5.Length, GenerateAllocation(0, f5), res, minAlloc))); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(2L); ReservationId r3 = ReservationId.NewInstance(ts, 3); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r3, null, "u5", "dedicated", 0, 0 + f5.Length, GenerateAllocation(0, f5), res, minAlloc))); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(3L); ReservationId r4 = ReservationId.NewInstance(ts, 4); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r4, null, "u6", "dedicated", 0, 0 + f5.Length, GenerateAllocation(0, f5), res, minAlloc))); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(4L); ReservationId r5 = ReservationId.NewInstance(ts, 5); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r5, null, "u7", "dedicated", 0, 0 + f5.Length, GenerateAllocation(0, f5), res, minAlloc))); int[] f6 = new int[] { 50, 50, 50, 50, 50 }; ReservationId r6 = ReservationId.NewInstance(ts, 6); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r6, null, "u3", "dedicated", 10, 10 + f6.Length, GenerateAllocation(10, f6), res , minAlloc))); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(6L); ReservationId r7 = ReservationId.NewInstance(ts, 7); NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (r7, null, "u4", "dedicated", 10, 10 + f6.Length, GenerateAllocation(10, f6), res , minAlloc))); // remove some of the resources (requires replanning) plan.SetTotalCapacity(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(70 * 1024, 70)); Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(0L); // run the replanner enf.Plan(plan, null); // check which reservation are still present NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(r1)); NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(r2)); NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(r3)); NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(r6)); NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(r7)); // and which ones are removed NUnit.Framework.Assert.IsNull(plan.GetReservationById(r4)); NUnit.Framework.Assert.IsNull(plan.GetReservationById(r5)); // check resources at each moment in time no more exceed capacity for (int i = 0; i < 20; i++) { int tot = 0; foreach (ReservationAllocation r in plan.GetReservationsAtTime(i)) { tot = r.GetResourcesAtTime(i).GetMemory(); } NUnit.Framework.Assert.IsTrue(tot <= 70 * 1024); } }