Exemplo n.º 1
0
 /// <summary>Process resource update on a node.</summary>
 public virtual void UpdateNodeResource(RMNode nm, ResourceOption resourceOption)
 {
     lock (this)
     {
         SchedulerNode node = GetSchedulerNode(nm.GetNodeID());
         Org.Apache.Hadoop.Yarn.Api.Records.Resource newResource = resourceOption.GetResource
                                                                       ();
         Org.Apache.Hadoop.Yarn.Api.Records.Resource oldResource = node.GetTotalResource();
         if (!oldResource.Equals(newResource))
         {
             // Log resource change
             Log.Info("Update resource on node: " + node.GetNodeName() + " from: " + oldResource
                      + ", to: " + newResource);
             Sharpen.Collections.Remove(nodes, nm.GetNodeID());
             UpdateMaximumAllocation(node, false);
             // update resource to node
             node.SetTotalResource(newResource);
             nodes[nm.GetNodeID()] = (N)node;
             UpdateMaximumAllocation(node, true);
             // update resource to clusterResource
             Resources.SubtractFrom(clusterResource, oldResource);
             Resources.AddTo(clusterResource, newResource);
         }
         else
         {
             // Log resource change
             Log.Warn("Update resource on node: " + node.GetNodeName() + " with the same resource: "
                      + newResource);
         }
     }
 }
Exemplo n.º 2
0
        public virtual void TestRMNMInfoMissmatch()
        {
            RMContext         rmc = Org.Mockito.Mockito.Mock <RMContext>();
            ResourceScheduler rms = Org.Mockito.Mockito.Mock <ResourceScheduler>();
            ConcurrentMap <NodeId, RMNode> map = new ConcurrentHashMap <NodeId, RMNode>();
            RMNode node = MockNodes.NewNodeInfo(1, MockNodes.NewResource(4 * 1024));

            map[node.GetNodeID()] = node;
            Org.Mockito.Mockito.When(rmc.GetRMNodes()).ThenReturn(map);
            RMNMInfo     rmInfo  = new RMNMInfo(rmc, rms);
            string       liveNMs = rmInfo.GetLiveNodeManagers();
            ObjectMapper mapper  = new ObjectMapper();
            JsonNode     jn      = mapper.ReadTree(liveNMs);

            NUnit.Framework.Assert.AreEqual("Unexpected number of live nodes:", 1, jn.Size());
            IEnumerator <JsonNode> it = jn.GetEnumerator();

            while (it.HasNext())
            {
                JsonNode n = it.Next();
                NUnit.Framework.Assert.IsNotNull(n.Get("HostName"));
                NUnit.Framework.Assert.IsNotNull(n.Get("Rack"));
                NUnit.Framework.Assert.IsTrue("Node " + n.Get("NodeId") + " should be RUNNING", n
                                              .Get("State").AsText().Contains("RUNNING"));
                NUnit.Framework.Assert.IsNotNull(n.Get("NodeHTTPAddress"));
                NUnit.Framework.Assert.IsNotNull(n.Get("LastHealthUpdate"));
                NUnit.Framework.Assert.IsNotNull(n.Get("HealthReport"));
                NUnit.Framework.Assert.IsNotNull(n.Get("NodeManagerVersion"));
                NUnit.Framework.Assert.IsNull(n.Get("NumContainers"));
                NUnit.Framework.Assert.IsNull(n.Get("UsedMemoryMB"));
                NUnit.Framework.Assert.IsNull(n.Get("AvailableMemoryMB"));
            }
        }
