Search in sources :

Example 16 with PrivilegedOperationException

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException 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 17 with PrivilegedOperationException

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException 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)

Example 18 with PrivilegedOperationException

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException in project hadoop by apache.

the class TestCGroupsHandlerImpl method testMountController.

@Test
public void testMountController() {
    CGroupsHandler cGroupsHandler = null;
    //Since we enabled (deferred) cgroup controller mounting, no interactions
    //should have occurred, with this mock
    verifyZeroInteractions(privilegedOperationExecutorMock);
    try {
        cGroupsHandler = new CGroupsHandlerImpl(conf, privilegedOperationExecutorMock);
        PrivilegedOperation expectedOp = new PrivilegedOperation(PrivilegedOperation.OperationType.MOUNT_CGROUPS);
        //This is expected to be of the form :
        //net_cls=<mount_path>/net_cls
        StringBuffer controllerKV = new StringBuffer(controller.getName()).append('=').append(tmpPath).append('/').append(controller.getName());
        expectedOp.appendArgs(hierarchy, controllerKV.toString());
        cGroupsHandler.initializeCGroupController(controller);
        try {
            ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass(PrivilegedOperation.class);
            verify(privilegedOperationExecutorMock).executePrivilegedOperation(opCaptor.capture(), eq(false));
            //we'll explicitly capture and assert that the
            //captured op and the expected op are identical.
            Assert.assertEquals(expectedOp, opCaptor.getValue());
            verifyNoMoreInteractions(privilegedOperationExecutorMock);
            //Try mounting the same controller again - this should be a no-op
            cGroupsHandler.initializeCGroupController(controller);
            verifyNoMoreInteractions(privilegedOperationExecutorMock);
        } catch (PrivilegedOperationException e) {
            LOG.error("Caught exception: " + e);
            Assert.assertTrue("Unexpected PrivilegedOperationException from mock!", false);
        }
    } catch (ResourceHandlerException e) {
        LOG.error("Caught exception: " + e);
        Assert.assertTrue("Unexpected ResourceHandler Exception!", false);
    }
}
Also used : PrivilegedOperationException(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException) PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) Test(org.junit.Test)

Aggregations

PrivilegedOperation (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation)18 PrivilegedOperationException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException)18 ContainerExecutionException (org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException)7 PrivilegedOperationExecutor (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor)6 ArrayList (java.util.ArrayList)5 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)5 IOException (java.io.IOException)4 Configuration (org.apache.hadoop.conf.Configuration)4 Path (org.apache.hadoop.fs.Path)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)4 List (java.util.List)3 File (java.io.File)2 ResourceHandlerException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerException)2 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 AccessControlList (org.apache.hadoop.security.authorize.AccessControlList)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 ContainerExecutor (org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor)1 ContainerDiagnosticsUpdateEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerDiagnosticsUpdateEvent)1 DefaultLinuxContainerRuntime (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime)1