示例#1
0
            public virtual void Run()
            {
                ContainerLauncherImpl.Log.Info("Processing the event " + [email protected]());
                // Load ContainerManager tokens before creating a connection.
                // TODO: Do it only once per NodeManager.
                ContainerId containerID = [email protected]();

                ContainerLauncherImpl.Container c = this._enclosing.GetContainer(this.@event);
                switch ([email protected]())
                {
                case ContainerLauncher.EventType.ContainerRemoteLaunch:
                {
                    ContainerRemoteLaunchEvent launchEvent = (ContainerRemoteLaunchEvent)this.@event;
                    c.Launch(launchEvent);
                    break;
                }

                case ContainerLauncher.EventType.ContainerRemoteCleanup:
                {
                    c.Kill();
                    break;
                }
                }
                this._enclosing.RemoveContainerIfDone(containerID);
            }
        /// <exception cref="System.Exception"/>
        public virtual void TestMyShutdown()
        {
            Log.Info("in test Shutdown");
            AppContext   mockContext      = Org.Mockito.Mockito.Mock <AppContext>();
            EventHandler mockEventHandler = Org.Mockito.Mockito.Mock <EventHandler>();

            Org.Mockito.Mockito.When(mockContext.GetEventHandler()).ThenReturn(mockEventHandler
                                                                               );
            TestContainerLauncherImpl.ContainerManagementProtocolClient mockCM = Org.Mockito.Mockito.Mock
                                                                                 <TestContainerLauncherImpl.ContainerManagementProtocolClient>();
            TestContainerLauncherImpl.ContainerLauncherImplUnderTest ut = new TestContainerLauncherImpl.ContainerLauncherImplUnderTest
                                                                              (mockContext, mockCM);
            Configuration conf = new Configuration();

            ut.Init(conf);
            ut.Start();
            try
            {
                ContainerId             contId        = MakeContainerId(0l, 0, 0, 1);
                TaskAttemptId           taskAttemptId = MakeTaskAttemptId(0l, 0, 0, TaskType.Map, 0);
                string                  cmAddress     = "127.0.0.1:8000";
                StartContainersResponse startResp     = recordFactory.NewRecordInstance <StartContainersResponse
                                                                                         >();
                startResp.SetAllServicesMetaData(serviceResponse);
                Log.Info("inserting launch event");
                ContainerRemoteLaunchEvent mockLaunchEvent = Org.Mockito.Mockito.Mock <ContainerRemoteLaunchEvent
                                                                                       >();
                Org.Mockito.Mockito.When(mockLaunchEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                               .ContainerRemoteLaunch);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                        );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                              );
                Org.Mockito.Mockito.When(mockCM.StartContainers(Matchers.Any <StartContainersRequest
                                                                              >())).ThenReturn(startResp);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken
                                                                                             (contId, cmAddress));
                ut.Handle(mockLaunchEvent);
                ut.WaitForPoolToIdle();
                Org.Mockito.Mockito.Verify(mockCM).StartContainers(Matchers.Any <StartContainersRequest
                                                                                 >());
            }
            finally
            {
                // skip cleanup and make sure stop kills the container
                ut.Stop();
                Org.Mockito.Mockito.Verify(mockCM).StopContainers(Matchers.Any <StopContainersRequest
                                                                                >());
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestContainerCleaned()
        {
            Log.Info("STARTING testContainerCleaned");
            CyclicBarrier startLaunchBarrier    = new CyclicBarrier(2);
            CyclicBarrier completeLaunchBarrier = new CyclicBarrier(2);
            AppContext    mockContext           = Org.Mockito.Mockito.Mock <AppContext>();
            EventHandler  mockEventHandler      = Org.Mockito.Mockito.Mock <EventHandler>();

            Org.Mockito.Mockito.When(mockContext.GetEventHandler()).ThenReturn(mockEventHandler
                                                                               );
            TestContainerLauncherImpl.ContainerManagementProtocolClient mockCM = new TestContainerLauncherImpl.ContainerManagerForTest
                                                                                     (startLaunchBarrier, completeLaunchBarrier);
            TestContainerLauncherImpl.ContainerLauncherImplUnderTest ut = new TestContainerLauncherImpl.ContainerLauncherImplUnderTest
                                                                              (mockContext, mockCM);
            Configuration conf = new Configuration();

            ut.Init(conf);
            ut.Start();
            try
            {
                ContainerId             contId        = MakeContainerId(0l, 0, 0, 1);
                TaskAttemptId           taskAttemptId = MakeTaskAttemptId(0l, 0, 0, TaskType.Map, 0);
                string                  cmAddress     = "127.0.0.1:8000";
                StartContainersResponse startResp     = recordFactory.NewRecordInstance <StartContainersResponse
                                                                                         >();
                startResp.SetAllServicesMetaData(serviceResponse);
                Log.Info("inserting launch event");
                ContainerRemoteLaunchEvent mockLaunchEvent = Org.Mockito.Mockito.Mock <ContainerRemoteLaunchEvent
                                                                                       >();
                Org.Mockito.Mockito.When(mockLaunchEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                               .ContainerRemoteLaunch);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                        );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                              );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken
                                                                                             (contId, cmAddress));
                ut.Handle(mockLaunchEvent);
                startLaunchBarrier.Await();
                Log.Info("inserting cleanup event");
                ContainerLauncherEvent mockCleanupEvent = Org.Mockito.Mockito.Mock <ContainerLauncherEvent
                                                                                    >();
                Org.Mockito.Mockito.When(mockCleanupEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                                .ContainerRemoteCleanup);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                         );
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                               );
                ut.Handle(mockCleanupEvent);
                completeLaunchBarrier.Await();
                ut.WaitForPoolToIdle();
                ArgumentCaptor <Org.Apache.Hadoop.Yarn.Event.Event> arg = ArgumentCaptor.ForClass <
                    Org.Apache.Hadoop.Yarn.Event.Event>();
                Org.Mockito.Mockito.Verify(mockEventHandler, Org.Mockito.Mockito.AtLeast(2)).Handle
                    (arg.Capture());
                bool containerCleaned = false;
                for (int i = 0; i < arg.GetAllValues().Count; i++)
                {
                    Log.Info(arg.GetAllValues()[i].ToString());
                    Org.Apache.Hadoop.Yarn.Event.Event currentEvent = arg.GetAllValues()[i];
                    if (currentEvent.GetType() == TaskAttemptEventType.TaContainerCleaned)
                    {
                        containerCleaned = true;
                    }
                }
                System.Diagnostics.Debug.Assert((containerCleaned));
            }
            finally
            {
                ut.Stop();
            }
        }