Exemplo n.º 3
0
        public NodeInfo(RMNode ni, ResourceScheduler sched)
        {
            // JAXB needs this
            NodeId id = ni.GetNodeID();
            SchedulerNodeReport report = sched.GetNodeReport(id);

            this.numContainers = 0;
            this.usedMemoryMB  = 0;
            this.availMemoryMB = 0;
            if (report != null)
            {
                this.numContainers         = report.GetNumContainers();
                this.usedMemoryMB          = report.GetUsedResource().GetMemory();
                this.availMemoryMB         = report.GetAvailableResource().GetMemory();
                this.usedVirtualCores      = report.GetUsedResource().GetVirtualCores();
                this.availableVirtualCores = report.GetAvailableResource().GetVirtualCores();
            }
            this.id               = id.ToString();
            this.rack             = ni.GetRackName();
            this.nodeHostName     = ni.GetHostName();
            this.state            = ni.GetState();
            this.nodeHTTPAddress  = ni.GetHttpAddress();
            this.lastHealthUpdate = ni.GetLastHealthReportTime();
            this.healthReport     = ni.GetHealthReport().ToString();
            this.version          = ni.GetNodeManagerVersion();
            // add labels
            ICollection <string> labelSet = ni.GetNodeLabels();

            if (labelSet != null)
            {
                Sharpen.Collections.AddAll(nodeLabels, labelSet);
                nodeLabels.Sort();
            }
        }
Exemplo n.º 4
0
 private void KillOrphanContainerOnNode(RMNode node, NMContainerStatus container)
 {
     if (!container.GetContainerState().Equals(ContainerState.Complete))
     {
         this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMNodeCleanContainerEvent
                                                                     (node.GetNodeID(), container.GetContainerId()));
     }
 }
Exemplo n.º 5
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual UpdateNodeResourceResponse UpdateNodeResource(UpdateNodeResourceRequest
                                                                     request)
        {
            string argName            = "updateNodeResource";
            UserGroupInformation user = CheckAcls(argName);

            CheckRMStatus(user.GetShortUserName(), argName, "update node resource.");
            IDictionary <NodeId, ResourceOption> nodeResourceMap = request.GetNodeResourceMap(
                );
            ICollection <NodeId> nodeIds = nodeResourceMap.Keys;

            // verify nodes are all valid first.
            // if any invalid nodes, throw exception instead of partially updating
            // valid nodes.
            foreach (NodeId nodeId in nodeIds)
            {
                RMNode node = this.rmContext.GetRMNodes()[nodeId];
                if (node == null)
                {
                    Log.Error("Resource update get failed on all nodes due to change " + "resource on an unrecognized node: "
                              + nodeId);
                    throw RPCUtil.GetRemoteException("Resource update get failed on all nodes due to change resource "
                                                     + "on an unrecognized node: " + nodeId);
                }
            }
            // do resource update on each node.
            // Notice: it is still possible to have invalid NodeIDs as nodes decommission
            // may happen just at the same time. This time, only log and skip absent
            // nodes without throwing any exceptions.
            bool allSuccess = true;

            foreach (KeyValuePair <NodeId, ResourceOption> entry in nodeResourceMap)
            {
                ResourceOption newResourceOption = entry.Value;
                NodeId         nodeId_1          = entry.Key;
                RMNode         node = this.rmContext.GetRMNodes()[nodeId_1];
                if (node == null)
                {
                    Log.Warn("Resource update get failed on an unrecognized node: " + nodeId_1);
                    allSuccess = false;
                }
                else
                {
                    // update resource to RMNode
                    this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMNodeResourceUpdateEvent
                                                                                (nodeId_1, newResourceOption));
                    Log.Info("Update resource on node(" + node.GetNodeID() + ") with resource(" + newResourceOption
                             .ToString() + ")");
                }
            }
            if (allSuccess)
            {
                RMAuditLogger.LogSuccess(user.GetShortUserName(), argName, "AdminService");
            }
            UpdateNodeResourceResponse response = UpdateNodeResourceResponse.NewInstance();

            return(response);
        }
