Exemple #1
0
        public virtual void TestResourceOverCommit()
        {
            MockRM rm = new MockRM(conf);

            rm.Start();
            MockNM nm1  = rm.RegisterNode("127.0.0.1:1234", 4 * Gb);
            RMApp  app1 = rm.SubmitApp(2048);

            // kick the scheduling, 2 GB given to AM1, remaining 2GB on nm1
            nm1.NodeHeartbeat(true);
            RMAppAttempt attempt1 = app1.GetCurrentAppAttempt();
            MockAM       am1      = rm.SendAMLaunched(attempt1.GetAppAttemptId());

            am1.RegisterAppAttempt();
            SchedulerNodeReport report_nm1 = rm.GetResourceScheduler().GetNodeReport(nm1.GetNodeId
                                                                                         ());

            // check node report, 2 GB used and 2 GB available
            NUnit.Framework.Assert.AreEqual(2 * Gb, report_nm1.GetUsedResource().GetMemory());
            NUnit.Framework.Assert.AreEqual(2 * Gb, report_nm1.GetAvailableResource().GetMemory
                                                ());
            // add request for containers
            am1.AddRequests(new string[] { "127.0.0.1", "127.0.0.2" }, 2 * Gb, 1, 1);
            AllocateResponse alloc1Response = am1.Schedule();

            // send the request
            // kick the scheduler, 2 GB given to AM1, resource remaining 0
            nm1.NodeHeartbeat(true);
            while (alloc1Response.GetAllocatedContainers().Count < 1)
            {
                Log.Info("Waiting for containers to be created for app 1...");
                Sharpen.Thread.Sleep(1000);
                alloc1Response = am1.Schedule();
            }
            IList <Container> allocated1 = alloc1Response.GetAllocatedContainers();

            NUnit.Framework.Assert.AreEqual(1, allocated1.Count);
            NUnit.Framework.Assert.AreEqual(2 * Gb, allocated1[0].GetResource().GetMemory());
            NUnit.Framework.Assert.AreEqual(nm1.GetNodeId(), allocated1[0].GetNodeId());
            report_nm1 = rm.GetResourceScheduler().GetNodeReport(nm1.GetNodeId());
            // check node report, 4 GB used and 0 GB available
            NUnit.Framework.Assert.AreEqual(0, report_nm1.GetAvailableResource().GetMemory());
            NUnit.Framework.Assert.AreEqual(4 * Gb, report_nm1.GetUsedResource().GetMemory());
            // check container is assigned with 2 GB.
            Container c1 = allocated1[0];

            NUnit.Framework.Assert.AreEqual(2 * Gb, c1.GetResource().GetMemory());
            // update node resource to 2 GB, so resource is over-consumed.
            IDictionary <NodeId, ResourceOption> nodeResourceMap = new Dictionary <NodeId, ResourceOption
                                                                                   >();

            nodeResourceMap[nm1.GetNodeId()] = ResourceOption.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                          .NewInstance(2 * Gb, 1), -1);
            UpdateNodeResourceRequest request = UpdateNodeResourceRequest.NewInstance(nodeResourceMap
                                                                                      );
            AdminService @as = rm.adminService;

            @as.UpdateNodeResource(request);
            // Now, the used resource is still 4 GB, and available resource is minus value.
            report_nm1 = rm.GetResourceScheduler().GetNodeReport(nm1.GetNodeId());
            NUnit.Framework.Assert.AreEqual(4 * Gb, report_nm1.GetUsedResource().GetMemory());
            NUnit.Framework.Assert.AreEqual(-2 * Gb, report_nm1.GetAvailableResource().GetMemory
                                                ());
            // Check container can complete successfully in case of resource over-commitment.
            ContainerStatus containerStatus = BuilderUtils.NewContainerStatus(c1.GetId(), ContainerState
                                                                              .Complete, string.Empty, 0);

            nm1.ContainerStatus(containerStatus);
            int waitCount = 0;

            while (attempt1.GetJustFinishedContainers().Count < 1 && waitCount++ != 20)
            {
                Log.Info("Waiting for containers to be finished for app 1... Tried " + waitCount
                         + " times already..");
                Sharpen.Thread.Sleep(100);
            }
            NUnit.Framework.Assert.AreEqual(1, attempt1.GetJustFinishedContainers().Count);
            NUnit.Framework.Assert.AreEqual(1, am1.Schedule().GetCompletedContainersStatuses(
                                                ).Count);
            report_nm1 = rm.GetResourceScheduler().GetNodeReport(nm1.GetNodeId());
            NUnit.Framework.Assert.AreEqual(2 * Gb, report_nm1.GetUsedResource().GetMemory());
            // As container return 2 GB back, the available resource becomes 0 again.
            NUnit.Framework.Assert.AreEqual(0 * Gb, report_nm1.GetAvailableResource().GetMemory
                                                ());
            rm.Stop();
        }