Esempio n. 1
0
 public RMAppNodeUpdateEvent(ApplicationId appId, RMNode node, RMAppNodeUpdateEvent.RMAppNodeUpdateType
                             updateType)
     : base(appId, RMAppEventType.NodeUpdate)
 {
     this.node       = node;
     this.updateType = updateType;
 }
        /// <exception cref="System.IO.IOException"/>
        private void CreateClusterWithQueuesAndOneNode(int mem, int vCores, string policy
                                                       )
        {
            PrintWriter @out = new PrintWriter(new FileWriter(AllocFile));

            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("<queue name=\"root\" >");
            @out.WriteLine("   <queue name=\"parentA\" >");
            @out.WriteLine("       <weight>8</weight>");
            @out.WriteLine("       <queue name=\"childA1\" />");
            @out.WriteLine("       <queue name=\"childA2\" />");
            @out.WriteLine("       <queue name=\"childA3\" />");
            @out.WriteLine("       <queue name=\"childA4\" />");
            @out.WriteLine("   </queue>");
            @out.WriteLine("   <queue name=\"parentB\" >");
            @out.WriteLine("       <weight>1</weight>");
            @out.WriteLine("       <queue name=\"childB1\" />");
            @out.WriteLine("       <queue name=\"childB2\" />");
            @out.WriteLine("   </queue>");
            @out.WriteLine("</queue>");
            @out.WriteLine("<defaultQueueSchedulingPolicy>" + policy + "</defaultQueueSchedulingPolicy>"
                           );
            @out.WriteLine("</allocations>");
            @out.Close();
            resourceManager = new MockRM(conf);
            resourceManager.Start();
            scheduler = (FairScheduler)resourceManager.GetResourceScheduler();
            RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(mem, vCores), 1,
                                                 "127.0.0.1");
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
        }
Esempio n. 3
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"));
            }
        }
Esempio n. 4
0
        public virtual void TestNodeUpdateBeforeAppAttemptInit()
        {
            FifoScheduler scheduler = new FifoScheduler();
            MockRM        rm        = new MockRM(conf);

            scheduler.SetRMContext(rm.GetRMContext());
            scheduler.Init(conf);
            scheduler.Start();
            scheduler.Reinitialize(conf, rm.GetRMContext());
            RMNode node = MockNodes.NewNodeInfo(1, Resources.CreateResource(1024, 4), 1, "127.0.0.1"
                                                );

            scheduler.Handle(new NodeAddedSchedulerEvent(node));
            ApplicationId appId = ApplicationId.NewInstance(0, 1);

            scheduler.AddApplication(appId, "queue1", "user1", false);
            NodeUpdateSchedulerEvent updateEvent = new NodeUpdateSchedulerEvent(node);

            try
            {
                scheduler.Handle(updateEvent);
            }
            catch (ArgumentNullException)
            {
                NUnit.Framework.Assert.Fail();
            }
            ApplicationAttemptId attId = ApplicationAttemptId.NewInstance(appId, 1);

            scheduler.AddApplicationAttempt(attId, false, false);
            rm.Stop();
        }
 public NodeAddedSchedulerEvent(RMNode rmNode, IList <NMContainerStatus> containerReports
                                )
     : base(SchedulerEventType.NodeAdded)
 {
     this.rmNode           = rmNode;
     this.containerReports = containerReports;
 }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
        /// <exception cref="System.Exception"/>
        public virtual void TestRMNodeStatusAfterReconnect()
        {
            // The node(127.0.0.1:1234) reconnected with RM. When it registered with
            // RM, RM set its lastNodeHeartbeatResponse's id to 0 asynchronously. But
            // the node's heartbeat come before RM succeeded setting the id to 0.
            DrainDispatcher dispatcher = new DrainDispatcher();
            MockRM          rm         = new _MockRM_204(dispatcher);

            rm.Start();
            MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm.GetResourceTrackerService());

            nm1.RegisterNode();
            int i = 0;

            while (i < 3)
            {
                nm1.NodeHeartbeat(true);
                dispatcher.Await();
                i++;
            }
            MockNM nm2 = new MockNM("127.0.0.1:1234", 15120, rm.GetResourceTrackerService());

            nm2.RegisterNode();
            RMNode rmNode = rm.GetRMContext().GetRMNodes()[nm2.GetNodeId()];

            nm2.NodeHeartbeat(true);
            dispatcher.Await();
            NUnit.Framework.Assert.AreEqual("Node is Not in Running state.", NodeState.Running
                                            , rmNode.GetState());
            rm.Stop();
        }
 /// <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);
         }
     }
 }
 public NodeResourceUpdateSchedulerEvent(RMNode rmNode, ResourceOption resourceOption
                                         )
     : base(SchedulerEventType.NodeResourceUpdate)
 {
     this.rmNode         = rmNode;
     this.resourceOption = resourceOption;
 }
        public virtual void TestSingleNodeQueryStateLost()
        {
            WebResource r   = Resource();
            MockNM      nm1 = rm.RegisterNode("h1:1234", 5120);
            MockNM      nm2 = rm.RegisterNode("h2:1234", 5120);

            rm.SendNodeStarted(nm1);
            rm.SendNodeStarted(nm2);
            rm.NMwaitForState(nm1.GetNodeId(), NodeState.Running);
            rm.NMwaitForState(nm2.GetNodeId(), NodeState.Running);
            rm.SendNodeLost(nm1);
            rm.SendNodeLost(nm2);
            ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").Path
                                          ("h2:1234").Accept(MediaType.ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();
            JSONObject info = json.GetJSONObject("node");
            string     id   = info.Get("id").ToString();

            NUnit.Framework.Assert.AreEqual("Incorrect Node Information.", "h2:1234", id);
            RMNode rmNode = rm.GetRMContext().GetInactiveRMNodes()["h2"];

            WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", string.Empty, info.GetString
                                                      ("nodeHTTPAddress"));
            WebServicesTestUtils.CheckStringMatch("state", rmNode.GetState().ToString(), info
                                                  .GetString("state"));
        }