Exemplo n.º 6
0
 private void NodeUpdate(RMNode rmNode)
 {
     lock (this)
     {
         FiCaSchedulerNode            node = GetNode(rmNode.GetNodeID());
         IList <UpdatedContainerInfo> containerInfoList       = rmNode.PullContainerUpdates();
         IList <ContainerStatus>      newlyLaunchedContainers = new AList <ContainerStatus>();
         IList <ContainerStatus>      completedContainers     = new AList <ContainerStatus>();
         foreach (UpdatedContainerInfo containerInfo in containerInfoList)
         {
             Sharpen.Collections.AddAll(newlyLaunchedContainers, containerInfo.GetNewlyLaunchedContainers
                                            ());
             Sharpen.Collections.AddAll(completedContainers, containerInfo.GetCompletedContainers
                                            ());
         }
         // Processing the newly launched containers
         foreach (ContainerStatus launchedContainer in newlyLaunchedContainers)
         {
             ContainerLaunchedOnNode(launchedContainer.GetContainerId(), node);
         }
         // Process completed containers
         foreach (ContainerStatus completedContainer in completedContainers)
         {
             ContainerId containerId = completedContainer.GetContainerId();
             Log.Debug("Container FINISHED: " + containerId);
             CompletedContainer(GetRMContainer(containerId), completedContainer, RMContainerEventType
                                .Finished);
         }
         if (rmContext.IsWorkPreservingRecoveryEnabled() && !rmContext.IsSchedulerReadyForAllocatingContainers
                 ())
         {
             return;
         }
         if (Resources.GreaterThanOrEqual(resourceCalculator, clusterResource, node.GetAvailableResource
                                              (), minimumAllocation))
         {
             Log.Debug("Node heartbeat " + rmNode.GetNodeID() + " available resource = " + node
                       .GetAvailableResource());
             AssignContainers(node);
             Log.Debug("Node after allocation " + rmNode.GetNodeID() + " resource = " + node.GetAvailableResource
                           ());
         }
         UpdateAvailableResourcesMetrics();
     }
 }
Exemplo n.º 7
0
 private void AddNode(RMNode nodeManager)
 {
     lock (this)
     {
         FiCaSchedulerNode schedulerNode = new FiCaSchedulerNode(nodeManager, usePortForNodeName
                                                                 );
         this.nodes[nodeManager.GetNodeID()] = schedulerNode;
         Resources.AddTo(clusterResource, schedulerNode.GetTotalResource());
         UpdateMaximumAllocation(schedulerNode, true);
     }
 }
Exemplo n.º 8
0
        private RMContainer RecoverAndCreateContainer(NMContainerStatus status, RMNode node
                                                      )
        {
            Container container = Container.NewInstance(status.GetContainerId(), node.GetNodeID
                                                            (), node.GetHttpAddress(), status.GetAllocatedResource(), status.GetPriority(),
                                                        null);
            ApplicationAttemptId attemptId   = container.GetId().GetApplicationAttemptId();
            RMContainer          rmContainer = new RMContainerImpl(container, attemptId, node.GetNodeID
                                                                       (), applications[attemptId.GetApplicationId()].GetUser(), rmContext, status.GetCreationTime
                                                                       ());

            return(rmContainer);
        }
Exemplo n.º 9
0
 private void RemoveNode(RMNode nodeInfo)
 {
     lock (this)
     {
         FiCaSchedulerNode node = GetNode(nodeInfo.GetNodeID());
         if (node == null)
         {
             return;
         }
         // Kill running containers
         foreach (RMContainer container in node.GetRunningContainers())
         {
             CompletedContainer(container, SchedulerUtils.CreateAbnormalContainerStatus(container
                                                                                        .GetContainerId(), SchedulerUtils.LostContainer), RMContainerEventType.Kill);
         }
         //Remove the node
         Sharpen.Collections.Remove(this.nodes, nodeInfo.GetNodeID());
         UpdateMaximumAllocation(node, false);
         // Update cluster metrics
         Resources.SubtractFrom(clusterResource, node.GetTotalResource());
     }
 }
Exemplo n.º 10
0
 public SchedulerNode(RMNode node, bool usePortForNodeName, ICollection <string> labels
                      )
 {
     /* set of containers that are allocated containers */
     this.rmNode                  = node;
     this.availableResource       = Resources.Clone(node.GetTotalCapability());
     this.totalResourceCapability = Resources.Clone(node.GetTotalCapability());
     if (usePortForNodeName)
     {
         nodeName = rmNode.GetHostName() + ":" + node.GetNodeID().GetPort();
     }
     else
     {
         nodeName = rmNode.GetHostName();
     }
     this.labels = ImmutableSet.CopyOf(labels);
 }
