[ https://issues.apache.org/jira/browse/YARN-11672?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17839564#comment-17839564 ]
ASF GitHub Bot commented on YARN-11672: --------------------------------------- brumi1024 commented on code in PR #6734: URL: https://github.com/apache/hadoop/pull/6734#discussion_r1574392520 ########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsV2HandlerImpl.java: ########## @@ -0,0 +1,287 @@ +/* + * * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources; + +import org.apache.commons.io.FileUtils; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.verifyZeroInteractions; + +/** + * Tests for the CGroups handler implementation. + */ +public class TestCGroupsV2HandlerImpl extends TestCGroupsHandlerBase { + private static final Logger LOG = + LoggerFactory.getLogger(TestCGroupsV2HandlerImpl.class); + + // Create a controller file in the unified hierarchy of cgroup v2 + @Override + protected String getControllerFilePath(String controllerName) { + return new File(tmpPath, hierarchy).getAbsolutePath(); + } + + public File createPremountedCgroups(File parentDir) + throws IOException { + // Format: + // cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 + String baseCgroup2Line = + "cgroup2 " + parentDir.getAbsolutePath() + + " cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0\n"; + + File mockMtab = new File(parentDir, UUID.randomUUID().toString()); + if (!mockMtab.exists()) { + if (!mockMtab.createNewFile()) { + String message = "Could not create file " + mockMtab.getAbsolutePath(); + throw new IOException(message); + } + } + FileWriter mtabWriter = new FileWriter(mockMtab.getAbsoluteFile()); + mtabWriter.write(baseCgroup2Line); + mtabWriter.close(); + mockMtab.deleteOnExit(); + + String enabledControllers = "cpuset cpu io memory hugetlb pids rdma misc\n"; + + File controllersFile = new File(parentDir, CGroupsHandler.CGROUP_CONTROLLERS_FILE); + FileWriter controllerWriter = new FileWriter(controllersFile.getAbsoluteFile()); + controllerWriter.write(enabledControllers); + controllerWriter.close(); + controllersFile.deleteOnExit(); + + File subtreeControlFile = new File(parentDir, CGroupsHandler.CGROUP_SUBTREE_CONTROL_FILE); + Assert.assertTrue("empty subtree_control file should be created", subtreeControlFile.createNewFile()); + + File hierarchyDir = new File(parentDir, hierarchy); + if (!hierarchyDir.mkdirs()) { + String message = "Could not create directory " + hierarchyDir.getAbsolutePath(); + throw new IOException(message); + } + hierarchyDir.deleteOnExit(); + FileUtils.copyFile(controllersFile, new File(hierarchyDir, CGroupsHandler.CGROUP_CONTROLLERS_FILE)); + FileUtils.copyFile(subtreeControlFile, new File(hierarchyDir, CGroupsHandler.CGROUP_SUBTREE_CONTROL_FILE)); + + return mockMtab; + } + + @Test + public void testCGroupPaths() throws IOException { + verifyZeroInteractions(privilegedOperationExecutorMock); + CGroupsHandler cGroupsHandler = null; + File parentDir = new File(tmpPath); + File mtab = createPremountedCgroups(parentDir); + assertTrue("Sample subsystem should be created", + new File(controllerPath).exists()); + + try { + cGroupsHandler = new CGroupsV2HandlerImpl(createNoMountConfiguration(hierarchy), + privilegedOperationExecutorMock, mtab.getAbsolutePath()); + cGroupsHandler.initializeCGroupController(controller); + } catch (ResourceHandlerException e) { Review Comment: Done. > Create a CgroupHandler implementation for cgroup v2 > --------------------------------------------------- > > Key: YARN-11672 > URL: https://issues.apache.org/jira/browse/YARN-11672 > Project: Hadoop YARN > Issue Type: Sub-task > Reporter: Benjamin Teke > Assignee: Benjamin Teke > Priority: Major > Labels: pull-request-available > > [CGroupsHandler's|https://github.com/apache/hadoop/blob/69b328943edf2f61c8fc139934420e3f10bf3813/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsHandler.java#L36] > current implementation holds the functionality to mount and setup the YARN > specific cgroup v1 functionality. A similar v2 implementation should be > created that allows initialising the v2 structure. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: yarn-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: yarn-issues-h...@hadoop.apache.org