Search in sources :

Example 36 with PrivilegedOperation

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

the class TestCGroupsMemoryResourceHandlerImpl method testBootstrap.

@Test
public void testBootstrap() throws Exception {
    Configuration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false);
    conf.setBoolean(YarnConfiguration.NM_VMEM_CHECK_ENABLED, false);
    List<PrivilegedOperation> ret = cGroupsMemoryResourceHandler.bootstrap(conf);
    verify(mockCGroupsHandler, times(1)).initializeCGroupController(CGroupsHandler.CGroupController.MEMORY);
    Assert.assertNull(ret);
    Assert.assertEquals("Default swappiness value incorrect", 0, cGroupsMemoryResourceHandler.getSwappiness());
    conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, true);
    try {
        cGroupsMemoryResourceHandler.bootstrap(conf);
        Assert.fail("Pmem check should not be allowed to run with cgroups");
    } catch (ResourceHandlerException re) {
    // do nothing
    }
    conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false);
    conf.setBoolean(YarnConfiguration.NM_VMEM_CHECK_ENABLED, true);
    try {
        cGroupsMemoryResourceHandler.bootstrap(conf);
        Assert.fail("Vmem check should not be allowed to run with cgroups");
    } catch (ResourceHandlerException re) {
    // do nothing
    }
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) Test(org.junit.Test)

Example 37 with PrivilegedOperation

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

the class TestCGroupsMemoryResourceHandlerImpl method testPreStart.

@Test
public void testPreStart() throws Exception {
    Configuration conf = new Configuration();
    conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false);
    conf.setBoolean(YarnConfiguration.NM_VMEM_CHECK_ENABLED, false);
    cGroupsMemoryResourceHandler.bootstrap(conf);
    String id = "container_01_01";
    String path = "test-path/" + id;
    ContainerId mockContainerId = mock(ContainerId.class);
    when(mockContainerId.toString()).thenReturn(id);
    Container mockContainer = mock(Container.class);
    when(mockContainer.getContainerId()).thenReturn(mockContainerId);
    when(mockCGroupsHandler.getPathForCGroupTasks(CGroupsHandler.CGroupController.MEMORY, id)).thenReturn(path);
    int memory = 1024;
    when(mockContainer.getResource()).thenReturn(Resource.newInstance(memory, 1));
    List<PrivilegedOperation> ret = cGroupsMemoryResourceHandler.preStart(mockContainer);
    verify(mockCGroupsHandler, times(1)).createCGroup(CGroupsHandler.CGroupController.MEMORY, id);
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id, CGroupsHandler.CGROUP_PARAM_MEMORY_HARD_LIMIT_BYTES, String.valueOf(memory) + "M");
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id, CGroupsHandler.CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES, String.valueOf((int) (memory * 0.9)) + "M");
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id, CGroupsHandler.CGROUP_PARAM_MEMORY_SWAPPINESS, String.valueOf(0));
    Assert.assertNotNull(ret);
    Assert.assertEquals(1, ret.size());
    PrivilegedOperation op = ret.get(0);
    Assert.assertEquals(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP, op.getOperationType());
    List<String> args = op.getArguments();
    Assert.assertEquals(1, args.size());
    Assert.assertEquals(PrivilegedOperation.CGROUP_ARG_PREFIX + path, args.get(0));
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) Test(org.junit.Test)

Example 38 with PrivilegedOperation

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

the class TestTrafficControlBandwidthHandlerImpl method testPreStart.

private void testPreStart(TrafficController trafficControllerSpy, TrafficControlBandwidthHandlerImpl handlerImpl) throws ResourceHandlerException {
    //This is not the cleanest of solutions - but since we are testing the
    //preStart/postComplete lifecycle, we don't have a different way of
    //handling this - we don't keep track of the number of invocations by
    //a class we are not testing here (TrafficController)
    //So, we'll reset this mock. This is not a problem with other mocks.
    reset(privilegedOperationExecutorMock);
    doReturn(TEST_CLASSID).when(trafficControllerSpy).getNextClassId();
    doReturn(TEST_CLASSID_STR).when(trafficControllerSpy).getStringForNetClsClassId(TEST_CLASSID);
    when(cGroupsHandlerMock.getPathForCGroupTasks(CGroupsHandler.CGroupController.NET_CLS, TEST_CONTAINER_ID_STR)).thenReturn(TEST_TASKS_FILE);
    List<PrivilegedOperation> ops = handlerImpl.preStart(containerMock);
    //Ensure that cgroups is created and updated as expected
    verify(cGroupsHandlerMock).createCGroup(eq(CGroupsHandler.CGroupController.NET_CLS), eq(TEST_CONTAINER_ID_STR));
    verify(cGroupsHandlerMock).updateCGroupParam(eq(CGroupsHandler.CGroupController.NET_CLS), eq(TEST_CONTAINER_ID_STR), eq(CGroupsHandler.CGROUP_PARAM_CLASSID), eq(TEST_CLASSID_STR));
    //Now check the privileged operations being returned
    //We expect two operations - one for adding pid to tasks file and another
    //for a tc modify operation
    Assert.assertEquals(2, ops.size());
    //Verify that the add pid op is correct
    PrivilegedOperation addPidOp = ops.get(0);
    String expectedAddPidOpArg = PrivilegedOperation.CGROUP_ARG_PREFIX + TEST_TASKS_FILE;
    List<String> addPidOpArgs = addPidOp.getArguments();
    Assert.assertEquals(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP, addPidOp.getOperationType());
    Assert.assertEquals(1, addPidOpArgs.size());
    Assert.assertEquals(expectedAddPidOpArg, addPidOpArgs.get(0));
    //Verify that that tc modify op is correct
    PrivilegedOperation tcModifyOp = ops.get(1);
    List<String> tcModifyOpArgs = tcModifyOp.getArguments();
    Assert.assertEquals(PrivilegedOperation.OperationType.TC_MODIFY_STATE, tcModifyOp.getOperationType());
    Assert.assertEquals(1, tcModifyOpArgs.size());
    //verify that the tc command file exists
    Assert.assertTrue(new File(tcModifyOpArgs.get(0)).exists());
}
Also used : PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) File(java.io.File)

