Search in sources :

Example 1 with ChangeMonitoringContainerResourceEvent

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ChangeMonitoringContainerResourceEvent in project hadoop by apache.

the class ContainerManagerImpl method changeContainerResourceInternal.

@SuppressWarnings("unchecked")
private void changeContainerResourceInternal(ContainerId containerId, int containerVersion, Resource targetResource, boolean increase) throws YarnException, IOException {
    Container container = context.getContainers().get(containerId);
    // Check container existence
    if (container == null) {
        if (nodeStatusUpdater.isContainerRecentlyStopped(containerId)) {
            throw RPCUtil.getRemoteException("Container " + containerId.toString() + " was recently stopped on node manager.");
        } else {
            throw RPCUtil.getRemoteException("Container " + containerId.toString() + " is not handled by this NodeManager");
        }
    }
    // Check container state
    org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState currentState = container.getContainerState();
    if (currentState != org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState.RUNNING) {
        throw RPCUtil.getRemoteException("Container " + containerId.toString() + " is in " + currentState.name() + " state." + " Resource can only be changed when a container is in" + " RUNNING state");
    }
    // Check validity of the target resource.
    Resource currentResource = container.getResource();
    if (currentResource.equals(targetResource)) {
        LOG.warn("Unable to change resource for container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is the same as the current resource");
        return;
    }
    if (increase && !Resources.fitsIn(currentResource, targetResource)) {
        throw RPCUtil.getRemoteException("Unable to increase resource for " + "container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is smaller than the current resource " + currentResource.toString());
    }
    if (!increase && (!Resources.fitsIn(Resources.none(), targetResource) || !Resources.fitsIn(targetResource, currentResource))) {
        throw RPCUtil.getRemoteException("Unable to decrease resource for " + "container " + containerId.toString() + ". The target resource " + targetResource.toString() + " is not smaller than the current resource " + currentResource.toString());
    }
    if (increase) {
        org.apache.hadoop.yarn.api.records.Container increasedContainer = org.apache.hadoop.yarn.api.records.Container.newInstance(containerId, null, null, targetResource, null, null);
        if (context.getIncreasedContainers().putIfAbsent(containerId, increasedContainer) != null) {
            throw RPCUtil.getRemoteException("Container " + containerId.toString() + " resource is being increased.");
        }
    }
    this.readLock.lock();
    try {
        if (!serviceStopped) {
            // Persist container resource change for recovery
            this.context.getNMStateStore().storeContainerResourceChanged(containerId, containerVersion, targetResource);
            getContainersMonitor().handle(new ChangeMonitoringContainerResourceEvent(containerId, targetResource));
        } else {
            throw new YarnException("Unable to change container resource as the NodeManager is " + "in the process of shutting down");
        }
    } finally {
        this.readLock.unlock();
    }
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ChangeMonitoringContainerResourceEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ChangeMonitoringContainerResourceEvent) Resource(org.apache.hadoop.yarn.api.records.Resource) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

Resource (org.apache.hadoop.yarn.api.records.Resource)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)1 ChangeMonitoringContainerResourceEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ChangeMonitoringContainerResourceEvent)1