示例#4
0
 public virtual void Launch(ContainerRemoteLaunchEvent @event)
 {
     lock (this)
     {
         ContainerLauncherImpl.Log.Info("Launching " + this.taskAttemptID);
         if (this.state == ContainerLauncherImpl.ContainerState.KilledBeforeLaunch)
         {
             this.state = ContainerLauncherImpl.ContainerState.Done;
             this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, "Container was killed before it was launched"
                                                          );
             return;
         }
         ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
         try
         {
             proxy = this._enclosing.GetCMProxy(this.containerMgrAddress, this.containerID);
             // Construct the actual Container
             ContainerLaunchContext containerLaunchContext = @event.GetContainerLaunchContext(
                 );
             // Now launch the actual container
             StartContainerRequest startRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                    , @event.GetContainerToken());
             IList <StartContainerRequest> list = new AList <StartContainerRequest>();
             list.AddItem(startRequest);
             StartContainersRequest  requestList = StartContainersRequest.NewInstance(list);
             StartContainersResponse response    = proxy.GetContainerManagementProtocol().StartContainers
                                                       (requestList);
             if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                     (this.containerID))
             {
                 throw response.GetFailedRequests()[this.containerID].DeSerialize();
             }
             ByteBuffer portInfo = response.GetAllServicesMetaData()[ShuffleHandler.MapreduceShuffleServiceid
                                   ];
             int port = -1;
             if (portInfo != null)
             {
                 port = ShuffleHandler.DeserializeMetaData(portInfo);
             }
             ContainerLauncherImpl.Log.Info("Shuffle port returned by ContainerManager for " +
                                            this.taskAttemptID + " : " + port);
             if (port < 0)
             {
                 this.state = ContainerLauncherImpl.ContainerState.Failed;
                 throw new InvalidOperationException("Invalid shuffle port number " + port + " returned for "
                                                     + this.taskAttemptID);
             }
             // after launching, send launched event to task attempt to move
             // it from ASSIGNED to RUNNING state
             this._enclosing.context.GetEventHandler().Handle(new TaskAttemptContainerLaunchedEvent
                                                                  (this.taskAttemptID, port));
             this.state = ContainerLauncherImpl.ContainerState.Running;
         }
         catch (Exception t)
         {
             string message = "Container launch failed for " + this.containerID + " : " + StringUtils
                              .StringifyException(t);
             this.state = ContainerLauncherImpl.ContainerState.Failed;
             this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, message);
         }
         finally
         {
             if (proxy != null)
             {
                 this._enclosing.cmProxy.MayBeCloseProxy(proxy);
             }
         }
     }
 }