Esempio n. 11
0
        /// <exception cref="System.Exception"/>
        public virtual void TestReconnectedNode()
        {
            CapacitySchedulerConfiguration conf = new CapacitySchedulerConfiguration();

            conf.SetQueues("default", new string[] { "default" });
            conf.SetCapacity("default", 100);
            FifoScheduler fs = new FifoScheduler();

            fs.Init(conf);
            fs.Start();
            // mock rmContext to avoid NPE.
            RMContext context = Org.Mockito.Mockito.Mock <RMContext>();

            fs.Reinitialize(conf, null);
            fs.SetRMContext(context);
            RMNode n1 = MockNodes.NewNodeInfo(0, MockNodes.NewResource(4 * Gb), 1, "127.0.0.2"
                                              );
            RMNode n2 = MockNodes.NewNodeInfo(0, MockNodes.NewResource(2 * Gb), 2, "127.0.0.3"
                                              );

            fs.Handle(new NodeAddedSchedulerEvent(n1));
            fs.Handle(new NodeAddedSchedulerEvent(n2));
            fs.Handle(new NodeUpdateSchedulerEvent(n1));
            NUnit.Framework.Assert.AreEqual(6 * Gb, fs.GetRootQueueMetrics().GetAvailableMB()
                                            );
            // reconnect n1 with downgraded memory
            n1 = MockNodes.NewNodeInfo(0, MockNodes.NewResource(2 * Gb), 1, "127.0.0.2");
            fs.Handle(new NodeRemovedSchedulerEvent(n1));
            fs.Handle(new NodeAddedSchedulerEvent(n1));
            fs.Handle(new NodeUpdateSchedulerEvent(n1));
            NUnit.Framework.Assert.AreEqual(4 * Gb, fs.GetRootQueueMetrics().GetAvailableMB()
                                            );
            fs.Stop();
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestSchedulingDelay()
        {
            // Add one node
            string host  = "127.0.0.1";
            RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(4096, 4), 1, host
                                                 );
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
            NodeUpdateSchedulerEvent nodeUpdateEvent = new NodeUpdateSchedulerEvent(node1);

            scheduler.Handle(nodeUpdateEvent);
            // Create one application and submit one each of node-local, rack-local
            // and ANY requests
            ApplicationAttemptId appAttemptId = CreateAppAttemptId(this.AppId++, this.AttemptId
                                                                   ++);

            CreateMockRMApp(appAttemptId);
            scheduler.AddApplication(appAttemptId.GetApplicationId(), "queue11", "user11", false
                                     );
            scheduler.AddApplicationAttempt(appAttemptId, false, false);
            IList <ResourceRequest> ask = new AList <ResourceRequest>();

            ask.AddItem(CreateResourceRequest(1024, 1, ResourceRequest.Any, 1, 1, true));
            scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null);
            FSAppAttempt app = scheduler.GetSchedulerApp(appAttemptId);

            // Advance time and let continuous scheduling kick in
            mockClock.Tick(1);
            while (1024 != app.GetCurrentConsumption().GetMemory())
            {
                Sharpen.Thread.Sleep(100);
            }
            NUnit.Framework.Assert.AreEqual(1024, app.GetCurrentConsumption().GetMemory());
        }
