Search in sources :

Example 81 with Container

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

the class DelegatingLinuxContainerRuntime method reapContainer.

@Override
public void reapContainer(ContainerRuntimeContext ctx) throws ContainerExecutionException {
    Container container = ctx.getContainer();
    LinuxContainerRuntime runtime = pickContainerRuntime(container);
    runtime.reapContainer(ctx);
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)

Example 82 with Container

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

the class DelegatingLinuxContainerRuntime method launchContainer.

@Override
public void launchContainer(ContainerRuntimeContext ctx) throws ContainerExecutionException {
    Container container = ctx.getContainer();
    LinuxContainerRuntime runtime = pickContainerRuntime(container);
    runtime.launchContainer(ctx);
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)

Example 83 with Container

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

the class DelegatingLinuxContainerRuntime method signalContainer.

@Override
public void signalContainer(ContainerRuntimeContext ctx) throws ContainerExecutionException {
    Container container = ctx.getContainer();
    LinuxContainerRuntime runtime = pickContainerRuntime(container);
    runtime.signalContainer(ctx);
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)

Example 84 with Container

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

the class DockerLinuxContainerRuntime method signalContainer.

@Override
public void signalContainer(ContainerRuntimeContext ctx) throws ContainerExecutionException {
    Container container = ctx.getContainer();
    ContainerExecutor.Signal signal = ctx.getExecutionAttribute(SIGNAL);
    PrivilegedOperation privOp = null;
    // Handle liveliness checks, send null signal to pid
    if (ContainerExecutor.Signal.NULL.equals(signal)) {
        privOp = new PrivilegedOperation(PrivilegedOperation.OperationType.SIGNAL_CONTAINER);
        privOp.appendArgs(ctx.getExecutionAttribute(RUN_AS_USER), ctx.getExecutionAttribute(USER), Integer.toString(PrivilegedOperation.RunAsUserCommand.SIGNAL_CONTAINER.getValue()), ctx.getExecutionAttribute(PID), Integer.toString(ctx.getExecutionAttribute(SIGNAL).getValue()));
    // All other signals handled as docker stop
    } else {
        String containerId = ctx.getContainer().getContainerId().toString();
        DockerStopCommand stopCommand = new DockerStopCommand(containerId);
        String commandFile = dockerClient.writeCommandToTempFile(stopCommand, containerId);
        privOp = new PrivilegedOperation(PrivilegedOperation.OperationType.RUN_DOCKER_CMD);
        privOp.appendArgs(commandFile);
    }
    //Some failures here are acceptable. Let the calling executor decide.
    privOp.disableFailureLogging();
    try {
        privilegedOperationExecutor.executePrivilegedOperation(null, privOp, null, container.getLaunchContext().getEnvironment(), false, false);
    } catch (PrivilegedOperationException e) {
        throw new ContainerExecutionException("Signal container failed", e.getExitCode(), e.getOutput(), e.getErrorOutput());
    }
}
Also used : ContainerExecutor(org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerExecutionException(org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException) PrivilegedOperationException(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException) PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) DockerStopCommand(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerStopCommand)

Example 85 with Container

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

the class AppLogAggregatorImpl method uploadLogsForContainers.