Example 39 with PrivilegedOperation

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

the class TestTrafficController method testContainerOperations.

@Test
public void testContainerOperations() {
    conf.setBoolean(YarnConfiguration.NM_RECOVERY_ENABLED, false);
    TrafficController trafficController = new TrafficController(conf, privilegedOperationExecutorMock);
    try {
        trafficController.bootstrap(DEVICE, ROOT_BANDWIDTH_MBIT, YARN_BANDWIDTH_MBIT);
        int classId = trafficController.getNextClassId();
        Assert.assertTrue(classId >= MIN_CONTAINER_CLASS_ID);
        Assert.assertEquals(String.format(FORMAT_CONTAINER_CLASS_STR, classId), trafficController.getStringForNetClsClassId(classId));
        //Verify that the operation is setup correctly with strictMode = false
        TrafficController.BatchBuilder builder = trafficController.new BatchBuilder(PrivilegedOperation.OperationType.TC_MODIFY_STATE).addContainerClass(classId, CONTAINER_BANDWIDTH_MBIT, false);
        PrivilegedOperation addClassOp = builder.commitBatchToTempFile();
        String expectedAddClassCmd = String.format(FORMAT_ADD_CONTAINER_CLASS_TO_DEVICE, classId, YARN_BANDWIDTH_MBIT);
        verifyTrafficControlOperation(addClassOp, PrivilegedOperation.OperationType.TC_MODIFY_STATE, Arrays.asList(expectedAddClassCmd));
        //Verify that the operation is setup correctly with strictMode = true
        TrafficController.BatchBuilder strictModeBuilder = trafficController.new BatchBuilder(PrivilegedOperation.OperationType.TC_MODIFY_STATE).addContainerClass(classId, CONTAINER_BANDWIDTH_MBIT, true);
        PrivilegedOperation addClassStrictModeOp = strictModeBuilder.commitBatchToTempFile();
        String expectedAddClassStrictModeCmd = String.format(FORMAT_ADD_CONTAINER_CLASS_TO_DEVICE, classId, CONTAINER_BANDWIDTH_MBIT);
        verifyTrafficControlOperation(addClassStrictModeOp, PrivilegedOperation.OperationType.TC_MODIFY_STATE, Arrays.asList(expectedAddClassStrictModeCmd));
        TrafficController.BatchBuilder deleteBuilder = trafficController.new BatchBuilder(PrivilegedOperation.OperationType.TC_MODIFY_STATE).deleteContainerClass(classId);
        PrivilegedOperation deleteClassOp = deleteBuilder.commitBatchToTempFile();
        String expectedDeleteClassCmd = String.format(FORAMT_DELETE_CONTAINER_CLASS_FROM_DEVICE, classId);
        verifyTrafficControlOperation(deleteClassOp, PrivilegedOperation.OperationType.TC_MODIFY_STATE, Arrays.asList(expectedDeleteClassCmd));
    } catch (ResourceHandlerException | IOException e) {
        LOG.error("Unexpected exception: " + e);
        Assert.fail("Caught unexpected exception: " + e.getClass().getSimpleName());
    }
}
Also used : PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) IOException(java.io.IOException) Test(org.junit.Test)

Example 40 with PrivilegedOperation

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

the class TestCGroupsBlkioResourceHandlerImpl method testPreStart.

@Test
public void testPreStart() throws Exception {
    String id = "container_01_01";
    String path = "test-path/" + id;
    ContainerId mockContainerId = mock(ContainerId.class);
    when(mockContainerId.toString()).thenReturn(id);
    Container mockContainer = mock(Container.class);
    when(mockContainer.getContainerId()).thenReturn(mockContainerId);
    when(mockCGroupsHandler.getPathForCGroupTasks(CGroupsHandler.CGroupController.BLKIO, id)).thenReturn(path);
    List<PrivilegedOperation> ret = cGroupsBlkioResourceHandlerImpl.preStart(mockContainer);
    verify(mockCGroupsHandler, times(1)).createCGroup(CGroupsHandler.CGroupController.BLKIO, id);
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.BLKIO, id, CGroupsHandler.CGROUP_PARAM_BLKIO_WEIGHT, CGroupsBlkioResourceHandlerImpl.DEFAULT_WEIGHT);
    Assert.assertNotNull(ret);
    Assert.assertEquals(1, ret.size());
    PrivilegedOperation op = ret.get(0);
    Assert.assertEquals(PrivilegedOperation.OperationType.ADD_PID_TO_CGROUP, op.getOperationType());
    List<String> args = op.getArguments();
    Assert.assertEquals(1, args.size());
    Assert.assertEquals(PrivilegedOperation.CGROUP_ARG_PREFIX + path, args.get(0));
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) 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)43 Test (org.junit.Test)19 PrivilegedOperationException (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException)18 Configuration (org.apache.hadoop.conf.Configuration)11 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)11 ArrayList (java.util.ArrayList)9 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)9 ContainerExecutionException (org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException)9 PrivilegedOperationExecutor (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor)6 IOException (java.io.IOException)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)5 File (java.io.File)4 Path (org.apache.hadoop.fs.Path)4 List (java.util.List)3 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 Resource (org.apache.hadoop.yarn.api.records.Resource)1 ContainerExecutor (org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor)1