Esempio n. 13
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()));
     }
 }
Esempio n. 14
0
        private void NodeUpdate(NodeManager nm1)
        {
            RMNode node = resourceManager.GetRMContext().GetRMNodes()[nm1.GetNodeId()];
            // Send a heartbeat to kick the tires on the Scheduler
            NodeUpdateSchedulerEvent nodeUpdate = new NodeUpdateSchedulerEvent(node);

            resourceManager.GetResourceScheduler().Handle(nodeUpdate);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public virtual void TestMaxAllocationAfterUpdateNodeResource()
        {
            int configuredMaxVCores = 20;
            int configuredMaxMemory = 10 * 1024;

            Org.Apache.Hadoop.Yarn.Api.Records.Resource configuredMaximumResource = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                                    .NewInstance(configuredMaxMemory, configuredMaxVCores);
            ConfigureScheduler();
            YarnConfiguration conf = GetConf();

            conf.SetInt(YarnConfiguration.RmSchedulerMaximumAllocationVcores, configuredMaxVCores
                        );
            conf.SetInt(YarnConfiguration.RmSchedulerMaximumAllocationMb, configuredMaxMemory
                        );
            conf.SetLong(YarnConfiguration.RmWorkPreservingRecoverySchedulingWaitMs, 0);
            MockRM rm = new MockRM(conf);

            try
            {
                rm.Start();
                AbstractYarnScheduler scheduler = (AbstractYarnScheduler)rm.GetResourceScheduler(
                    );
                VerifyMaximumResourceCapability(configuredMaximumResource, scheduler);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource1 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                        .NewInstance(2048, 5);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource2 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                        .NewInstance(4096, 10);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource3 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                        .NewInstance(512, 1);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource4 = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                        .NewInstance(1024, 2);
                RMNode node1 = MockNodes.NewNodeInfo(0, resource1, 1, "127.0.0.2");
                scheduler.Handle(new NodeAddedSchedulerEvent(node1));
                RMNode node2 = MockNodes.NewNodeInfo(0, resource3, 2, "127.0.0.3");
                scheduler.Handle(new NodeAddedSchedulerEvent(node2));
                VerifyMaximumResourceCapability(resource1, scheduler);
                // increase node1 resource
                scheduler.UpdateNodeResource(node1, ResourceOption.NewInstance(resource2, 0));
                VerifyMaximumResourceCapability(resource2, scheduler);
                // decrease node1 resource
                scheduler.UpdateNodeResource(node1, ResourceOption.NewInstance(resource1, 0));
                VerifyMaximumResourceCapability(resource1, scheduler);
                // increase node2 resource
                scheduler.UpdateNodeResource(node2, ResourceOption.NewInstance(resource4, 0));
                VerifyMaximumResourceCapability(resource1, scheduler);
                // decrease node2 resource
                scheduler.UpdateNodeResource(node2, ResourceOption.NewInstance(resource3, 0));
                VerifyMaximumResourceCapability(resource1, scheduler);
            }
            finally
            {
                rm.Stop();
            }
        }
Esempio n. 17
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);
     }
 }
Esempio n. 18
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);
        }