private void uploadLogsForContainers(boolean appFinished) {
    if (this.logAggregationDisabled) {
        return;
    }
    if (UserGroupInformation.isSecurityEnabled()) {
        Credentials systemCredentials = context.getSystemCredentialsForApps().get(appId);
        if (systemCredentials != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding new framework-token for " + appId + " for log-aggregation: " + systemCredentials.getAllTokens() + "; userUgi=" + userUgi);
            }
            // this will replace old token
            userUgi.addCredentials(systemCredentials);
        }
    }
    // Create a set of Containers whose logs will be uploaded in this cycle.
    // It includes:
    // a) all containers in pendingContainers: those containers are finished
    //    and satisfy the ContainerLogAggregationPolicy.
    // b) some set of running containers: For all the Running containers,
    //    we use exitCode of 0 to find those which satisfy the
    //    ContainerLogAggregationPolicy.
    Set<ContainerId> pendingContainerInThisCycle = new HashSet<ContainerId>();
    this.pendingContainers.drainTo(pendingContainerInThisCycle);
    Set<ContainerId> finishedContainers = new HashSet<ContainerId>(pendingContainerInThisCycle);
    if (this.context.getApplications().get(this.appId) != null) {
        for (Container container : this.context.getApplications().get(this.appId).getContainers().values()) {
            ContainerType containerType = container.getContainerTokenIdentifier().getContainerType();
            if (shouldUploadLogs(new ContainerLogContext(container.getContainerId(), containerType, 0))) {
                pendingContainerInThisCycle.add(container.getContainerId());
            }
        }
    }
    LogWriter writer = null;
    String diagnosticMessage = "";
    boolean logAggregationSucceedInThisCycle = true;
    try {
        if (pendingContainerInThisCycle.isEmpty()) {
            return;
        }
        logAggregationTimes++;
        try {
            writer = createLogWriter();
            // Write ACLs once when the writer is created.
            writer.writeApplicationACLs(appAcls);
            writer.writeApplicationOwner(this.userUgi.getShortUserName());
        } catch (IOException e1) {
            logAggregationSucceedInThisCycle = false;
            LOG.error("Cannot create writer for app " + this.applicationId + ". Skip log upload this time. ", e1);
            return;
        }
        boolean uploadedLogsInThisCycle = false;
        for (ContainerId container : pendingContainerInThisCycle) {
            ContainerLogAggregator aggregator = null;
            if (containerLogAggregators.containsKey(container)) {
                aggregator = containerLogAggregators.get(container);
            } else {
                aggregator = new ContainerLogAggregator(container);
                containerLogAggregators.put(container, aggregator);
            }
            Set<Path> uploadedFilePathsInThisCycle = aggregator.doContainerLogAggregation(writer, appFinished, finishedContainers.contains(container));
            if (uploadedFilePathsInThisCycle.size() > 0) {
                uploadedLogsInThisCycle = true;
                this.delService.delete(this.userUgi.getShortUserName(), null, uploadedFilePathsInThisCycle.toArray(new Path[uploadedFilePathsInThisCycle.size()]));
            }
            // remove it from containerLogAggregators.
            if (finishedContainers.contains(container)) {
                containerLogAggregators.remove(container);
            }
        }
        // is smaller than the configured NM log aggregation retention size.
        if (uploadedLogsInThisCycle && logAggregationInRolling) {
            cleanOldLogs();
            cleanupOldLogTimes++;
        }
        if (writer != null) {
            writer.close();
            writer = null;
        }
        long currentTime = System.currentTimeMillis();
        final Path renamedPath = this.rollingMonitorInterval <= 0 ? remoteNodeLogFileForApp : new Path(remoteNodeLogFileForApp.getParent(), remoteNodeLogFileForApp.getName() + "_" + currentTime);
        final boolean rename = uploadedLogsInThisCycle;
        try {
            userUgi.doAs(new PrivilegedExceptionAction<Object>() {

                @Override
                public Object run() throws Exception {
                    FileSystem remoteFS = remoteNodeLogFileForApp.getFileSystem(conf);
                    if (rename) {
                        remoteFS.rename(remoteNodeTmpLogFileForApp, renamedPath);
                    } else {
                        remoteFS.delete(remoteNodeTmpLogFileForApp, false);
                    }
                    return null;
                }
            });
            diagnosticMessage = "Log uploaded successfully for Application: " + appId + " in NodeManager: " + LogAggregationUtils.getNodeString(nodeId) + " at " + Times.format(currentTime) + "\n";
        } catch (Exception e) {
            LOG.error("Failed to move temporary log file to final location: [" + remoteNodeTmpLogFileForApp + "] to [" + renamedPath + "]", e);
            diagnosticMessage = "Log uploaded failed for Application: " + appId + " in NodeManager: " + LogAggregationUtils.getNodeString(nodeId) + " at " + Times.format(currentTime) + "\n";
            renameTemporaryLogFileFailed = true;
            logAggregationSucceedInThisCycle = false;
        }
    } finally {
        LogAggregationStatus logAggregationStatus = logAggregationSucceedInThisCycle ? LogAggregationStatus.RUNNING : LogAggregationStatus.RUNNING_WITH_FAILURE;
        sendLogAggregationReport(logAggregationStatus, diagnosticMessage);
        if (appFinished) {
            // If the app is finished, one extra final report with log aggregation
            // status SUCCEEDED/FAILED will be sent to RM to inform the RM
            // that the log aggregation in this NM is completed.
            LogAggregationStatus finalLogAggregationStatus = renameTemporaryLogFileFailed || !logAggregationSucceedInThisCycle ? LogAggregationStatus.FAILED : LogAggregationStatus.SUCCEEDED;
            sendLogAggregationReport(finalLogAggregationStatus, "");
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ContainerType(org.apache.hadoop.yarn.server.api.ContainerType) ContainerLogContext(org.apache.hadoop.yarn.server.api.ContainerLogContext) IOException(java.io.IOException) IOException(java.io.IOException) UnsupportedFileSystemException(org.apache.hadoop.fs.UnsupportedFileSystemException) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) LogWriter(org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogWriter) FileSystem(org.apache.hadoop.fs.FileSystem) LogAggregationStatus(org.apache.hadoop.yarn.api.records.LogAggregationStatus) Credentials(org.apache.hadoop.security.Credentials) HashSet(java.util.HashSet)

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