Search in sources :

Example 66 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.

the class ContainerManagerImpl method recoverActiveContainer.

/**
   * Recover a running container.
   */
@SuppressWarnings("unchecked")
protected void recoverActiveContainer(Application app, ContainerLaunchContext launchContext, ContainerTokenIdentifier token, RecoveredContainerState rcs) throws IOException {
    Credentials credentials = YarnServerSecurityUtils.parseCredentials(launchContext);
    Container container = new ContainerImpl(getConfig(), dispatcher, launchContext, credentials, metrics, token, context, rcs);
    context.getContainers().put(token.getContainerID(), container);
    app.handle(new ApplicationContainerInitEvent(container));
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerImpl(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl) ApplicationContainerInitEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationContainerInitEvent) Credentials(org.apache.hadoop.security.Credentials)

Example 67 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container 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)

Example 68 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.

the class ContainerManagerImpl method stopContainerInternal.

@SuppressWarnings("unchecked")
protected void stopContainerInternal(ContainerId containerID) throws YarnException, IOException {
    String containerIDStr = containerID.toString();
    Container container = this.context.getContainers().get(containerID);
    LOG.info("Stopping container with container Id: " + containerIDStr);
    if (container == null) {
        if (!nodeStatusUpdater.isContainerRecentlyStopped(containerID)) {
            throw RPCUtil.getRemoteException("Container " + containerIDStr + " is not handled by this NodeManager");
        }
    } else {
        if (container.isRecovering()) {
            throw new NMNotYetReadyException("Container " + containerIDStr + " is recovering, try later");
        }
        context.getNMStateStore().storeContainerKilled(containerID);
        container.sendKillEvent(ContainerExitStatus.KILLED_BY_APPMASTER, "Container killed by the ApplicationMaster.");
        NMAuditLogger.logSuccess(container.getUser(), AuditConstants.STOP_CONTAINER, "ContainerManageImpl", containerID.getApplicationAttemptId().getApplicationId(), containerID);
    }
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ByteString(com.google.protobuf.ByteString) NMNotYetReadyException(org.apache.hadoop.yarn.exceptions.NMNotYetReadyException)

Example 69 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.

the class ResourceLocalizationService method handleCleanupContainerResources.

@SuppressWarnings("unchecked")
private void handleCleanupContainerResources(ContainerLocalizationCleanupEvent rsrcCleanup) {
    Container c = rsrcCleanup.getContainer();
    Map<LocalResourceVisibility, Collection<LocalResourceRequest>> rsrcs = rsrcCleanup.getResources();
    for (Map.Entry<LocalResourceVisibility, Collection<LocalResourceRequest>> e : rsrcs.entrySet()) {
        LocalResourcesTracker tracker = getLocalResourcesTracker(e.getKey(), c.getUser(), c.getContainerId().getApplicationAttemptId().getApplicationId());
        for (LocalResourceRequest req : e.getValue()) {
            tracker.handle(new ResourceReleaseEvent(req, c.getContainerId()));
        }
    }
    String locId = c.getContainerId().toString();
    localizerTracker.cleanupPrivLocalizers(locId);
    // Delete the container directories
    String userName = c.getUser();
    String containerIDStr = c.toString();
    String appIDStr = c.getContainerId().getApplicationAttemptId().getApplicationId().toString();
    for (String localDir : dirsHandler.getLocalDirsForCleanup()) {
        // Delete the user-owned container-dir
        Path usersdir = new Path(localDir, ContainerLocalizer.USERCACHE);
        Path userdir = new Path(usersdir, userName);
        Path allAppsdir = new Path(userdir, ContainerLocalizer.APPCACHE);
        Path appDir = new Path(allAppsdir, appIDStr);
        Path containerDir = new Path(appDir, containerIDStr);
        submitDirForDeletion(userName, containerDir);
        // Delete the nmPrivate container-dir
        Path sysDir = new Path(localDir, NM_PRIVATE_DIR);
        Path appSysDir = new Path(sysDir, appIDStr);
        Path containerSysDir = new Path(appSysDir, containerIDStr);
        submitDirForDeletion(null, containerSysDir);
    }
    dispatcher.getEventHandler().handle(new ContainerEvent(c.getContainerId(), ContainerEventType.CONTAINER_RESOURCES_CLEANEDUP));
}
Also used : Path(org.apache.hadoop.fs.Path) ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) Collection(java.util.Collection) ResourceReleaseEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ResourceReleaseEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LocalResourceVisibility(org.apache.hadoop.yarn.api.records.LocalResourceVisibility)

Example 70 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container in project hadoop by apache.

the class ResourceLocalizationService method handleContainerResourcesLocalized.

/**
   * Once a container's resources are localized, kill the corresponding
   * {@link ContainerLocalizer}
   */
private void handleContainerResourcesLocalized(ContainerLocalizationEvent event) {
    Container c = event.getContainer();
    String locId = c.getContainerId().toString();
    localizerTracker.endContainerLocalization(locId);
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)

Aggregations

Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)109 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)55 Test (org.junit.Test)43 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)33 Path (org.apache.hadoop.fs.Path)31 ArrayList (java.util.ArrayList)29 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)29 HashMap (java.util.HashMap)27 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)27 Configuration (org.apache.hadoop.conf.Configuration)24 IOException (java.io.IOException)20 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)18 ContainerEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent)17 LocalDirsHandlerService (org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService)16 Collection (java.util.Collection)14 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)14 LocalResourceVisibility (org.apache.hadoop.yarn.api.records.LocalResourceVisibility)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)13 ApplicationEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationEvent)13