private void stopContainer(YarnRPC rpc, Token nmToken, List<ContainerId> containerId, ApplicationAttemptId appAttemptId, NodeId nodeId) throws Exception { StopContainersRequest request = StopContainersRequest.newInstance(containerId); ContainerManagementProtocol proxy = null; try { proxy = getContainerManagementProtocolProxy(rpc, nmToken, nodeId, appAttemptId.toString()); StopContainersResponse response = proxy.stopContainers(request); if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(containerId)) { parseAndThrowException(response.getFailedRequests().get(containerId) .deSerialize()); } } catch (Exception e) { if (proxy != null) { rpc.stopProxy(proxy, conf); } } }
/** * Stop a list of containers running on this NodeManager. */ @Override public StopContainersResponse stopContainers(StopContainersRequest requests) throws YarnException, IOException { List<ContainerId> succeededRequests = new ArrayList<ContainerId>(); Map<ContainerId, SerializedException> failedRequests = new HashMap<ContainerId, SerializedException>(); UserGroupInformation remoteUgi = getRemoteUgi(); NMTokenIdentifier identifier = selectNMTokenIdentifier(remoteUgi); for (ContainerId id : requests.getContainerIds()) { try { stopContainerInternal(identifier, id); succeededRequests.add(id); } catch (YarnException e) { failedRequests.put(id, SerializedException.newInstance(e)); } } return StopContainersResponse .newInstance(succeededRequests, failedRequests); }
public synchronized void finishTask(Task task) throws IOException, YarnException { Set<Task> tasks = this.tasks.get(task.getPriority()); if (!tasks.remove(task)) { throw new IllegalStateException( "Finishing unknown task " + task.getTaskId() + " from application " + applicationId); } NodeManager nodeManager = task.getNodeManager(); ContainerId containerId = task.getContainerId(); task.stop(); List<ContainerId> containerIds = new ArrayList<ContainerId>(); containerIds.add(containerId); StopContainersRequest stopRequest = StopContainersRequest.newInstance(containerIds); nodeManager.stopContainers(stopRequest); Resources.subtractFrom(used, requestSpec.get(task.getPriority())); LOG.info("Finished task " + task.getTaskId() + " of application " + applicationId + " on node " + nodeManager.getHostName() + ", currently using " + used + " resources"); }
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); } } }
/** * Stop a list of containers running on this NodeManager. */ @Override public StopContainersResponse stopContainers(StopContainersRequest requests) throws YarnException, IOException { List<ContainerId> succeededRequests = new ArrayList<ContainerId>(); 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 : requests.getContainerIds()) { try { stopContainerInternal(identifier, id); succeededRequests.add(id); } catch (YarnException e) { failedRequests.put(id, SerializedException.newInstance(e)); } } return StopContainersResponse .newInstance(succeededRequests, failedRequests); }
@Override public StopContainersResponse stopContainers(StopContainersRequest requests) throws YarnException, IOException { StopContainersRequestProto requestProto = ((StopContainersRequestPBImpl) requests).getProto(); try { return new StopContainersResponsePBImpl(proxy.stopContainers(null, requestProto)); } catch (ServiceException e) { RPCUtil.unwrapAndThrowException(e); return null; } }
@Override public StopContainersResponse stopContainers(StopContainersRequest request) throws YarnException { Exception e = new Exception(EXCEPTION_MSG, new Exception(EXCEPTION_CAUSE)); throw new YarnException(e); }
@Override public StopContainersResponse stopContainers(StopContainersRequest requests) throws YarnException, IOException { Exception e = new Exception("Dummy function", new Exception( "Dummy function cause")); throw new YarnException(e); }
private void cleanup() throws IOException, YarnException { connect(); ContainerId containerId = masterContainer.getId(); List<ContainerId> containerIds = new ArrayList<ContainerId>(); containerIds.add(containerId); StopContainersRequest stopRequest = StopContainersRequest.newInstance(containerIds); StopContainersResponse response = containerMgrProxy.stopContainers(stopRequest); if (response.getFailedRequests() != null && response.getFailedRequests().containsKey(containerId)) { Throwable t = response.getFailedRequests().get(containerId).deSerialize(); parseAndThrowException(t); } }
@Override public StopContainersResponse stopContainers(StopContainersRequest request) throws YarnException { LOG.info("Container cleaned up by MyContainerManager"); cleanedup = true; return null; }