Esempio n. 19
0
        /// <exception cref="System.Exception"/>
        public virtual void Test()
        {
            conf.Set(FairSchedulerConfiguration.AllocationFile, AllocFile);
            PrintWriter @out = new PrintWriter(new FileWriter(AllocFile));

            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("<queue name=\"queueA\">");
            @out.WriteLine("<minResources>2048mb,0vcores</minResources>");
            @out.WriteLine("</queue>");
            @out.WriteLine("<queue name=\"queueB\">");
            @out.WriteLine("<minResources>2048mb,0vcores</minResources>");
            @out.WriteLine("</queue>");
            @out.WriteLine("</allocations>");
            @out.Close();
            resourceManager = new MockRM(conf);
            resourceManager.Start();
            scheduler = (FairScheduler)resourceManager.GetResourceScheduler();
            // Add one big node (only care about aggregate capacity)
            RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(4 * 1024, 4), 1,
                                                 "127.0.0.1");
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
            scheduler.Update();
            // Queue A wants 3 * 1024. Node update gives this all to A
            CreateSchedulingRequest(3 * 1024, "queueA", "user1");
            scheduler.Update();
            NodeUpdateSchedulerEvent nodeEvent2 = new NodeUpdateSchedulerEvent(node1);

            scheduler.Handle(nodeEvent2);
            // Queue B arrives and wants 1 * 1024
            CreateSchedulingRequest(1 * 1024, "queueB", "user1");
            scheduler.Update();
            ICollection <FSLeafQueue> queues = scheduler.GetQueueManager().GetLeafQueues();

            NUnit.Framework.Assert.AreEqual(3, queues.Count);
            // Queue A should be above min share, B below.
            FSLeafQueue queueA = scheduler.GetQueueManager().GetLeafQueue("queueA", false);
            FSLeafQueue queueB = scheduler.GetQueueManager().GetLeafQueue("queueB", false);

            NUnit.Framework.Assert.IsFalse(queueA.IsStarvedForMinShare());
            NUnit.Framework.Assert.IsTrue(queueB.IsStarvedForMinShare());
            // Node checks in again, should allocate for B
            scheduler.Handle(nodeEvent2);
            // Now B should have min share ( = demand here)
            NUnit.Framework.Assert.IsFalse(queueB.IsStarvedForMinShare());
        }
Esempio n. 20
0
        public virtual void Handle(NodesListManagerEvent @event)
        {
            RMNode eventNode = @event.GetNode();

            switch (@event.GetType())
            {
            case NodesListManagerEventType.NodeUnusable:
            {
                Log.Debug(eventNode + " reported unusable");
                unusableRMNodesConcurrentSet.AddItem(eventNode);
                foreach (RMApp app in rmContext.GetRMApps().Values)
                {
                    if (!app.IsAppFinalStateStored())
                    {
                        this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppNodeUpdateEvent(
                                                                                    app.GetApplicationId(), eventNode, RMAppNodeUpdateEvent.RMAppNodeUpdateType.NodeUnusable
                                                                                    ));
                    }
                }
                break;
            }

            case NodesListManagerEventType.NodeUsable:
            {
                if (unusableRMNodesConcurrentSet.Contains(eventNode))
                {
                    Log.Debug(eventNode + " reported usable");
                    unusableRMNodesConcurrentSet.Remove(eventNode);
                }
                foreach (RMApp app_1 in rmContext.GetRMApps().Values)
                {
                    if (!app_1.IsAppFinalStateStored())
                    {
                        this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppNodeUpdateEvent(
                                                                                    app_1.GetApplicationId(), eventNode, RMAppNodeUpdateEvent.RMAppNodeUpdateType.NodeUsable
                                                                                    ));
                    }
                }
                break;
            }

            default:
            {
                Log.Error("Ignoring invalid eventtype " + @event.GetType());
                break;
            }
            }
        }
Esempio n. 21
0
        /// <exception cref="System.Exception"/>
        public virtual void NMwaitForState(NodeId nodeid, NodeState finalState)
        {
            RMNode node = GetRMContext().GetRMNodes()[nodeid];

            NUnit.Framework.Assert.IsNotNull("node shouldn't be null", node);
            int timeoutSecs = 0;

            while (!finalState.Equals(node.GetState()) && timeoutSecs++ < 20)
            {
                System.Console.Out.WriteLine("Node State is : " + node.GetState() + " Waiting for state : "
                                             + finalState);
                Sharpen.Thread.Sleep(500);
            }
            System.Console.Out.WriteLine("Node State is : " + node.GetState());
            NUnit.Framework.Assert.AreEqual("Node state is not correct (timedout)", finalState
                                            , node.GetState());
        }
Esempio n. 22
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);
 }
