private ReservationUpdateRequest CreateSimpleReservationUpdateRequest(int numRequests
                                                                              , int numContainers, long arrival, long deadline, long duration)
        {
            // create a request with a single atomic ask
            ReservationUpdateRequest request = new ReservationUpdateRequestPBImpl();
            ReservationDefinition    rDef    = new ReservationDefinitionPBImpl();

            rDef.SetArrival(arrival);
            rDef.SetDeadline(deadline);
            if (numRequests > 0)
            {
                ReservationRequests reqs = new ReservationRequestsPBImpl();
                rDef.SetReservationRequests(reqs);
                if (numContainers > 0)
                {
                    ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                          .NewInstance(1024, 1), numContainers, 1, duration);
                    reqs.SetReservationResources(Sharpen.Collections.SingletonList(r));
                    reqs.SetInterpreter(ReservationRequestInterpreter.RAll);
                }
            }
            request.SetReservationDefinition(rDef);
            request.SetReservationId(ReservationSystemTestUtil.GetNewReservationId());
            return(request);
        }
        public static ReservationDefinition GenerateBigRR(Random rand, long i)
        {
            rand.SetSeed(i);
            long now = Runtime.CurrentTimeMillis();
            // start time at random in the next 2 hours
            long arrival = rand.Next(2 * 3600 * 1000);
            // deadline at random in the next day
            long deadline = rand.Next(24 * 3600 * 1000);
            // create a request with a single atomic ask
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(now + arrival);
            rr.SetDeadline(now + deadline);
            int gang = 1;
            int par  = 100000;
            // 100k tasks
            long dur = rand.Next(60 * 1000);
            // 1min tasks
            ReservationRequest r = ReservationRequest.NewInstance(Resource.NewInstance(1024,
                                                                                       1), par, gang, dur);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetReservationResources(Collections.SingletonList(r));
            rand.Next(3);
            ReservationRequestInterpreter[] type = ReservationRequestInterpreter.Values();
            reqs.SetInterpreter(type[rand.Next(type.Length)]);
            rr.SetReservationRequests(reqs);
            return(rr);
        }
        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 TestOrder()
        {
            PrepareBasicPlan();
            // create a completely utilized segment around time 30
            int[] f = new int[] { 100, 100 };
            NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation
                                                                                   (ReservationSystemTestUtil.GetNewReservationId(), null, "u1", "dedicated", 30 *
                                                                                   step, 30 * step + f.Length * step, ReservationSystemTestUtil.GenerateAllocation(
                                                                                       30 * step, step, f), res, minAlloc)));
            // create a chain of 4 RR, mixing gang and non-gang
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(0 * step);
            rr.SetDeadline(70 * step);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetInterpreter(ReservationRequestInterpreter.ROrder);
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(2048, 2), 10, 1, 10 * step);
            ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1024, 1), 10, 10, 20 * step);
            IList <ReservationRequest> list = new AList <ReservationRequest>();

            list.AddItem(r);
            list.AddItem(r2);
            list.AddItem(r);
            list.AddItem(r2);
            reqs.SetReservationResources(list);
            rr.SetReservationRequests(reqs);
            // submit to agent
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();

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

            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 0 * step, 10 * step, 20, 1024
                                                               , 1));
            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 10 * step, 30 * step, 10,
                                                               1024, 1));
            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 40 * step, 50 * step, 20,
                                                               1024, 1));
            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 50 * step, 70 * step, 10,
                                                               1024, 1));
            System.Console.Out.WriteLine("--------AFTER ORDER ALLOCATION (queue: " + reservationID
                                         + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
        }
        public virtual void TestOrderNoGapImpossible()
        {
            PrepareBasicPlan();
            // create a completely utilized segment at time 30
            int[] f = new int[] { 100, 100 };
            NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation
                                                                                   (ReservationSystemTestUtil.GetNewReservationId(), null, "u1", "dedicated", 30 *
                                                                                   step, 30 * step + f.Length * step, ReservationSystemTestUtil.GenerateAllocation(
                                                                                       30 * step, step, f), res, minAlloc)));
            // create a chain of 4 RR, mixing gang and non-gang
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(0L);
            rr.SetDeadline(70L);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetInterpreter(ReservationRequestInterpreter.ROrderNoGap);
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(2048, 2), 10, 1, 10);
            ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1024, 1), 10, 10, 20);
            IList <ReservationRequest> list = new AList <ReservationRequest>();

            list.AddItem(r);
            list.AddItem(r2);
            list.AddItem(r);
            list.AddItem(r2);
            reqs.SetReservationResources(list);
            rr.SetReservationRequests(reqs);
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();
            bool          result        = false;

            try
            {
                // submit to agent
                result = agent.CreateReservation(reservationID, "u1", plan, rr);
                NUnit.Framework.Assert.Fail();
            }
            catch (PlanningException)
            {
            }
            // expected
            // validate
            NUnit.Framework.Assert.IsFalse("Agent-based allocation should have failed", result
                                           );
            NUnit.Framework.Assert.IsTrue("Agent-based allocation should have failed", plan.GetAllReservations
                                              ().Count == 3);
            System.Console.Out.WriteLine("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: "
                                         + reservationID + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
        }