Exemplo n.º 11
0
        public static FiCaSchedulerNode GetMockNode(string host, string rack, int port, int
                                                    capability)
        {
            NodeId nodeId = Org.Mockito.Mockito.Mock <NodeId>();

            Org.Mockito.Mockito.When(nodeId.GetHost()).ThenReturn(host);
            Org.Mockito.Mockito.When(nodeId.GetPort()).ThenReturn(port);
            RMNode rmNode = Org.Mockito.Mockito.Mock <RMNode>();

            Org.Mockito.Mockito.When(rmNode.GetNodeID()).ThenReturn(nodeId);
            Org.Mockito.Mockito.When(rmNode.GetTotalCapability()).ThenReturn(Resources.CreateResource
                                                                                 (capability, 1));
            Org.Mockito.Mockito.When(rmNode.GetNodeAddress()).ThenReturn(host + ":" + port);
            Org.Mockito.Mockito.When(rmNode.GetHostName()).ThenReturn(host);
            Org.Mockito.Mockito.When(rmNode.GetRackName()).ThenReturn(rack);
            FiCaSchedulerNode node = Org.Mockito.Mockito.Spy(new FiCaSchedulerNode(rmNode, false
                                                                                   ));

            Log.Info("node = " + host + " avail=" + node.GetAvailableResource());
            return(node);
        }