Esempio n. 23
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();
     }
 }
        /// <exception cref="System.IO.IOException"/>
        public static FairScheduler SetupFairScheduler(ReservationSystemTestUtil testUtil
                                                       , RMContext rmContext, Configuration conf, int numContainers)
        {
            FairScheduler scheduler = new FairScheduler();

            scheduler.SetRMContext(rmContext);
            Org.Mockito.Mockito.When(rmContext.GetScheduler()).ThenReturn(scheduler);
            scheduler.Init(conf);
            scheduler.Start();
            scheduler.Reinitialize(conf, rmContext);
            Resource resource = ReservationSystemTestUtil.CalculateClusterResource(numContainers
                                                                                   );
            RMNode node1 = MockNodes.NewNodeInfo(1, resource, 1, "127.0.0.1");
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
            return(scheduler);
        }
Esempio n. 25
0
        /// <exception cref="System.Exception"/>
        private void TestMaximumAllocationMemoryHelper(AbstractYarnScheduler scheduler, int
                                                       node1MaxMemory, int node2MaxMemory, int node3MaxMemory, params int[] expectedMaxMemory
                                                       )
        {
            NUnit.Framework.Assert.AreEqual(6, expectedMaxMemory.Length);
            NUnit.Framework.Assert.AreEqual(0, scheduler.GetNumClusterNodes());
            int maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();

            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[0], maxMemory);
            RMNode node1 = MockNodes.NewNodeInfo(0, Resources.CreateResource(node1MaxMemory),
                                                 1, "127.0.0.2");

            scheduler.Handle(new NodeAddedSchedulerEvent(node1));
            NUnit.Framework.Assert.AreEqual(1, scheduler.GetNumClusterNodes());
            maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();
            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[1], maxMemory);
            scheduler.Handle(new NodeRemovedSchedulerEvent(node1));
            NUnit.Framework.Assert.AreEqual(0, scheduler.GetNumClusterNodes());
            maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();
            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[2], maxMemory);
            RMNode node2 = MockNodes.NewNodeInfo(0, Resources.CreateResource(node2MaxMemory),
                                                 2, "127.0.0.3");

            scheduler.Handle(new NodeAddedSchedulerEvent(node2));
            NUnit.Framework.Assert.AreEqual(1, scheduler.GetNumClusterNodes());
            maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();
            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[3], maxMemory);
            RMNode node3 = MockNodes.NewNodeInfo(0, Resources.CreateResource(node3MaxMemory),
                                                 3, "127.0.0.4");

            scheduler.Handle(new NodeAddedSchedulerEvent(node3));
            NUnit.Framework.Assert.AreEqual(2, scheduler.GetNumClusterNodes());
            maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();
            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[4], maxMemory);
            scheduler.Handle(new NodeRemovedSchedulerEvent(node3));
            NUnit.Framework.Assert.AreEqual(1, scheduler.GetNumClusterNodes());
            maxMemory = scheduler.GetMaximumResourceCapability().GetMemory();
            NUnit.Framework.Assert.AreEqual(expectedMaxMemory[5], maxMemory);
            scheduler.Handle(new NodeRemovedSchedulerEvent(node2));
            NUnit.Framework.Assert.AreEqual(0, scheduler.GetNumClusterNodes());
        }
