/// <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); } }
public virtual void Launch(ContainerRemoteLaunchEvent @event) { lock (this) { ContainerLauncherImpl.Log.Info("Launching " + this.taskAttemptID); if (this.state == ContainerLauncherImpl.ContainerState.KilledBeforeLaunch) { this.state = ContainerLauncherImpl.ContainerState.Done; this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, "Container was killed before it was launched" ); return; } ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = null; try { proxy = this._enclosing.GetCMProxy(this.containerMgrAddress, this.containerID); // Construct the actual Container ContainerLaunchContext containerLaunchContext = @event.GetContainerLaunchContext( ); // Now launch the actual container StartContainerRequest startRequest = StartContainerRequest.NewInstance(containerLaunchContext , @event.GetContainerToken()); IList <StartContainerRequest> list = new AList <StartContainerRequest>(); list.AddItem(startRequest); StartContainersRequest requestList = StartContainersRequest.NewInstance(list); StartContainersResponse response = proxy.GetContainerManagementProtocol().StartContainers (requestList); if (response.GetFailedRequests() != null && response.GetFailedRequests().Contains (this.containerID)) { throw response.GetFailedRequests()[this.containerID].DeSerialize(); } ByteBuffer portInfo = response.GetAllServicesMetaData()[ShuffleHandler.MapreduceShuffleServiceid ]; int port = -1; if (portInfo != null) { port = ShuffleHandler.DeserializeMetaData(portInfo); } ContainerLauncherImpl.Log.Info("Shuffle port returned by ContainerManager for " + this.taskAttemptID + " : " + port); if (port < 0) { this.state = ContainerLauncherImpl.ContainerState.Failed; throw new InvalidOperationException("Invalid shuffle port number " + port + " returned for " + this.taskAttemptID); } // after launching, send launched event to task attempt to move // it from ASSIGNED to RUNNING state this._enclosing.context.GetEventHandler().Handle(new TaskAttemptContainerLaunchedEvent (this.taskAttemptID, port)); this.state = ContainerLauncherImpl.ContainerState.Running; } catch (Exception t) { string message = "Container launch failed for " + this.containerID + " : " + StringUtils .StringifyException(t); this.state = ContainerLauncherImpl.ContainerState.Failed; this._enclosing.SendContainerLaunchFailedMsg(this.taskAttemptID, message); } finally { if (proxy != null) { this._enclosing.cmProxy.MayBeCloseProxy(proxy); } } } }