Exemplo n.º 12
0
 public virtual void RecoverContainersOnNode(IList <NMContainerStatus> containerReports
                                             , RMNode nm)
 {
     lock (this)
     {
         if (!rmContext.IsWorkPreservingRecoveryEnabled() || containerReports == null || (
                 containerReports != null && containerReports.IsEmpty()))
         {
             return;
         }
         foreach (NMContainerStatus container in containerReports)
         {
             ApplicationId appId = container.GetContainerId().GetApplicationAttemptId().GetApplicationId
                                       ();
             RMApp rmApp = rmContext.GetRMApps()[appId];
             if (rmApp == null)
             {
                 Log.Error("Skip recovering container " + container + " for unknown application.");
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             // Unmanaged AM recovery is addressed in YARN-1815
             if (rmApp.GetApplicationSubmissionContext().GetUnmanagedAM())
             {
                 Log.Info("Skip recovering container " + container + " for unmanaged AM." + rmApp.
                          GetApplicationId());
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             SchedulerApplication <T> schedulerApp = applications[appId];
             if (schedulerApp == null)
             {
                 Log.Info("Skip recovering container  " + container + " for unknown SchedulerApplication. Application current state is "
                          + rmApp.GetState());
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             Log.Info("Recovering container " + container);
             SchedulerApplicationAttempt schedulerAttempt = schedulerApp.GetCurrentAppAttempt(
                 );
             if (!rmApp.GetApplicationSubmissionContext().GetKeepContainersAcrossApplicationAttempts
                     ())
             {
                 // Do not recover containers for stopped attempt or previous attempt.
                 if (schedulerAttempt.IsStopped() || !schedulerAttempt.GetApplicationAttemptId().Equals
                         (container.GetContainerId().GetApplicationAttemptId()))
                 {
                     Log.Info("Skip recovering container " + container + " for already stopped attempt."
                              );
                     KillOrphanContainerOnNode(nm, container);
                     continue;
                 }
             }
             // create container
             RMContainer rmContainer = RecoverAndCreateContainer(container, nm);
             // recover RMContainer
             rmContainer.Handle(new RMContainerRecoverEvent(container.GetContainerId(), container
                                                            ));
             // recover scheduler node
             nodes[nm.GetNodeID()].RecoverContainer(rmContainer);
             // recover queue: update headroom etc.
             Queue queue = schedulerAttempt.GetQueue();
             queue.RecoverContainer(clusterResource, schedulerAttempt, rmContainer);
             // recover scheduler attempt
             schedulerAttempt.RecoverContainer(rmContainer);
             // set master container for the current running AMContainer for this
             // attempt.
             RMAppAttempt appAttempt = rmApp.GetCurrentAppAttempt();
             if (appAttempt != null)
             {
                 Container masterContainer = appAttempt.GetMasterContainer();
                 // Mark current running AMContainer's RMContainer based on the master
                 // container ID stored in AppAttempt.
                 if (masterContainer != null && masterContainer.GetId().Equals(rmContainer.GetContainerId
                                                                                   ()))
                 {
                     ((RMContainerImpl)rmContainer).SetAMContainer(true);
                 }
             }
             lock (schedulerAttempt)
             {
                 ICollection <ContainerId> releases = schedulerAttempt.GetPendingRelease();
                 if (releases.Contains(container.GetContainerId()))
                 {
                     // release the container
                     rmContainer.Handle(new RMContainerFinishedEvent(container.GetContainerId(), SchedulerUtils
                                                                     .CreateAbnormalContainerStatus(container.GetContainerId(), SchedulerUtils.ReleasedContainer
                                                                                                    ), RMContainerEventType.Released));
                     releases.Remove(container.GetContainerId());
                     Log.Info(container.GetContainerId() + " is released by application.");
                 }
             }
         }
     }
 }
Exemplo n.º 13
0
        /// <exception cref="System.Exception"/>
        public virtual void TestBlackListNodes()
        {
            Configuration conf = new Configuration();

            conf.SetClass(YarnConfiguration.RmScheduler, typeof(FifoScheduler), typeof(ResourceScheduler
                                                                                       ));
            MockRM rm = new MockRM(conf);

            rm.Start();
            FifoScheduler fs         = (FifoScheduler)rm.GetResourceScheduler();
            int           rack_num_0 = 0;
            int           rack_num_1 = 1;
            // Add 4 nodes in 2 racks
            // host_0_0 in rack0
            string host_0_0 = "127.0.0.1";
            RMNode n1       = MockNodes.NewNodeInfo(rack_num_0, MockNodes.NewResource(4 * Gb), 1, host_0_0
                                                    );

            fs.Handle(new NodeAddedSchedulerEvent(n1));
            // host_0_1 in rack0
            string host_0_1 = "127.0.0.2";
            RMNode n2       = MockNodes.NewNodeInfo(rack_num_0, MockNodes.NewResource(4 * Gb), 1, host_0_1
                                                    );

            fs.Handle(new NodeAddedSchedulerEvent(n2));
            // host_1_0 in rack1
            string host_1_0 = "127.0.0.3";
            RMNode n3       = MockNodes.NewNodeInfo(rack_num_1, MockNodes.NewResource(4 * Gb), 1, host_1_0
                                                    );

            fs.Handle(new NodeAddedSchedulerEvent(n3));
            // host_1_1 in rack1
            string host_1_1 = "127.0.0.4";
            RMNode n4       = MockNodes.NewNodeInfo(rack_num_1, MockNodes.NewResource(4 * Gb), 1, host_1_1
                                                    );

            fs.Handle(new NodeAddedSchedulerEvent(n4));
            // Add one application
            ApplicationId        appId1        = BuilderUtils.NewApplicationId(100, 1);
            ApplicationAttemptId appAttemptId1 = BuilderUtils.NewApplicationAttemptId(appId1,
                                                                                      1);

            CreateMockRMApp(appAttemptId1, rm.GetRMContext());
            SchedulerEvent appEvent = new AppAddedSchedulerEvent(appId1, "queue", "user");

            fs.Handle(appEvent);
            SchedulerEvent attemptEvent = new AppAttemptAddedSchedulerEvent(appAttemptId1, false
                                                                            );

            fs.Handle(attemptEvent);
            IList <ContainerId>     emptyId  = new AList <ContainerId>();
            IList <ResourceRequest> emptyAsk = new AList <ResourceRequest>();
            // Allow rack-locality for rack_1, but blacklist host_1_0
            // Set up resource requests
            // Ask for a 1 GB container for app 1
            IList <ResourceRequest> ask1 = new AList <ResourceRequest>();

            ask1.AddItem(BuilderUtils.NewResourceRequest(BuilderUtils.NewPriority(0), "rack1"
                                                         , BuilderUtils.NewResource(Gb, 1), 1));
            ask1.AddItem(BuilderUtils.NewResourceRequest(BuilderUtils.NewPriority(0), ResourceRequest
                                                         .Any, BuilderUtils.NewResource(Gb, 1), 1));
            fs.Allocate(appAttemptId1, ask1, emptyId, Sharpen.Collections.SingletonList(host_1_0
                                                                                        ), null);
            // Trigger container assignment
            fs.Handle(new NodeUpdateSchedulerEvent(n3));
            // Get the allocation for the application and verify no allocation on blacklist node
            Allocation allocation1 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation1", 0, allocation1.GetContainers().Count
                                            );
            // verify host_1_1 can get allocated as not in blacklist
            fs.Handle(new NodeUpdateSchedulerEvent(n4));
            Allocation allocation2 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation2", 1, allocation2.GetContainers().Count
                                            );
            IList <Container> containerList = allocation2.GetContainers();

            foreach (Container container in containerList)
            {
                NUnit.Framework.Assert.AreEqual("Container is allocated on n4", container.GetNodeId
                                                    (), n4.GetNodeID());
            }
            // Ask for a 1 GB container again for app 1
            IList <ResourceRequest> ask2 = new AList <ResourceRequest>();

            // this time, rack0 is also in blacklist, so only host_1_1 is available to
            // be assigned
            ask2.AddItem(BuilderUtils.NewResourceRequest(BuilderUtils.NewPriority(0), ResourceRequest
                                                         .Any, BuilderUtils.NewResource(Gb, 1), 1));
            fs.Allocate(appAttemptId1, ask2, emptyId, Sharpen.Collections.SingletonList("rack0"
                                                                                        ), null);
            // verify n1 is not qualified to be allocated
            fs.Handle(new NodeUpdateSchedulerEvent(n1));
            Allocation allocation3 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation3", 0, allocation3.GetContainers().Count
                                            );
            // verify n2 is not qualified to be allocated
            fs.Handle(new NodeUpdateSchedulerEvent(n2));
            Allocation allocation4 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation4", 0, allocation4.GetContainers().Count
                                            );
            // verify n3 is not qualified to be allocated
            fs.Handle(new NodeUpdateSchedulerEvent(n3));
            Allocation allocation5 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation5", 0, allocation5.GetContainers().Count
                                            );
            fs.Handle(new NodeUpdateSchedulerEvent(n4));
            Allocation allocation6 = fs.Allocate(appAttemptId1, emptyAsk, emptyId, null, null
                                                 );

            NUnit.Framework.Assert.AreEqual("allocation6", 1, allocation6.GetContainers().Count
                                            );
            containerList = allocation6.GetContainers();
            foreach (Container container_1 in containerList)
            {
                NUnit.Framework.Assert.AreEqual("Container is allocated on n4", container_1.GetNodeId
                                                    (), n4.GetNodeID());
            }
            rm.Stop();
        }