Esempio n. 26
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);
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void VerifyNodeInfoGeneric(MockNM nm, string state, string rack, string
                                                  id, string nodeHostName, string nodeHTTPAddress, long lastHealthUpdate, string
                                                  healthReport, int numContainers, long usedMemoryMB, long availMemoryMB, long usedVirtualCores
                                                  , long availVirtualCores, string version)
        {
            RMNode              node   = rm.GetRMContext().GetRMNodes()[nm.GetNodeId()];
            ResourceScheduler   sched  = rm.GetResourceScheduler();
            SchedulerNodeReport report = sched.GetNodeReport(nm.GetNodeId());

            WebServicesTestUtils.CheckStringMatch("state", node.GetState().ToString(), state);
            WebServicesTestUtils.CheckStringMatch("rack", node.GetRackName(), rack);
            WebServicesTestUtils.CheckStringMatch("id", nm.GetNodeId().ToString(), id);
            WebServicesTestUtils.CheckStringMatch("nodeHostName", nm.GetNodeId().GetHost(), nodeHostName
                                                  );
            WebServicesTestUtils.CheckStringMatch("healthReport", node.GetHealthReport().ToString
                                                      (), healthReport);
            string expectedHttpAddress = nm.GetNodeId().GetHost() + ":" + nm.GetHttpPort();

            WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", expectedHttpAddress, nodeHTTPAddress
                                                  );
            WebServicesTestUtils.CheckStringMatch("version", node.GetNodeManagerVersion(), version
                                                  );
            long expectedHealthUpdate = node.GetLastHealthReportTime();

            NUnit.Framework.Assert.AreEqual("lastHealthUpdate doesn't match, got: " + lastHealthUpdate
                                            + " expected: " + expectedHealthUpdate, expectedHealthUpdate, lastHealthUpdate);
            if (report != null)
            {
                NUnit.Framework.Assert.AreEqual("numContainers doesn't match: " + numContainers,
                                                report.GetNumContainers(), numContainers);
                NUnit.Framework.Assert.AreEqual("usedMemoryMB doesn't match: " + usedMemoryMB, report
                                                .GetUsedResource().GetMemory(), usedMemoryMB);
                NUnit.Framework.Assert.AreEqual("availMemoryMB doesn't match: " + availMemoryMB,
                                                report.GetAvailableResource().GetMemory(), availMemoryMB);
                NUnit.Framework.Assert.AreEqual("usedVirtualCores doesn't match: " + usedVirtualCores
                                                , report.GetUsedResource().GetVirtualCores(), usedVirtualCores);
                NUnit.Framework.Assert.AreEqual("availVirtualCores doesn't match: " + availVirtualCores
                                                , report.GetAvailableResource().GetVirtualCores(), availVirtualCores);
            }
        }
Esempio n. 28
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());
     }
 }
        public virtual void TestNodesQueryStateLost()
        {
            WebResource r   = Resource();
            MockNM      nm1 = rm.RegisterNode("h1:1234", 5120);
            MockNM      nm2 = rm.RegisterNode("h2:1234", 5120);

            rm.SendNodeStarted(nm1);
            rm.SendNodeStarted(nm2);
            rm.NMwaitForState(nm1.GetNodeId(), NodeState.Running);
            rm.NMwaitForState(nm2.GetNodeId(), NodeState.Running);
            rm.SendNodeLost(nm1);
            rm.SendNodeLost(nm2);
            ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").QueryParam
                                          ("states", NodeState.Lost.ToString()).Accept(MediaType.ApplicationJson).Get <ClientResponse
                                                                                                                       >();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json  = response.GetEntity <JSONObject>();
            JSONObject nodes = json.GetJSONObject("nodes");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.Length()
                                            );
            JSONArray nodeArray = nodes.GetJSONArray("node");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, nodeArray.Length
                                                ());
            for (int i = 0; i < nodeArray.Length(); ++i)
            {
                JSONObject info   = nodeArray.GetJSONObject(i);
                string     host   = info.Get("id").ToString().Split(":")[0];
                RMNode     rmNode = rm.GetRMContext().GetInactiveRMNodes()[host];
                WebServicesTestUtils.CheckStringMatch("nodeHTTPAddress", string.Empty, info.GetString
                                                          ("nodeHTTPAddress"));
                WebServicesTestUtils.CheckStringMatch("state", rmNode.GetState().ToString(), info
                                                      .GetString("state"));
            }
        }
        private void RegisterNodeAndSubmitApp(int memory, int vcores, int appContainers,
                                              int appMemory)
        {
            RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(memory, vcores),
                                                 1, "node1");
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
            NUnit.Framework.Assert.AreEqual("Incorrect amount of resources in the cluster", memory
                                            , scheduler.rootMetrics.GetAvailableMB());
            NUnit.Framework.Assert.AreEqual("Incorrect amount of resources in the cluster", vcores
                                            , scheduler.rootMetrics.GetAvailableVirtualCores());
            CreateSchedulingRequest(appMemory, "queueA", "user1", appContainers);
            scheduler.Update();
            // Sufficient node check-ins to fully schedule containers
            for (int i = 0; i < 3; i++)
            {
                NodeUpdateSchedulerEvent nodeUpdate1 = new NodeUpdateSchedulerEvent(node1);
                scheduler.Handle(nodeUpdate1);
            }
            NUnit.Framework.Assert.AreEqual("app1's request is not met", memory - appContainers
                                            * appMemory, scheduler.rootMetrics.GetAvailableMB());
        }