Exemplo n.º 6
0
        private ReservationDefinition CreateSimpleReservationDefinition(long arrival, long
                                                                        deadline, long duration, ICollection <ReservationRequest> resources)
        {
            // create a request with a single atomic ask
            ReservationDefinition rDef = new ReservationDefinitionPBImpl();
            ReservationRequests   reqs = new ReservationRequestsPBImpl();

            reqs.SetReservationResources(new AList <ReservationRequest>(resources));
            reqs.SetInterpreter(ReservationRequestInterpreter.RAll);
            rDef.SetReservationRequests(reqs);
            rDef.SetArrival(arrival);
            rDef.SetDeadline(deadline);
            return(rDef);
        }
        private ReservationDefinition CreateSimpleReservationDefinition(long arrival, long
                                                                        deadline, long duration)
        {
            // create a request with a single atomic ask
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(1024, 1), 1, 1, duration);
            ReservationDefinition rDef = new ReservationDefinitionPBImpl();
            ReservationRequests   reqs = new ReservationRequestsPBImpl();

            reqs.SetReservationResources(Sharpen.Collections.SingletonList(r));
            reqs.SetInterpreter(ReservationRequestInterpreter.RAll);
            rDef.SetReservationRequests(reqs);
            rDef.SetArrival(arrival);
            rDef.SetDeadline(deadline);
            return(rDef);
        }
        public virtual void TestAnyImpossible()
        {
            PrepareBasicPlan();
            // create an ANY request, with all impossible alternatives
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(100L);
            rr.SetDeadline(120L);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetInterpreter(ReservationRequestInterpreter.RAny);
            // longer than arrival-deadline
            ReservationRequest r1 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1024, 1), 35, 5, 30);
            // above max cluster size
            ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1024, 1), 110, 110, 10);
            IList <ReservationRequest> list = new AList <ReservationRequest>();

            list.AddItem(r1);
            list.AddItem(r2);
            reqs.SetReservationResources(list);
            rr.SetReservationRequests(reqs);
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();
            bool          result        = false;

            try
            {
                // submit to agent
                result = agent.CreateReservation(reservationID, "u1", plan, rr);
                NUnit.Framework.Assert.Fail();
            }
            catch (PlanningException)
            {
            }
            // expected
            // validate results, we expect the second one to be accepted
            NUnit.Framework.Assert.IsFalse("Agent-based allocation should have failed", result
                                           );
            NUnit.Framework.Assert.IsTrue("Agent-based allocation should have failed", plan.GetAllReservations
                                              ().Count == 2);
            System.Console.Out.WriteLine("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: " +
                                         reservationID + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
        }
        public virtual void TestAny()
        {
            PrepareBasicPlan();
            // create an ANY request, with an impossible step (last in list, first
            // considered),
            // and two satisfiable ones. We expect the second one to be returned.
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(100 * step);
            rr.SetDeadline(120 * step);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetInterpreter(ReservationRequestInterpreter.RAny);
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(1024, 1), 5, 5, 10 * step);
            ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(2048, 2), 10, 5, 10 * step);
            ReservationRequest r3 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1024, 1), 110, 110, 10 * step);
            IList <ReservationRequest> list = new AList <ReservationRequest>();

            list.AddItem(r);
            list.AddItem(r2);
            list.AddItem(r3);
            reqs.SetReservationResources(list);
            rr.SetReservationRequests(reqs);
            // submit to agent
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();
            bool          res           = agent.CreateReservation(reservationID, "u1", plan, rr);

            // validate results, we expect the second one to be accepted
            NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", res);
            NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", plan.GetAllReservations
                                              ().Count == 3);
            ReservationAllocation cs = plan.GetReservationById(reservationID);

            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 110 * step, 120 * step, 20
                                                               , 1024, 1));
            System.Console.Out.WriteLine("--------AFTER ANY ALLOCATION (queue: " + reservationID
                                         + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
        }
        public virtual void TestSingleSliding()
        {
            PrepareBasicPlan();
            // create a single request for which we need subsequent (tight) packing.
            ReservationDefinition rr = new ReservationDefinitionPBImpl();

            rr.SetArrival(100 * step);
            rr.SetDeadline(120 * step);
            ReservationRequests reqs = new ReservationRequestsPBImpl();

            reqs.SetInterpreter(ReservationRequestInterpreter.RAll);
            ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                  .NewInstance(1024, 1), 200, 10, 10 * step);
            IList <ReservationRequest> list = new AList <ReservationRequest>();

            list.AddItem(r);
            reqs.SetReservationResources(list);
            rr.SetReservationRequests(reqs);
            // submit to agent
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();

            agent.CreateReservation(reservationID, "u1", plan, rr);
            // validate results, we expect the second one to be accepted
            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);

            NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 100 * step, 120 * step, 100
                                                               , 1024, 1));
            System.Console.Out.WriteLine("--------AFTER packed ALLOCATION (queue: " + reservationID
                                         + ")----------");
            System.Console.Out.WriteLine(plan.ToString());
            System.Console.Out.WriteLine(plan.ToCumulativeString());
        }