Example usage for org.apache.hadoop.yarn.api ContainerManagementProtocol stopContainers

List of usage examples for org.apache.hadoop.yarn.api ContainerManagementProtocol stopContainers

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api ContainerManagementProtocol stopContainers.

Prototype

@Public
@Stable
StopContainersResponse stopContainers(StopContainersRequest request) throws YarnException, IOException;

Source Link

Document

The ApplicationMaster requests a NodeManager to stop a list of Container s allocated to it using this interface.

Usage

From source file:org.apache.tajo.master.YarnContainerProxy.java

License:Apache License

@Override
public synchronized void stopContainer() {

    if (isCompletelyDone()) {
        return;//from   w w w  .  ja  va2s.c o m
    }
    if (this.state == ContainerState.PREP) {
        this.state = ContainerState.KILLED_BEFORE_LAUNCH;
    } else {
        LOG.info("KILLING " + containerID);

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

            // kill the remote container if already launched
            List<ContainerId> willBeStopedIds = new ArrayList<ContainerId>();
            willBeStopedIds.add(this.containerID);
            StopContainersRequest stopRequests = Records.newRecord(StopContainersRequest.class);
            stopRequests.setContainerIds(willBeStopedIds);
            proxy.stopContainers(stopRequests);
            // If stopContainer returns without an error, assuming the stop made
            // it over to the NodeManager.
            //          context.getEventHandler().handle(
            //              new AMContainerEvent(containerID, AMContainerEventType.C_NM_STOP_SENT));
            context.getResourceAllocator().removeContainer(containerID);
        } catch (Throwable t) {

            // ignore the cleanup failure
            String message = "cleanup failed for container " + this.containerID + " : "
                    + StringUtils.stringifyException(t);
            //          context.getEventHandler().handle(
            //              new AMContainerEventStopFailed(containerID, message));
            LOG.warn(message);
            this.state = ContainerState.DONE;
            return;
        } finally {
            if (proxy != null) {
                yarnRPC.stopProxy(proxy, conf);
            }
        }
        this.state = ContainerState.DONE;
    }
}

From source file:org.springframework.yarn.am.AppmasterCmTemplate.java

License:Apache License

@Override
public StopContainersResponse stopContainers() {
    return execute(new YarnRpcCallback<StopContainersResponse, ContainerManagementProtocol>() {
        @Override//from   w  ww .j  a v  a 2s .c  om
        public StopContainersResponse doInYarn(ContainerManagementProtocol proxy)
                throws YarnException, IOException {
            StopContainersRequest request = Records.newRecord(StopContainersRequest.class);
            ArrayList<ContainerId> ids = new ArrayList<ContainerId>();
            ids.add(container.getId());
            request.setContainerIds(ids);
            return proxy.stopContainers(request);
        }
    });
}