Exemplo n.º 14
0
        /// <exception cref="System.Exception"/>
        public virtual void TestUpdateResourceOnNode()
        {
            AsyncDispatcher dispatcher = new InlineDispatcher();
            Configuration   conf       = new Configuration();
            RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager
                                                                            (conf);

            containerTokenSecretManager.RollMasterKey();
            NMTokenSecretManagerInRM nmTokenSecretManager = new NMTokenSecretManagerInRM(conf
                                                                                         );

            nmTokenSecretManager.RollMasterKey();
            RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter
                                                                          >();
            FifoScheduler scheduler = new _FifoScheduler_275(this);
            RMContext     rmContext = new RMContextImpl(dispatcher, null, null, null, null, null,
                                                        containerTokenSecretManager, nmTokenSecretManager, null, scheduler);

            rmContext.SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher
                                                                          >());
            rmContext.SetRMApplicationHistoryWriter(Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter
                                                                              >());
            ((RMContextImpl)rmContext).SetYarnConfiguration(new YarnConfiguration());
            scheduler.SetRMContext(rmContext);
            scheduler.Init(conf);
            scheduler.Start();
            scheduler.Reinitialize(new Configuration(), rmContext);
            RMNode node0 = MockNodes.NewNodeInfo(1, Resources.CreateResource(2048, 4), 1, "127.0.0.1"
                                                 );
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0);

            scheduler.Handle(nodeEvent1);
            MethodInfo method = Sharpen.Runtime.GetDeclaredMethod(scheduler.GetType(), "getNodes"
                                                                  );
            IDictionary <NodeId, FiCaSchedulerNode> schedulerNodes = (IDictionary <NodeId, FiCaSchedulerNode
                                                                                   >)method.Invoke(scheduler);

            NUnit.Framework.Assert.AreEqual(schedulerNodes.Values.Count, 1);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource newResource = Resources.CreateResource
                                                                          (1024, 4);
            NodeResourceUpdateSchedulerEvent node0ResourceUpdate = new NodeResourceUpdateSchedulerEvent
                                                                       (node0, ResourceOption.NewInstance(newResource, RMNode.OverCommitTimeoutMillisDefault
                                                                                                          ));

            scheduler.Handle(node0ResourceUpdate);
            // SchedulerNode's total resource and available resource are changed.
            NUnit.Framework.Assert.AreEqual(schedulerNodes[node0.GetNodeID()].GetTotalResource
                                                ().GetMemory(), 1024);
            NUnit.Framework.Assert.AreEqual(schedulerNodes[node0.GetNodeID()].GetAvailableResource
                                                ().GetMemory(), 1024);
            QueueInfo queueInfo = scheduler.GetQueueInfo(null, false, false);

            NUnit.Framework.Assert.AreEqual(0.0f, queueInfo.GetCurrentCapacity(), 0.0f);
            int _appId        = 1;
            int _appAttemptId = 1;
            ApplicationAttemptId appAttemptId = CreateAppAttemptId(_appId, _appAttemptId);

            CreateMockRMApp(appAttemptId, rmContext);
            AppAddedSchedulerEvent appEvent = new AppAddedSchedulerEvent(appAttemptId.GetApplicationId
                                                                             (), "queue1", "user1");

            scheduler.Handle(appEvent);
            AppAttemptAddedSchedulerEvent attemptEvent = new AppAttemptAddedSchedulerEvent(appAttemptId
                                                                                           , false);

            scheduler.Handle(attemptEvent);
            int memory   = 1024;
            int priority = 1;
            IList <ResourceRequest> ask       = new AList <ResourceRequest>();
            ResourceRequest         nodeLocal = CreateResourceRequest(memory, node0.GetHostName(), priority
                                                                      , 1);
            ResourceRequest rackLocal = CreateResourceRequest(memory, node0.GetRackName(), priority
                                                              , 1);
            ResourceRequest any = CreateResourceRequest(memory, ResourceRequest.Any, priority
                                                        , 1);

            ask.AddItem(nodeLocal);
            ask.AddItem(rackLocal);
            ask.AddItem(any);
            scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null);
            // Before the node update event, there are one local request
            NUnit.Framework.Assert.AreEqual(1, nodeLocal.GetNumContainers());
            NodeUpdateSchedulerEvent node0Update = new NodeUpdateSchedulerEvent(node0);

            // Now schedule.
            scheduler.Handle(node0Update);
            // After the node update event, check no local request
            NUnit.Framework.Assert.AreEqual(0, nodeLocal.GetNumContainers());
            // Also check that one container was scheduled
            SchedulerAppReport info = scheduler.GetSchedulerAppInfo(appAttemptId);

            NUnit.Framework.Assert.AreEqual(1, info.GetLiveContainers().Count);
            // And check the default Queue now is full.
            queueInfo = scheduler.GetQueueInfo(null, false, false);
            NUnit.Framework.Assert.AreEqual(1.0f, queueInfo.GetCurrentCapacity(), 0.0f);
        }