protected internal virtual void ReleaseContainers(IList <ContainerId> containers, SchedulerApplicationAttempt attempt) { foreach (ContainerId containerId in containers) { RMContainer rmContainer = GetRMContainer(containerId); if (rmContainer == null) { if (Runtime.CurrentTimeMillis() - ResourceManager.GetClusterTimeStamp() < nmExpireInterval) { Log.Info(containerId + " doesn't exist. Add the container" + " to the release request cache as it maybe on recovery." ); lock (attempt) { attempt.GetPendingRelease().AddItem(containerId); } } else { RMAuditLogger.LogFailure(attempt.GetUser(), RMAuditLogger.AuditConstants.ReleaseContainer , "Unauthorized access or invalid container", "Scheduler", "Trying to release container not owned by app or with invalid id." , attempt.GetApplicationId(), containerId); } } CompletedContainer(rmContainer, SchedulerUtils.CreateAbnormalContainerStatus(containerId , SchedulerUtils.ReleasedContainer), RMContainerEventType.Released); } }
public virtual void TestCreateAbnormalContainerStatus() { ContainerStatus cd = SchedulerUtils.CreateAbnormalContainerStatus(ContainerId.NewContainerId (ApplicationAttemptId.NewInstance(ApplicationId.NewInstance(Runtime.CurrentTimeMillis (), 1), 1), 1), "x"); NUnit.Framework.Assert.AreEqual(ContainerExitStatus.Aborted, cd.GetExitStatus()); }
public virtual void RecoverContainersOnNode(IList <NMContainerStatus> containerReports , RMNode nm) { lock (this) { if (!rmContext.IsWorkPreservingRecoveryEnabled() || containerReports == null || ( containerReports != null && containerReports.IsEmpty())) { return; } foreach (NMContainerStatus container in containerReports) { ApplicationId appId = container.GetContainerId().GetApplicationAttemptId().GetApplicationId (); RMApp rmApp = rmContext.GetRMApps()[appId]; if (rmApp == null) { Log.Error("Skip recovering container " + container + " for unknown application."); KillOrphanContainerOnNode(nm, container); continue; } // Unmanaged AM recovery is addressed in YARN-1815 if (rmApp.GetApplicationSubmissionContext().GetUnmanagedAM()) { Log.Info("Skip recovering container " + container + " for unmanaged AM." + rmApp. GetApplicationId()); KillOrphanContainerOnNode(nm, container); continue; } SchedulerApplication <T> schedulerApp = applications[appId]; if (schedulerApp == null) { Log.Info("Skip recovering container " + container + " for unknown SchedulerApplication. Application current state is " + rmApp.GetState()); KillOrphanContainerOnNode(nm, container); continue; } Log.Info("Recovering container " + container); SchedulerApplicationAttempt schedulerAttempt = schedulerApp.GetCurrentAppAttempt( ); if (!rmApp.GetApplicationSubmissionContext().GetKeepContainersAcrossApplicationAttempts ()) { // Do not recover containers for stopped attempt or previous attempt. if (schedulerAttempt.IsStopped() || !schedulerAttempt.GetApplicationAttemptId().Equals (container.GetContainerId().GetApplicationAttemptId())) { Log.Info("Skip recovering container " + container + " for already stopped attempt." ); KillOrphanContainerOnNode(nm, container); continue; } } // create container RMContainer rmContainer = RecoverAndCreateContainer(container, nm); // recover RMContainer rmContainer.Handle(new RMContainerRecoverEvent(container.GetContainerId(), container )); // recover scheduler node nodes[nm.GetNodeID()].RecoverContainer(rmContainer); // recover queue: update headroom etc. Queue queue = schedulerAttempt.GetQueue(); queue.RecoverContainer(clusterResource, schedulerAttempt, rmContainer); // recover scheduler attempt schedulerAttempt.RecoverContainer(rmContainer); // set master container for the current running AMContainer for this // attempt. RMAppAttempt appAttempt = rmApp.GetCurrentAppAttempt(); if (appAttempt != null) { Container masterContainer = appAttempt.GetMasterContainer(); // Mark current running AMContainer's RMContainer based on the master // container ID stored in AppAttempt. if (masterContainer != null && masterContainer.GetId().Equals(rmContainer.GetContainerId ())) { ((RMContainerImpl)rmContainer).SetAMContainer(true); } } lock (schedulerAttempt) { ICollection <ContainerId> releases = schedulerAttempt.GetPendingRelease(); if (releases.Contains(container.GetContainerId())) { // release the container rmContainer.Handle(new RMContainerFinishedEvent(container.GetContainerId(), SchedulerUtils .CreateAbnormalContainerStatus(container.GetContainerId(), SchedulerUtils.ReleasedContainer ), RMContainerEventType.Released)); releases.Remove(container.GetContainerId()); Log.Info(container.GetContainerId() + " is released by application."); } } } } }