Пример #1
0
 public _SchedulerEventDispatcher_170(_MockRM_167 _enclosing, ResourceScheduler baseArg1
                                      )
     : base(baseArg1)
 {
     this._enclosing = _enclosing;
 }
Пример #2
0
        public virtual void TestContainerCleanup()
        {
            Logger rootLogger = LogManager.GetRootLogger();

            rootLogger.SetLevel(Level.Debug);
            DrainDispatcher dispatcher = new DrainDispatcher();
            MockRM          rm         = new _MockRM_167(this, dispatcher);

            rm.Start();
            MockNM nm1 = rm.RegisterNode("127.0.0.1:1234", 5000);
            RMApp  app = rm.SubmitApp(2000);

            //kick the scheduling
            nm1.NodeHeartbeat(true);
            RMAppAttempt attempt = app.GetCurrentAppAttempt();
            MockAM       am      = rm.SendAMLaunched(attempt.GetAppAttemptId());

            am.RegisterAppAttempt();
            //request for containers
            int request = 2;

            am.Allocate("127.0.0.1", 1000, request, new AList <ContainerId>());
            dispatcher.Await();
            //kick the scheduler
            nm1.NodeHeartbeat(true);
            IList <Container> conts = am.Allocate(new AList <ResourceRequest>(), new AList <ContainerId
                                                                                            >()).GetAllocatedContainers();
            int contReceived = conts.Count;
            int waitCount    = 0;

            while (contReceived < request && waitCount++ < 200)
            {
                Log.Info("Got " + contReceived + " containers. Waiting to get " + request);
                Sharpen.Thread.Sleep(100);
                conts = am.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()).GetAllocatedContainers
                            ();
                dispatcher.Await();
                contReceived += conts.Count;
                nm1.NodeHeartbeat(true);
            }
            NUnit.Framework.Assert.AreEqual(request, contReceived);
            // Release a container.
            AList <ContainerId> release = new AList <ContainerId>();

            release.AddItem(conts[0].GetId());
            am.Allocate(new AList <ResourceRequest>(), release);
            dispatcher.Await();
            // Send one more heartbeat with a fake running container. This is to
            // simulate the situation that can happen if the NM reports that container
            // is running in the same heartbeat when the RM asks it to clean it up.
            IDictionary <ApplicationId, IList <ContainerStatus> > containerStatuses = new Dictionary
                                                                                      <ApplicationId, IList <ContainerStatus> >();
            AList <ContainerStatus> containerStatusList = new AList <ContainerStatus>();

            containerStatusList.AddItem(BuilderUtils.NewContainerStatus(conts[0].GetId(), ContainerState
                                                                        .Running, "nothing", 0));
            containerStatuses[app.GetApplicationId()] = containerStatusList;
            NodeHeartbeatResponse resp = nm1.NodeHeartbeat(containerStatuses, true);

            WaitForContainerCleanup(dispatcher, nm1, resp);
            // Now to test the case when RM already gave cleanup, and NM suddenly
            // realizes that the container is running.
            Log.Info("Testing container launch much after release and " + "NM getting cleanup"
                     );
            containerStatuses.Clear();
            containerStatusList.Clear();
            containerStatusList.AddItem(BuilderUtils.NewContainerStatus(conts[0].GetId(), ContainerState
                                                                        .Running, "nothing", 0));
            containerStatuses[app.GetApplicationId()] = containerStatusList;
            resp = nm1.NodeHeartbeat(containerStatuses, true);
            // The cleanup list won't be instantaneous as it is given out by scheduler
            // and not RMNodeImpl.
            WaitForContainerCleanup(dispatcher, nm1, resp);
            rm.Stop();
        }