Search in sources :

Example 1 with DockerInspectCommand

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerInspectCommand 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

PrivilegedOperation (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation)1 PrivilegedOperationException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException)1 DockerInspectCommand (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerInspectCommand)1 ContainerExecutionException (org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException)1