Search in sources :

Example 1 with ContainerManagementProtocolProxyData

use of org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData in project hadoop by apache.

the class NMClientImpl method increaseContainerResource.

@Override
public void increaseContainerResource(Container container) throws YarnException, IOException {
    ContainerManagementProtocolProxyData proxy = null;
    try {
        proxy = cmProxy.getProxy(container.getNodeId().toString(), container.getId());
        List<Token> increaseTokens = new ArrayList<>();
        increaseTokens.add(container.getContainerToken());
        IncreaseContainersResourceRequest increaseRequest = IncreaseContainersResourceRequest.newInstance(increaseTokens);
        IncreaseContainersResourceResponse response = proxy.getContainerManagementProtocol().increaseContainersResource(increaseRequest);
        if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(container.getId())) {
            Throwable t = response.getFailedRequests().get(container.getId()).deSerialize();
            parseAndThrowException(t);
        }
    } finally {
        if (proxy != null) {
            cmProxy.mayBeCloseProxy(proxy);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IncreaseContainersResourceRequest(org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) Token(org.apache.hadoop.yarn.api.records.Token) ContainerManagementProtocolProxyData(org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData) IncreaseContainersResourceResponse(org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse)

Example 2 with ContainerManagementProtocolProxyData

use of org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData in project hadoop by apache.

the class NMClientImpl method getContainerStatus.

@Override
public ContainerStatus getContainerStatus(ContainerId containerId, NodeId nodeId) throws YarnException, IOException {
    ContainerManagementProtocolProxyData proxy = null;
    List<ContainerId> containerIds = new ArrayList<ContainerId>();
    containerIds.add(containerId);
    try {
        proxy = cmProxy.getProxy(nodeId.toString(), containerId);
        GetContainerStatusesResponse response = proxy.getContainerManagementProtocol().getContainerStatuses(GetContainerStatusesRequest.newInstance(containerIds));
        if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(containerId)) {
            Throwable t = response.getFailedRequests().get(containerId).deSerialize();
            parseAndThrowException(t);
        }
        ContainerStatus containerStatus = response.getContainerStatuses().get(0);
        return containerStatus;
    } finally {
        if (proxy != null) {
            cmProxy.mayBeCloseProxy(proxy);
        }
    }
}
Also used : GetContainerStatusesResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) ContainerManagementProtocolProxyData(org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData)

Example 3 with ContainerManagementProtocolProxyData

use of org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData 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)

Example 4 with ContainerManagementProtocolProxyData

use of org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData in project hadoop by apache.

the class NMClientImpl method stopContainerInternal.

private void stopContainerInternal(ContainerId containerId, NodeId nodeId) throws IOException, YarnException {
    ContainerManagementProtocolProxyData proxy = null;
    List<ContainerId> containerIds = new ArrayList<ContainerId>();
    containerIds.add(containerId);
    try {
        proxy = cmProxy.getProxy(nodeId.toString(), containerId);
        StopContainersResponse response = proxy.getContainerManagementProtocol().stopContainers(StopContainersRequest.newInstance(containerIds));
        if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(containerId)) {
            Throwable t = response.getFailedRequests().get(containerId).deSerialize();
            parseAndThrowException(t);
        }
    } finally {
        if (proxy != null) {
            cmProxy.mayBeCloseProxy(proxy);
        }
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ArrayList(java.util.ArrayList) ContainerManagementProtocolProxyData(org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData) StopContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse)

Aggregations

ArrayList (java.util.ArrayList)4 ContainerManagementProtocolProxyData (org.apache.hadoop.yarn.client.api.impl.ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 InvalidToken (org.apache.hadoop.security.token.SecretManager.InvalidToken)1 GetContainerStatusesResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse)1 IncreaseContainersResourceRequest (org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest)1 IncreaseContainersResourceResponse (org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse)1 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)1 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)1 StartContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse)1 StopContainersResponse (org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse)1 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)1 Token (org.apache.hadoop.yarn.api.records.Token)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1