/** * Get a list of container statuses running on this NodeManager */ @Override public GetContainerStatusesResponse getContainerStatuses( GetContainerStatusesRequest request) throws YarnException, IOException { List<ContainerStatus> succeededRequests = new ArrayList<ContainerStatus>(); Map<ContainerId, SerializedException> failedRequests = new HashMap<ContainerId, SerializedException>(); UserGroupInformation remoteUgi = getRemoteUgi(); NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi); for (ContainerId id : request.getContainerIds()) { try { ContainerStatus status = getContainerStatusInternal(id, identifier); succeededRequests.add(status); } catch (YarnException e) { failedRequests.put(id, SerializedException.newInstance(e)); } } return GetContainerStatusesResponse.newInstance(succeededRequests, failedRequests); }
public static void waitForContainerState(ContainerManagementProtocol containerManager, ContainerId containerID, ContainerState finalState, int timeOutMax) throws InterruptedException, YarnException, IOException { List<ContainerId> list = new ArrayList<ContainerId>(); list.add(containerID); GetContainerStatusesRequest request = GetContainerStatusesRequest.newInstance(list); ContainerStatus containerStatus = containerManager.getContainerStatuses(request).getContainerStatuses() .get(0); int timeoutSecs = 0; while (!containerStatus.getState().equals(finalState) && timeoutSecs++ < timeOutMax) { Thread.sleep(1000); LOG.info("Waiting for container to get into state " + finalState + ". Current state is " + containerStatus.getState()); containerStatus = containerManager.getContainerStatuses(request).getContainerStatuses().get(0); } LOG.info("Container state is " + containerStatus.getState()); Assert.assertEquals("ContainerState is not correct (timedout)", finalState, containerStatus.getState()); }
@Override synchronized public GetContainerStatusesResponse getContainerStatuses( GetContainerStatusesRequest request) throws YarnException { List<ContainerStatus> statuses = new ArrayList<ContainerStatus>(); for (ContainerId containerId : request.getContainerIds()) { List<Container> appContainers = containers.get(containerId.getApplicationAttemptId() .getApplicationId()); Container container = null; for (Container c : appContainers) { if (c.getId().equals(containerId)) { container = c; } } if (container != null && containerStatusMap.get(container).getState() != null) { statuses.add(containerStatusMap.get(container)); } } return GetContainerStatusesResponse.newInstance(statuses, null); }
@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); } } }
/** * Get a list of container statuses running on this NodeManager */ @Override public GetContainerStatusesResponse getContainerStatuses( GetContainerStatusesRequest request) throws YarnException, IOException { List<ContainerStatus> succeededRequests = new ArrayList<ContainerStatus>(); Map<ContainerId, SerializedException> failedRequests = new HashMap<ContainerId, SerializedException>(); UserGroupInformation remoteUgi = getRemoteUgi(); NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi); if (identifier == null) { throw RPCUtil.getRemoteException(INVALID_NMTOKEN_MSG); } for (ContainerId id : request.getContainerIds()) { try { ContainerStatus status = getContainerStatusInternal(id, identifier); succeededRequests.add(status); } catch (YarnException e) { failedRequests.put(id, SerializedException.newInstance(e)); } } return GetContainerStatusesResponse.newInstance(succeededRequests, failedRequests); }
private ContainerStatus getContainerStatus( Context context, final ContainerManagerImpl cm, ContainerId cid) throws Exception { UserGroupInformation user = UserGroupInformation.createRemoteUser( cid.getApplicationAttemptId().toString()); NMTokenIdentifier nmToken = new NMTokenIdentifier( cid.getApplicationAttemptId(), context.getNodeId(), user.getShortUserName(), context.getNMTokenSecretManager().getCurrentKey().getKeyId()); user.addTokenIdentifier(nmToken); List<ContainerId> containerIds = new ArrayList<>(); containerIds.add(cid); final GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.newInstance(containerIds); return user.doAs( new PrivilegedExceptionAction<ContainerStatus>() { @Override public ContainerStatus run() throws Exception { return cm.getContainerStatuses(gcsRequest) .getContainerStatuses().get(0); } }); }
@Override public GetContainerStatusesResponse getContainerStatuses( GetContainerStatusesRequest request) throws YarnException, IOException { GetContainerStatusesRequestProto requestProto = ((GetContainerStatusesRequestPBImpl) request).getProto(); try { return new GetContainerStatusesResponsePBImpl(proxy.getContainerStatuses( null, requestProto)); } catch (ServiceException e) { RPCUtil.unwrapAndThrowException(e); return null; } }
@Override public GetContainerStatusesResponse getContainerStatuses( GetContainerStatusesRequest request) throws YarnException { GetContainerStatusesResponse response = recordFactory.newRecordInstance(GetContainerStatusesResponse.class); response.setContainerStatuses(statuses); return response; }