Java Code Examples for org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest#newInstance()

The following examples show how to use org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestContainerManagerSecurity.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example 2
Source File: Application.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 3
Source File: TestContainerManagerSecurity.java    From big-c with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example 4
Source File: Application.java    From big-c with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 5
Source File: AMLauncher.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 6
Source File: AMLauncher.java    From big-c with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 7
Source File: ContainerLauncherImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized void kill() {

  if(this.state == ContainerState.PREP) {
    this.state = ContainerState.KILLED_BEFORE_LAUNCH;
  } else if (!isCompletelyDone()) {
    LOG.info("KILLING " + taskAttemptID);

    ContainerManagementProtocolProxyData proxy = null;
    try {
      proxy = getCMProxy(this.containerMgrAddress, this.containerID);

      // kill the remote container if already launched
      List<ContainerId> ids = new ArrayList<ContainerId>();
      ids.add(this.containerID);
      StopContainersRequest request = StopContainersRequest.newInstance(ids);
      StopContainersResponse response =
          proxy.getContainerManagementProtocol().stopContainers(request);
      if (response.getFailedRequests() != null
          && response.getFailedRequests().containsKey(this.containerID)) {
        throw response.getFailedRequests().get(this.containerID)
          .deSerialize();
      }
    } catch (Throwable t) {
      // ignore the cleanup failure
      String message = "cleanup failed for container "
          + this.containerID + " : "
          + StringUtils.stringifyException(t);
      context.getEventHandler()
          .handle(
              new TaskAttemptDiagnosticsUpdateEvent(this.taskAttemptID,
                  message));
      LOG.warn(message);
    } finally {
      if (proxy != null) {
        cmProxy.mayBeCloseProxy(proxy);
      }
    }
    this.state = ContainerState.DONE;
  }
  // after killing, send killed event to task attempt
  context.getEventHandler().handle(
      new TaskAttemptEvent(this.taskAttemptID,
          TaskAttemptEventType.TA_CONTAINER_CLEANED));
}
 
Example 8
Source File: ContainerLauncherImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized void kill() {

  if(this.state == ContainerState.PREP) {
    this.state = ContainerState.KILLED_BEFORE_LAUNCH;
  } else if (!isCompletelyDone()) {
    LOG.info("KILLING " + taskAttemptID);

    ContainerManagementProtocolProxyData proxy = null;
    try {
      proxy = getCMProxy(this.containerMgrAddress, this.containerID);

      // kill the remote container if already launched
      List<ContainerId> ids = new ArrayList<ContainerId>();
      ids.add(this.containerID);
      StopContainersRequest request = StopContainersRequest.newInstance(ids);
      StopContainersResponse response =
          proxy.getContainerManagementProtocol().stopContainers(request);
      if (response.getFailedRequests() != null
          && response.getFailedRequests().containsKey(this.containerID)) {
        throw response.getFailedRequests().get(this.containerID)
          .deSerialize();
      }
    } catch (Throwable t) {
      // ignore the cleanup failure
      String message = "cleanup failed for container "
          + this.containerID + " : "
          + StringUtils.stringifyException(t);
      context.getEventHandler()
          .handle(
              new TaskAttemptDiagnosticsUpdateEvent(this.taskAttemptID,
                  message));
      LOG.warn(message);
    } finally {
      if (proxy != null) {
        cmProxy.mayBeCloseProxy(proxy);
      }
    }
    this.state = ContainerState.DONE;
  }
  // after killing, send killed event to task attempt
  context.getEventHandler().handle(
      new TaskAttemptEvent(this.taskAttemptID,
          TaskAttemptEventType.TA_CONTAINER_CLEANED));
}