Search in sources :

Example 61 with Container

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

the class LinuxContainerExecutor method signalContainer.

@Override
public boolean signalContainer(ContainerSignalContext ctx) throws IOException {
    Container container = ctx.getContainer();
    String user = ctx.getUser();
    String pid = ctx.getPid();
    Signal signal = ctx.getSignal();
    verifyUsernamePattern(user);
    String runAsUser = getRunAsUser(user);
    ContainerRuntimeContext runtimeContext = new ContainerRuntimeContext.Builder(container).setExecutionAttribute(RUN_AS_USER, runAsUser).setExecutionAttribute(USER, user).setExecutionAttribute(PID, pid).setExecutionAttribute(SIGNAL, signal).build();
    try {
        linuxContainerRuntime.signalContainer(runtimeContext);
    } catch (ContainerExecutionException e) {
        int retCode = e.getExitCode();
        if (retCode == PrivilegedOperation.ResultCode.INVALID_CONTAINER_PID.getValue()) {
            return false;
        }
        LOG.warn("Error in signalling container " + pid + " with " + signal + "; exit = " + retCode, e);
        logOutput(e.getOutput());
        throw new IOException("Problem signalling container " + pid + " with " + signal + "; output: " + e.getOutput() + " and exitCode: " + retCode, e);
    }
    return true;
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerExecutionException(org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException) IOException(java.io.IOException) ContainerRuntimeContext(org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeContext)

Example 62 with Container

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

the class NodeStatusUpdaterImpl method removeOrTrackCompletedContainersFromContext.

@VisibleForTesting
@Private
public void removeOrTrackCompletedContainersFromContext(List<ContainerId> containerIds) throws IOException {
    Set<ContainerId> removedContainers = new HashSet<ContainerId>();
    Set<ContainerId> removedNullContainers = new HashSet<ContainerId>();
    pendingContainersToRemove.addAll(containerIds);
    Iterator<ContainerId> iter = pendingContainersToRemove.iterator();
    while (iter.hasNext()) {
        ContainerId containerId = iter.next();
        // remove the container only if the container is at DONE state
        Container nmContainer = context.getContainers().get(containerId);
        if (nmContainer == null) {
            iter.remove();
            removedNullContainers.add(containerId);
        } else if (nmContainer.getContainerState().equals(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState.DONE)) {
            context.getContainers().remove(containerId);
            removedContainers.add(containerId);
            iter.remove();
        }
    }
    if (!removedContainers.isEmpty()) {
        LOG.info("Removed completed containers from NM context: " + removedContainers);
    }
    pendingCompletedContainers.clear();
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 63 with Container

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

the class ContainerManagerImpl method internalSignalToContainer.

@SuppressWarnings("unchecked")
private void internalSignalToContainer(SignalContainerRequest request, String sentBy) {
    ContainerId containerId = request.getContainerId();
    Container container = this.context.getContainers().get(containerId);
    if (container != null) {
        LOG.info(containerId + " signal request " + request.getCommand() + " by " + sentBy);
        this.dispatcher.getEventHandler().handle(new SignalContainersLauncherEvent(container, request.getCommand()));
    } else {
        LOG.info("Container " + containerId + " no longer exists");
    }
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) SignalContainersLauncherEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.SignalContainersLauncherEvent)

Example 64 with Container

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

the class ContainerManagerImpl method stopContainers.

/**
   * 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 {
            Container container = this.context.getContainers().get(id);
            authorizeGetAndStopContainerRequest(id, container, true, identifier);
            stopContainerInternal(id);
            succeededRequests.add(id);
        } catch (YarnException e) {
            failedRequests.put(id, SerializedException.newInstance(e));
        }
    }
    return StopContainersResponse.newInstance(succeededRequests, failedRequests);
}
Also used : NMTokenIdentifier(org.apache.hadoop.yarn.security.NMTokenIdentifier) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) HashMap(java.util.HashMap) SerializedException(org.apache.hadoop.yarn.api.records.SerializedException) ArrayList(java.util.ArrayList) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 65 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)

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