Exemplo n.º 1
0
 public virtual void TestSingleUserEasyFitPass()
 {
     // generate allocation that easily fit within resource constraints
     int[] f = GenerateData(3600, (int)Math.Ceil(0.2 * totCont));
     NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation
                                                                            (ReservationSystemTestUtil.GetNewReservationId(), null, "u1", "dedicated", initTime
                                                                            , initTime + f.Length, ReservationSystemTestUtil.GenerateAllocation(initTime, step
                                                                                                                                                , f), res, minAlloc)));
 }
Exemplo n.º 2
0
        /// <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 TestSimple()
        {
            PrepareBasicPlan();
            // create a request with a single atomic ask
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(5 * step);
            rr.SetDeadline(20 * step);
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(2048, 2), 10, 5, 10 * step);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetReservationResources(Collections.SingletonList(r));
            rr.SetReservationRequests(reqs);
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();

            agent.CreateReservation(reservationID, "u1", plan, rr);
            NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", reservationID != null
                                          );
            NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", plan.GetAllReservations
                                              ().Count == 3);
            ReservationAllocation cs = plan.GetReservationById(reservationID);

            System.Console.Out.WriteLine("--------AFTER SIMPLE ALLOCATION (queue: " + reservationID
                                         + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
            for (long i = 10 * step; i < 20 * step; i++)
            {
                NUnit.Framework.Assert.IsTrue("Agent-based allocation unexpected", Resources.Equals
                                                  (cs.GetResourcesAtTime(i), Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                      (2048 * 10, 2 * 10)));
            }
        }
        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);
            }
        }