Search in sources :

Example 96 with Container

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

the class BaseContainerManagerTest method waitForNMContainerState.

public static void waitForNMContainerState(ContainerManagerImpl containerManager, ContainerId containerID, List<org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState> finalStates, int timeOutMax) throws InterruptedException, YarnException, IOException {
    Container container = null;
    org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState currentState = null;
    int timeoutSecs = 0;
    do {
        Thread.sleep(2000);
        container = containerManager.getContext().getContainers().get(containerID);
        if (container != null) {
            currentState = container.getContainerState();
        }
        if (currentState != null) {
            LOG.info("Waiting for NM container to get into one of the following " + "states: " + finalStates + ". Current state is " + currentState);
        }
        timeoutSecs += 2;
    } while (!finalStates.contains(currentState) && timeoutSecs++ < timeOutMax);
    LOG.info("Container state is " + currentState);
    Assert.assertTrue("ContainerState is not correct (timedout)", finalStates.contains(currentState));
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)

Example 97 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container 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 98 with Container

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container 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)

Example 99 with Container

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

the class TestCGroupsCpuResourceHandlerImpl 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.CPU, id)).thenReturn(path);
    when(mockContainer.getResource()).thenReturn(Resource.newInstance(1024, 2));
    List<PrivilegedOperation> ret = cGroupsCpuResourceHandler.preStart(mockContainer);
    verify(mockCGroupsHandler, times(1)).createCGroup(CGroupsHandler.CGroupController.CPU, id);
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.CPU, id, CGroupsHandler.CGROUP_CPU_SHARES, String.valueOf(CGroupsCpuResourceHandlerImpl.CPU_DEFAULT_WEIGHT * 2));
    // don't set quota or period
    verify(mockCGroupsHandler, never()).updateCGroupParam(eq(CGroupsHandler.CGroupController.CPU), eq(id), eq(CGroupsHandler.CGROUP_CPU_PERIOD_US), anyString());
    verify(mockCGroupsHandler, never()).updateCGroupParam(eq(CGroupsHandler.CGroupController.CPU), eq(id), eq(CGroupsHandler.CGROUP_CPU_QUOTA_US), anyString());
    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)

Example 100 with Container

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

the class TestCGroupsCpuResourceHandlerImpl method testPreStartStrictUsage.

@Test
public void testPreStartStrictUsage() 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.CPU, id)).thenReturn(path);
    when(mockContainer.getResource()).thenReturn(Resource.newInstance(1024, 1));
    Configuration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE, true);
    cGroupsCpuResourceHandler.bootstrap(plugin, conf);
    int defaultVCores = 8;
    float share = (float) numProcessors / (float) defaultVCores;
    List<PrivilegedOperation> ret = cGroupsCpuResourceHandler.preStart(mockContainer);
    verify(mockCGroupsHandler, times(1)).createCGroup(CGroupsHandler.CGroupController.CPU, id);
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.CPU, id, CGroupsHandler.CGROUP_CPU_SHARES, String.valueOf(CGroupsCpuResourceHandlerImpl.CPU_DEFAULT_WEIGHT));
    // set quota and period
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.CPU, id, CGroupsHandler.CGROUP_CPU_PERIOD_US, String.valueOf(CGroupsCpuResourceHandlerImpl.MAX_QUOTA_US));
    verify(mockCGroupsHandler, times(1)).updateCGroupParam(CGroupsHandler.CGroupController.CPU, id, CGroupsHandler.CGROUP_CPU_QUOTA_US, String.valueOf((int) (CGroupsCpuResourceHandlerImpl.MAX_QUOTA_US * share)));
    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) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) PrivilegedOperation(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation) Test(org.junit.Test)

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