Search in sources :

Example 16 with ContainerExecutionException

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException in project hadoop by apache.

the class DockerLinuxContainerRuntime method initialize.

@Override
public void initialize(Configuration conf) throws ContainerExecutionException {
    this.conf = conf;
    dockerClient = new DockerClient(conf);
    allowedNetworks.clear();
    allowedNetworks.addAll(Arrays.asList(conf.getTrimmedStrings(YarnConfiguration.NM_DOCKER_ALLOWED_CONTAINER_NETWORKS, YarnConfiguration.DEFAULT_NM_DOCKER_ALLOWED_CONTAINER_NETWORKS)));
    defaultNetwork = conf.getTrimmed(YarnConfiguration.NM_DOCKER_DEFAULT_CONTAINER_NETWORK, YarnConfiguration.DEFAULT_NM_DOCKER_DEFAULT_CONTAINER_NETWORK);
    if (!allowedNetworks.contains(defaultNetwork)) {
        String message = "Default network: " + defaultNetwork + " is not in the set of allowed networks: " + allowedNetworks;
        if (LOG.isWarnEnabled()) {
            LOG.warn(message + ". Please check " + "configuration");
        }
        throw new ContainerExecutionException(message);
    }
    privilegedContainersAcl = new AccessControlList(conf.getTrimmed(YarnConfiguration.NM_DOCKER_PRIVILEGED_CONTAINERS_ACL, YarnConfiguration.DEFAULT_NM_DOCKER_PRIVILEGED_CONTAINERS_ACL));
}
Also used : AccessControlList(org.apache.hadoop.security.authorize.AccessControlList) ContainerExecutionException(org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException) DockerClient(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerClient)

Example 17 with ContainerExecutionException

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException in project hadoop by apache.

the class DockerLinuxContainerRuntime method getIpAndHost.

// ipAndHost[0] contains comma separated list of IPs
// ipAndHost[1] contains the hostname.
@Override
public String[] getIpAndHost(Container container) {
    String containerId = container.getContainerId().toString();
    DockerInspectCommand inspectCommand = new DockerInspectCommand(containerId).getIpAndHost();
    try {
        String commandFile = dockerClient.writeCommandToTempFile(inspectCommand, containerId);
        PrivilegedOperation privOp = new PrivilegedOperation(PrivilegedOperation.OperationType.RUN_DOCKER_CMD);
        privOp.appendArgs(commandFile);
        String output = privilegedOperationExecutor.executePrivilegedOperation(null, privOp, null, container.getLaunchContext().getEnvironment(), true, false);
        LOG.info("Docker inspect output for " + containerId + ": " + output);
        int index = output.lastIndexOf(',');
        if (index == -1) {
            LOG.error("Incorrect format for ip and host");
            return null;
        }
        String ips = output.substring(0, index).trim();
        String host = output.substring(index + 1).trim();
        String[] ipAndHost = new String[2];
        ipAndHost[0] = ips;
        ipAndHost[1] = host;
        return ipAndHost;
    } catch (ContainerExecutionException e) {
        LOG.error("Error when writing command to temp file", e);
    } catch (PrivilegedOperationException e) {
        LOG.error("Error when executing command.", e);
    }
    return null;
}
Also used : DockerInspectCommand(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerInspectCommand) 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)

Aggregations

ContainerExecutionException (org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException)17 PrivilegedOperation (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation)9 IOException (java.io.IOException)8 PrivilegedOperationException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException)7 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)6 List (java.util.List)4 ContainerRuntimeContext (org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeContext)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Path (org.apache.hadoop.fs.Path)2 AccessControlList (org.apache.hadoop.security.authorize.AccessControlList)2 PrivilegedOperationExecutor (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor)2 ResourceHandlerException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerException)2 Test (org.junit.Test)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1