/// <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); } } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> public virtual StopContainersResponse StopContainers(StopContainersRequest request ) { lock (this) { foreach (ContainerId containerID in request.GetContainerIds()) { string applicationId = containerID.GetApplicationAttemptId().GetApplicationId().GetId ().ToString(); // Mark the container as COMPLETE IList <Container> applicationContainers = containers[containerID.GetApplicationAttemptId ().GetApplicationId()]; foreach (Container c in applicationContainers) { if (c.GetId().CompareTo(containerID) == 0) { ContainerStatus containerStatus = containerStatusMap[c]; containerStatus.SetState(ContainerState.Complete); containerStatusMap[c] = containerStatus; } } // Send a heartbeat try { Heartbeat(); } catch (IOException ioe) { throw RPCUtil.GetRemoteException(ioe); } // Remove container and update status int ctr = 0; Container container = null; for (IEnumerator <Container> i = applicationContainers.GetEnumerator(); i.HasNext( );) { container = i.Next(); if (container.GetId().CompareTo(containerID) == 0) { i.Remove(); ++ctr; } } if (ctr != 1) { throw new InvalidOperationException("Container " + containerID + " stopped " + ctr + " times!"); } Resources.AddTo(available, container.GetResource()); Resources.SubtractFrom(used, container.GetResource()); if (Log.IsDebugEnabled()) { Log.Debug("stopContainer:" + " node=" + containerManagerAddress + " application=" + applicationId + " container=" + containerID + " available=" + available + " used=" + used); } } return(StopContainersResponse.NewInstance(null, null)); } }
/// <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); } } }
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)); } }
/// <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); } }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual YarnServiceProtos.StopContainersResponseProto StopContainers(RpcController arg0, YarnServiceProtos.StopContainersRequestProto proto) { StopContainersRequestPBImpl request = new StopContainersRequestPBImpl(proto); try { StopContainersResponse response = real.StopContainers(request); return(((StopContainersResponsePBImpl)response).GetProto()); } catch (YarnException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } }
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" )); } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> public StopContainersResponse StopContainers(StopContainersRequest request) { return(StopContainersResponse.NewInstance(null, null)); }