CGroupsMemoryResourceHandlerImpl implements MemoryResourceHandler { @Override public List<PrivilegedOperation> bootstrap(Configuration conf) throws ResourceHandlerException { this.cGroupsHandler.initializeCGroupController(MEMORY); enforce = conf.getBoolean( YarnConfiguration.NM_MEMORY_RESOURCE_ENFORCED, YarnConfiguration.DEFAULT_NM_MEMORY_RESOURCE_ENFORCED); swappiness = conf .getInt(YarnConfiguration.NM_MEMORY_RESOURCE_CGROUPS_SWAPPINESS, YarnConfiguration.DEFAULT_NM_MEMORY_RESOURCE_CGROUPS_SWAPPINESS); if (swappiness < 0 || swappiness > 100) { throw new ResourceHandlerException( "Illegal value '" + swappiness + "' for " + YarnConfiguration.NM_MEMORY_RESOURCE_CGROUPS_SWAPPINESS + ". Value must be between 0 and 100."); } float softLimitPerc = conf.getFloat( YarnConfiguration.NM_MEMORY_RESOURCE_CGROUPS_SOFT_LIMIT_PERCENTAGE, YarnConfiguration. DEFAULT_NM_MEMORY_RESOURCE_CGROUPS_SOFT_LIMIT_PERCENTAGE); softLimit = softLimitPerc / 100.0f; if (softLimitPerc < 0.0f || softLimitPerc > 100.0f) { throw new ResourceHandlerException( "Illegal value '" + softLimitPerc + "' " + YarnConfiguration. NM_MEMORY_RESOURCE_CGROUPS_SOFT_LIMIT_PERCENTAGE + ". Value must be between 0 and 100."); } return null; } CGroupsMemoryResourceHandlerImpl(CGroupsHandler cGroupsHandler); @Override List<PrivilegedOperation> bootstrap(Configuration conf); @Override List<PrivilegedOperation> reacquireContainer(ContainerId containerId); @Override List<PrivilegedOperation> updateContainer(Container container); @Override List<PrivilegedOperation> preStart(Container container); @Override List<PrivilegedOperation> postComplete(ContainerId containerId); @Override List<PrivilegedOperation> teardown(); @Override String toString();  }
@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); } catch(ResourceHandlerException re) { Assert.fail("Pmem check should be allowed to run with cgroups"); } conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false); conf.setBoolean(YarnConfiguration.NM_VMEM_CHECK_ENABLED, true); try { cGroupsMemoryResourceHandler.bootstrap(conf); } catch(ResourceHandlerException re) { Assert.fail("Vmem check should be allowed to run with cgroups"); } }