/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public override void StopContainer(ContainerId containerId, NodeId nodeId) { NMClientImpl.StartedContainer startedContainer = GetStartedContainer(containerId); // Only allow one request of stopping the container to move forward // When entering the block, check whether the precursor has already stopped // the container if (startedContainer != null) { lock (startedContainer) { if (startedContainer.state != ContainerState.Running) { return; } StopContainerInternal(containerId, nodeId); // Only after successful startedContainer.state = ContainerState.Complete; RemoveStartedContainer(startedContainer); } } else { StopContainerInternal(containerId, nodeId); } }
protected internal virtual void RemoveStartedContainer(NMClientImpl.StartedContainer container) { lock (this) { Sharpen.Collections.Remove(startedContainers, container.containerId); } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> protected internal virtual NMClientImpl.StartedContainer CreateStartedContainer(Container container) { lock (this) { NMClientImpl.StartedContainer startedContainer = new NMClientImpl.StartedContainer (container.GetId(), container.GetNodeId(), container.GetContainerToken()); return(startedContainer); } }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> private void AddStartingContainer(NMClientImpl.StartedContainer startedContainer) { if (startedContainers.PutIfAbsent(startedContainer.containerId, startedContainer) != null) { throw RPCUtil.GetRemoteException("Container " + startedContainer.containerId.ToString () + " is already started"); } startedContainers[startedContainer.GetContainerId()] = startedContainer; }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public override IDictionary <string, ByteBuffer> StartContainer(Container container , ContainerLaunchContext containerLaunchContext) { // Do synchronization on StartedContainer to prevent race condition // between startContainer and stopContainer only when startContainer is // in progress for a given container. NMClientImpl.StartedContainer startingContainer = CreateStartedContainer(container ); lock (startingContainer) { AddStartingContainer(startingContainer); IDictionary <string, ByteBuffer> allServiceResponse; ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null; try { proxy = cmProxy.GetProxy(container.GetNodeId().ToString(), container.GetId()); StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext , container.GetContainerToken()); IList <StartContainerRequest> list = new AList <StartContainerRequest>(); list.AddItem(scRequest); StartContainersRequest allRequests = StartContainersRequest.NewInstance(list); StartContainersResponse response = proxy.GetContainerManagementProtocol().StartContainers (allRequests); if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains (container.GetId())) { Exception t = response.GetFailedRequests()[container.GetId()].DeSerialize(); ParseAndThrowException(t); } allServiceResponse = response.GetAllServicesMetaData(); startingContainer.state = ContainerState.Running; } catch (YarnException e) { startingContainer.state = ContainerState.Complete; // Remove the started container if it failed to start RemoveStartedContainer(startingContainer); throw; } catch (IOException e) { startingContainer.state = ContainerState.Complete; RemoveStartedContainer(startingContainer); throw; } catch (Exception t) { startingContainer.state = ContainerState.Complete; RemoveStartedContainer(startingContainer); throw RPCUtil.GetRemoteException(t); } finally { if (proxy != null) { cmProxy.MayBeCloseProxy(proxy); } } return(allServiceResponse); } }