Search in sources :

Example 21 with StartContainersResponse

use of org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse in project hadoop by apache.

the class NMClientImpl method startContainer.

@Override
public Map<String, ByteBuffer> startContainer(Container container, ContainerLaunchContext containerLaunchContext) throws YarnException, IOException {
    // Do synchronization on StartedContainer to prevent race condition
    // between startContainer and stopContainer only when startContainer is
    // in progress for a given container.
    StartedContainer startingContainer = new StartedContainer(container.getId(), container.getNodeId());
    synchronized (startingContainer) {
        addStartingContainer(startingContainer);
        Map<String, ByteBuffer> allServiceResponse;
        ContainerManagementProtocolProxyData proxy = null;
        try {
            proxy = cmProxy.getProxy(container.getNodeId().toString(), container.getId());
            StartContainerRequest scRequest = StartContainerRequest.newInstance(containerLaunchContext, container.getContainerToken());
            List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
            list.add(scRequest);
            StartContainersRequest allRequests = StartContainersRequest.newInstance(list);
            StartContainersResponse response = proxy.getContainerManagementProtocol().startContainers(allRequests);
            if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(container.getId())) {
                Throwable t = response.getFailedRequests().get(container.getId()).deSerialize();
                parseAndThrowException(t);
            }
            allServiceResponse = response.getAllServicesMetaData();
            startingContainer.state = ContainerState.RUNNING;
        } catch (YarnException | IOException e) {
            startingContainer.state = ContainerState.COMPLETE;
            // Remove the started container if it failed to start
            startedContainers.remove(startingContainer.containerId);
            throw e;
        } catch (Throwable t) {
            startingContainer.state = ContainerState.COMPLETE;
            startedContainers.remove(startingContainer.containerId);
            throw RPCUtil.getRemoteException(t);
        } finally {
            if (proxy != null) {
                cmProxy.mayBeCloseProxy(proxy);
            }
        }
        return allServiceResponse;
    }
}
Also used : StartContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest) StartContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ContainerManagementProtocolProxyData(org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) StartContainerRequest(org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)

Aggregations

StartContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse)21 Test (org.junit.Test)16 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)15 ArrayList (java.util.ArrayList)11 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)11 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)11 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)10 ByteBuffer (java.nio.ByteBuffer)7 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Configuration (org.apache.hadoop.conf.Configuration)5 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)5 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)5 FileContext (org.apache.hadoop.fs.FileContext)4 TaskAttemptId (org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId)4 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)4 ContainerManagementProtocol (org.apache.hadoop.yarn.api.ContainerManagementProtocol)4 StopContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest)4 LogAggregationContext (org.apache.hadoop.yarn.api.records.LogAggregationContext)4