Esempio n. 1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void StopContainerInternal(ContainerId containerId, NodeId nodeId)
        {
            ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(containerId);
            try
            {
                proxy = cmProxy.GetProxy(nodeId.ToString(), containerId);
                StopContainersResponse response = proxy.GetContainerManagementProtocol().StopContainers
                                                      (StopContainersRequest.NewInstance(containerIds));
                if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                        (containerId))
                {
                    Exception t = response.GetFailedRequests()[containerId].DeSerialize();
                    ParseAndThrowException(t);
                }
            }
            finally
            {
                if (proxy != null)
                {
                    cmProxy.MayBeCloseProxy(proxy);
                }
            }
        }
Esempio n. 2
0
        /// <exception cref="System.Exception"/>
        private void StopContainer(YarnRPC rpc, Token nmToken, IList <ContainerId> containerId
                                   , ApplicationAttemptId appAttemptId, NodeId nodeId)
        {
            StopContainersRequest       request = StopContainersRequest.NewInstance(containerId);
            ContainerManagementProtocol proxy   = null;

            try
            {
                proxy = GetContainerManagementProtocolProxy(rpc, nmToken, nodeId, appAttemptId.ToString
                                                                ());
                StopContainersResponse response = proxy.StopContainers(request);
                if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                        (containerId))
                {
                    ParseAndThrowException(response.GetFailedRequests()[containerId].DeSerialize());
                }
            }
            catch (Exception)
            {
                if (proxy != null)
                {
                    rpc.StopProxy(proxy, conf);
                }
            }
        }
Esempio n. 3
0
 public virtual void Kill()
 {
     lock (this)
     {
         if (this.state == ContainerLauncherImpl.ContainerState.Prep)
         {
             this.state = ContainerLauncherImpl.ContainerState.KilledBeforeLaunch;
         }
         else
         {
             if (!this.IsCompletelyDone())
             {
                 ContainerLauncherImpl.Log.Info("KILLING " + this.taskAttemptID);
                 ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null;
                 try
                 {
                     proxy = this._enclosing.GetCMProxy(this.containerMgrAddress, this.containerID);
                     // kill the remote container if already launched
                     IList <ContainerId> ids = new AList <ContainerId>();
                     ids.AddItem(this.containerID);
                     StopContainersRequest  request  = StopContainersRequest.NewInstance(ids);
                     StopContainersResponse response = proxy.GetContainerManagementProtocol().StopContainers
                                                           (request);
                     if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                             (this.containerID))
                     {
                         throw response.GetFailedRequests()[this.containerID].DeSerialize();
                     }
                 }
                 catch (Exception t)
                 {
                     // ignore the cleanup failure
                     string message = "cleanup failed for container " + this.containerID + " : " + StringUtils
                                      .StringifyException(t);
                     this._enclosing.context.GetEventHandler().Handle(new TaskAttemptDiagnosticsUpdateEvent
                                                                          (this.taskAttemptID, message));
                     ContainerLauncherImpl.Log.Warn(message);
                 }
                 finally
                 {
                     if (proxy != null)
                     {
                         this._enclosing.cmProxy.MayBeCloseProxy(proxy);
                     }
                 }
                 this.state = ContainerLauncherImpl.ContainerState.Done;
             }
         }
         // after killing, send killed event to task attempt
         this._enclosing.context.GetEventHandler().Handle(new TaskAttemptEvent(this.taskAttemptID
                                                                               , TaskAttemptEventType.TaContainerCleaned));
     }
 }
Esempio n. 4
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void Cleanup()
        {
            Connect();
            ContainerId         containerId  = masterContainer.GetId();
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(containerId);
            StopContainersRequest stopRequest = StopContainersRequest.NewInstance(containerIds
                                                                                  );
            StopContainersResponse response = containerMgrProxy.StopContainers(stopRequest);

            if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains
                    (containerId))
            {
                Exception t = response.GetFailedRequests()[containerId].DeSerialize();
                ParseAndThrowException(t);
            }
        }
        public virtual void TestMultipleContainersStopAndGetStatus()
        {
            containerManager.Start();
            IList <StartContainerRequest> startRequest           = new AList <StartContainerRequest>();
            ContainerLaunchContext        containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                                    >();
            IList <ContainerId> containerIds = new AList <ContainerId>();

            for (int i = 0; i < 10; i++)
            {
                ContainerId cId  = CreateContainerId(i);
                string      user = null;
                if ((i & 1) == 0)
                {
                    // container with even id fail
                    user = "******";
                }
                else
                {
                    user = "******";
                }
                Token containerToken = CreateContainerToken(cId, DummyRmIdentifier, context.GetNodeId
                                                                (), user, context.GetContainerTokenSecretManager());
                StartContainerRequest request = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                  , containerToken);
                startRequest.AddItem(request);
                containerIds.AddItem(cId);
            }
            // start containers
            StartContainersRequest requestList = StartContainersRequest.NewInstance(startRequest
                                                                                    );

            containerManager.StartContainers(requestList);
            // Get container statuses
            GetContainerStatusesRequest statusRequest = GetContainerStatusesRequest.NewInstance
                                                            (containerIds);
            GetContainerStatusesResponse statusResponse = containerManager.GetContainerStatuses
                                                              (statusRequest);

            NUnit.Framework.Assert.AreEqual(5, statusResponse.GetContainerStatuses().Count);
            foreach (ContainerStatus status in statusResponse.GetContainerStatuses())
            {
                // Containers with odd id should succeed
                NUnit.Framework.Assert.AreEqual(1, status.GetContainerId().GetContainerId() & 1);
            }
            NUnit.Framework.Assert.AreEqual(5, statusResponse.GetFailedRequests().Count);
            foreach (KeyValuePair <ContainerId, SerializedException> entry in statusResponse.GetFailedRequests
                         ())
            {
                // Containers with even id should fail.
                NUnit.Framework.Assert.AreEqual(0, entry.Key.GetContainerId() & 1);
                NUnit.Framework.Assert.IsTrue(entry.Value.GetMessage().Contains("Reject this container"
                                                                                ));
            }
            // stop containers
            StopContainersRequest stopRequest = StopContainersRequest.NewInstance(containerIds
                                                                                  );
            StopContainersResponse stopResponse = containerManager.StopContainers(stopRequest
                                                                                  );

            NUnit.Framework.Assert.AreEqual(5, stopResponse.GetSuccessfullyStoppedContainers(
                                                ).Count);
            foreach (ContainerId id in stopResponse.GetSuccessfullyStoppedContainers())
            {
                // Containers with odd id should succeed.
                NUnit.Framework.Assert.AreEqual(1, id.GetContainerId() & 1);
            }
            NUnit.Framework.Assert.AreEqual(5, stopResponse.GetFailedRequests().Count);
            foreach (KeyValuePair <ContainerId, SerializedException> entry_1 in stopResponse.GetFailedRequests
                         ())
            {
                // Containers with even id should fail.
                NUnit.Framework.Assert.AreEqual(0, entry_1.Key.GetContainerId() & 1);
                NUnit.Framework.Assert.IsTrue(entry_1.Value.GetMessage().Contains("Reject this container"
                                                                                  ));
            }
        }