Exemple #1
0
        /// <exception cref="System.Exception"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public static void WaitForContainerState(ContainerManagementProtocol containerManager
                                                 , ContainerId containerID, ContainerState finalState, int timeOutMax)
        {
            IList <ContainerId> list = new AList <ContainerId>();

            list.AddItem(containerID);
            GetContainerStatusesRequest request = GetContainerStatusesRequest.NewInstance(list
                                                                                          );
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(request).
                                              GetContainerStatuses()[0];
            int timeoutSecs = 0;

            while (!containerStatus.GetState().Equals(finalState) && timeoutSecs++ < timeOutMax
                   )
            {
                Sharpen.Thread.Sleep(1000);
                Log.Info("Waiting for container to get into state " + finalState + ". Current state is "
                         + containerStatus.GetState());
                containerStatus = containerManager.GetContainerStatuses(request).GetContainerStatuses
                                      ()[0];
            }
            Log.Info("Container state is " + containerStatus.GetState());
            NUnit.Framework.Assert.AreEqual("ContainerState is not correct (timedout)", finalState
                                            , containerStatus.GetState());
        }
Exemple #2
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 private void TestGetContainerStatus(Container container, int index, ContainerState
                                     state, string diagnostics, IList <int> exitStatuses)
 {
     while (true)
     {
         try
         {
             ContainerStatus status = nmClient.GetContainerStatus(container.GetId(), container
                                                                  .GetNodeId());
             // NodeManager may still need some time to get the stable
             // container status
             if (status.GetState() == state)
             {
                 NUnit.Framework.Assert.AreEqual(container.GetId(), status.GetContainerId());
                 NUnit.Framework.Assert.IsTrue(string.Empty + index + ": " + status.GetDiagnostics
                                                   (), status.GetDiagnostics().Contains(diagnostics));
                 NUnit.Framework.Assert.IsTrue("Exit Statuses are supposed to be in: " + exitStatuses
                                               + ", but the actual exit status code is: " + status.GetExitStatus(), exitStatuses
                                               .Contains(status.GetExitStatus()));
                 break;
             }
             Sharpen.Thread.Sleep(100);
         }
         catch (Exception e)
         {
             Sharpen.Runtime.PrintStackTrace(e);
         }
     }
 }
Exemple #3
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public static void StartContainer(NodeManager nm, ContainerId cId, FileContext localFS
                                          , FilePath scriptFileDir, FilePath processStartFile)
        {
            FilePath scriptFile = CreateUnhaltingScriptFile(cId, scriptFileDir, processStartFile
                                                            );
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            NodeId nodeId = BuilderUtils.NewNodeId(Sharpen.Extensions.GetAddressByName("localhost"
                                                                                       ).ToString(), 12345);
            URL localResourceUri = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new
                                                                                           Path(scriptFile.GetAbsolutePath())));
            LocalResource localResource = recordFactory.NewRecordInstance <LocalResource>();

            localResource.SetResource(localResourceUri);
            localResource.SetSize(-1);
            localResource.SetVisibility(LocalResourceVisibility.Application);
            localResource.SetType(LocalResourceType.File);
            localResource.SetTimestamp(scriptFile.LastModified());
            string destinationFile = "dest_file";
            IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource
                                                                                 >();

            localResources[destinationFile] = localResource;
            containerLaunchContext.SetLocalResources(localResources);
            IList <string> commands = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile));

            containerLaunchContext.SetCommands(commands);
            IPEndPoint containerManagerBindAddress = NetUtils.CreateSocketAddrForHost("127.0.0.1"
                                                                                      , 12345);
            UserGroupInformation currentUser = UserGroupInformation.CreateRemoteUser(cId.ToString
                                                                                         ());

            Org.Apache.Hadoop.Security.Token.Token <NMTokenIdentifier> nmToken = ConverterUtils
                                                                                 .ConvertFromYarn(nm.GetNMContext().GetNMTokenSecretManager().CreateNMToken(cId.GetApplicationAttemptId
                                                                                                                                                                (), nodeId, user), containerManagerBindAddress);
            currentUser.AddToken(nmToken);
            ContainerManagementProtocol containerManager = currentUser.DoAs(new _PrivilegedAction_229
                                                                                ());
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , TestContainerManager.CreateContainerToken(cId, 0, nodeId, user, nm.GetNMContext
                                                                                                                                ().GetContainerTokenSecretManager()));
            IList <StartContainerRequest> list = new AList <StartContainerRequest>();

            list.AddItem(scRequest);
            StartContainersRequest allRequests = StartContainersRequest.NewInstance(list);

            containerManager.StartContainers(allRequests);
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(cId);
            GetContainerStatusesRequest request = GetContainerStatusesRequest.NewInstance(containerIds
                                                                                          );
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(request).
                                              GetContainerStatuses()[0];

            NUnit.Framework.Assert.AreEqual(ContainerState.Running, containerStatus.GetState(
                                                ));
        }
Exemple #4
0
        protected internal virtual IList <ContainerStatus> GetContainerStatuses()
        {
            IList <ContainerStatus> containerStatuses = new AList <ContainerStatus>();

            foreach (Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                     container in this.context.GetContainers().Values)
            {
                ContainerId   containerId   = container.GetContainerId();
                ApplicationId applicationId = containerId.GetApplicationAttemptId().GetApplicationId
                                                  ();
                ContainerStatus containerStatus = container.CloneAndGetContainerStatus();
                if (containerStatus.GetState() == ContainerState.Complete)
                {
                    if (IsApplicationStopped(applicationId))
                    {
                        if (Log.IsDebugEnabled())
                        {
                            Log.Debug(applicationId + " is completing, " + " remove " + containerId + " from NM context."
                                      );
                        }
                        Sharpen.Collections.Remove(context.GetContainers(), containerId);
                        pendingCompletedContainers[containerId] = containerStatus;
                    }
                    else
                    {
                        if (!IsContainerRecentlyStopped(containerId))
                        {
                            pendingCompletedContainers[containerId] = containerStatus;
                        }
                    }
                    // Adding to finished containers cache. Cache will keep it around at
                    // least for #durationToTrackStoppedContainers duration. In the
                    // subsequent call to stop container it will get removed from cache.
                    AddCompletedContainer(containerId);
                }
                else
                {
                    containerStatuses.AddItem(containerStatus);
                }
            }
            Sharpen.Collections.AddAll(containerStatuses, pendingCompletedContainers.Values);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Sending out " + containerStatuses.Count + " container statuses: " + containerStatuses
                          );
            }
            return(containerStatuses);
        }