コード例 #1
0
        /// <summary>
        /// Get a mock
        /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.RMContext"/>
        /// for use in test cases.
        /// </summary>
        /// <returns>
        /// a mock
        /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.RMContext"/>
        /// for use in test cases
        /// </returns>
        public static RMContext GetMockRMContext()
        {
            // Null dispatcher
            Dispatcher nullDispatcher = new _Dispatcher_73();
            // No op
            ContainerAllocationExpirer cae    = new ContainerAllocationExpirer(nullDispatcher);
            Configuration conf                = new Configuration();
            RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter
                                                                          >();
            RMContextImpl rmContext = new RMContextImpl(nullDispatcher, cae, null, null, null
                                                        , new AMRMTokenSecretManager(conf, null), new RMContainerTokenSecretManager(conf
                                                                                                                                    ), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM());
            RMNodeLabelsManager nlm = Org.Mockito.Mockito.Mock <RMNodeLabelsManager>();

            Org.Mockito.Mockito.When(nlm.GetQueueResource(Matchers.Any <string>(), Matchers.Any
                                                          <Set>(), Matchers.Any <Resource>())).ThenAnswer(new _Answer_105());
            Org.Mockito.Mockito.When(nlm.GetResourceByLabel(Matchers.Any <string>(), Matchers.Any
                                                            <Resource>())).ThenAnswer(new _Answer_114());
            rmContext.SetNodeLabelManager(nlm);
            rmContext.SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher
                                                                          >());
            rmContext.SetRMApplicationHistoryWriter(Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter
                                                                              >());
            return(rmContext);
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestNodeLocalAssignment()
        {
            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();
            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(1024 * 64), 1, "127.0.0.1"
                                                 );
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0);

            scheduler.Handle(nodeEvent1);
            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   = 64;
            int nConts   = 3;
            int priority = 20;
            IList <ResourceRequest> ask       = new AList <ResourceRequest>();
            ResourceRequest         nodeLocal = CreateResourceRequest(memory, node0.GetHostName(), priority
                                                                      , nConts);
            ResourceRequest rackLocal = CreateResourceRequest(memory, node0.GetRackName(), priority
                                                              , nConts);
            ResourceRequest any = CreateResourceRequest(memory, ResourceRequest.Any, priority
                                                        , nConts);

            ask.AddItem(nodeLocal);
            ask.AddItem(rackLocal);
            ask.AddItem(any);
            scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null);
            NodeUpdateSchedulerEvent node0Update = new NodeUpdateSchedulerEvent(node0);

            // Before the node update event, there are 3 local requests outstanding
            NUnit.Framework.Assert.AreEqual(3, nodeLocal.GetNumContainers());
            scheduler.Handle(node0Update);
            // After the node update event, check that there are no more local requests
            // outstanding
            NUnit.Framework.Assert.AreEqual(0, nodeLocal.GetNumContainers());
            //Also check that the containers were scheduled
            SchedulerAppReport info = scheduler.GetSchedulerAppInfo(appAttemptId);

            NUnit.Framework.Assert.AreEqual(3, info.GetLiveContainers().Count);
            scheduler.Stop();
        }