CGroupsHandlerImpl implements CGroupsHandler { @VisibleForTesting static Map<CGroupController, String> initializeControllerPathsFromMtab( String mtab, String cGroupPrefix) throws ResourceHandlerException { try { Map<String, List<String>> parsedMtab = parseMtab(mtab); Map<CGroupController, String> ret = new HashMap<>(); for (CGroupController controller : CGroupController.values()) { String name = controller.getName(); String controllerPath = findControllerInMtab(name, parsedMtab); if (controllerPath != null) { File f = new File(controllerPath + "/" + cGroupPrefix); if (FileUtil.canWrite(f)) { ret.put(controller, controllerPath); } else { String error = new StringBuffer("Mount point Based on mtab file: ") .append(mtab) .append(". Controller mount point not writable for: ") .append(name).toString(); LOG.error(error); throw new ResourceHandlerException(error); } } else { LOG.warn("Controller not mounted but automount disabled: " + name); } } return ret; } catch (IOException e) { LOG.warn("Failed to initialize controller paths! Exception: " + e); throw new ResourceHandlerException( "Failed to initialize controller paths!"); } } CGroupsHandlerImpl(Configuration conf, PrivilegedOperationExecutor
      privilegedOperationExecutor); @Override void mountCGroupController(CGroupController controller); @Override String getRelativePathForCGroup(String cGroupId); @Override String getPathForCGroup(CGroupController controller, String cGroupId); @Override String getPathForCGroupTasks(CGroupController controller,
      String cGroupId); @Override String getPathForCGroupParam(CGroupController controller,
      String cGroupId, String param); @Override String createCGroup(CGroupController controller, String cGroupId); @Override void deleteCGroup(CGroupController controller, String cGroupId); @Override void updateCGroupParam(CGroupController controller, String cGroupId,
      String param, String value); @Override String getCGroupParam(CGroupController controller, String cGroupId,
      String param);  }
@Test public void testMtabParsing() throws Exception { File parentDir = new File(tmpPath); File cpuCgroupMountDir = createMockCgroupMount(parentDir, "cpu", hierarchy); Assert.assertTrue(cpuCgroupMountDir.exists()); File blkioCgroupMountDir = createMockCgroupMount(parentDir, "blkio", hierarchy); Assert.assertTrue(blkioCgroupMountDir.exists()); File mockMtabFile = createMockMTab(parentDir); Map<CGroupsHandler.CGroupController, String> controllerPaths = CGroupsHandlerImpl.initializeControllerPathsFromMtab( mockMtabFile.getAbsolutePath(), hierarchy); Assert.assertEquals(2, controllerPaths.size()); Assert.assertTrue(controllerPaths .containsKey(CGroupsHandler.CGroupController.CPU)); Assert.assertTrue(controllerPaths .containsKey(CGroupsHandler.CGroupController.BLKIO)); String cpuDir = controllerPaths.get(CGroupsHandler.CGroupController.CPU); String blkioDir = controllerPaths.get(CGroupsHandler.CGroupController.BLKIO); Assert.assertEquals(parentDir.getAbsolutePath() + "/cpu", cpuDir); Assert.assertEquals(parentDir.getAbsolutePath() + "/blkio", blkioDir); }