/// <exception cref="Com.Google.Protobuf.ServiceException"/>
        public virtual YarnServiceProtos.GetContainersResponseProto GetContainers(RpcController
                                                                                  controller, YarnServiceProtos.GetContainersRequestProto proto)
        {
            GetContainersRequestPBImpl request = new GetContainersRequestPBImpl(proto);

            try
            {
                GetContainersResponse response = real.GetContainers(request);
                return(((GetContainersResponsePBImpl)response).GetProto());
            }
            catch (YarnException e)
            {
                throw new ServiceException(e);
            }
            catch (IOException e)
            {
                throw new ServiceException(e);
            }
        }
Exemplo n.º 2
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override IList <ContainerReport> GetContainers(ApplicationAttemptId applicationAttemptId
                                                              )
        {
            IList <ContainerReport> containersForAttempt = new AList <ContainerReport>();
            bool appNotFoundInRM = false;

            try
            {
                GetContainersRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <GetContainersRequest
                                                                                              >();
                request.SetApplicationAttemptId(applicationAttemptId);
                GetContainersResponse response = rmClient.GetContainers(request);
                Sharpen.Collections.AddAll(containersForAttempt, response.GetContainerList());
            }
            catch (YarnException e)
            {
                if (e.GetType() != typeof(ApplicationNotFoundException) || !historyServiceEnabled)
                {
                    // If Application is not in RM and history service is enabled then we
                    // need to check with history service else throw exception.
                    throw;
                }
                appNotFoundInRM = true;
            }
            if (historyServiceEnabled)
            {
                // Check with AHS even if found in RM because to capture info of finished
                // containers also
                IList <ContainerReport> containersListFromAHS = null;
                try
                {
                    containersListFromAHS = historyClient.GetContainers(applicationAttemptId);
                }
                catch (IOException e)
                {
                    // History service access might be enabled but system metrics publisher
                    // is disabled hence app not found exception is possible
                    if (appNotFoundInRM)
                    {
                        // app not found in bothM and RM then propagate the exception.
                        throw;
                    }
                }
                if (null != containersListFromAHS && containersListFromAHS.Count > 0)
                {
                    // remove duplicates
                    ICollection <ContainerId>     containerIdsToBeKeptFromAHS = new HashSet <ContainerId>();
                    IEnumerator <ContainerReport> tmpItr = containersListFromAHS.GetEnumerator();
                    while (tmpItr.HasNext())
                    {
                        containerIdsToBeKeptFromAHS.AddItem(tmpItr.Next().GetContainerId());
                    }
                    IEnumerator <ContainerReport> rmContainers = containersForAttempt.GetEnumerator();
                    while (rmContainers.HasNext())
                    {
                        ContainerReport tmp = rmContainers.Next();
                        containerIdsToBeKeptFromAHS.Remove(tmp.GetContainerId());
                    }
                    // Remove containers from AHS as container from RM will have latest
                    // information
                    if (containerIdsToBeKeptFromAHS.Count > 0 && containersListFromAHS.Count != containerIdsToBeKeptFromAHS
                        .Count)
                    {
                        IEnumerator <ContainerReport> containersFromHS = containersListFromAHS.GetEnumerator
                                                                             ();
                        while (containersFromHS.HasNext())
                        {
                            ContainerReport containerReport = containersFromHS.Next();
                            if (containerIdsToBeKeptFromAHS.Contains(containerReport.GetContainerId()))
                            {
                                containersForAttempt.AddItem(containerReport);
                            }
                        }
                    }
                    else
                    {
                        if (containersListFromAHS.Count == containerIdsToBeKeptFromAHS.Count)
                        {
                            Sharpen.Collections.AddAll(containersForAttempt, containersListFromAHS);
                        }
                    }
                }
            }
            return(containersForAttempt);
        }