[ https://issues.apache.org/jira/browse/HADOOP-15891?focusedWorklogId=480602&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-480602 ]
ASF GitHub Bot logged work on HADOOP-15891: ------------------------------------------- Author: ASF GitHub Bot Created on: 09/Sep/20 05:28 Start Date: 09/Sep/20 05:28 Worklog Time Spent: 10m Work Description: JohnZZGithub commented on a change in pull request #2185: URL: https://github.com/apache/hadoop/pull/2185#discussion_r485346691 ########## File path: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLinkRegex.java ########## @@ -0,0 +1,473 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.fs.viewfs; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FileSystemTestHelper; +import org.apache.hadoop.fs.FsConstants; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.DFSConfigKeys; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hadoop.hdfs.MiniDFSNNTopology; +import org.apache.hadoop.test.GenericTestUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.hadoop.fs.viewfs.RegexMountPoint.INTERCEPTOR_INTERNAL_SEP; +import static org.junit.Assert.assertSame; + +/** + * Test linkRegex node type for view file system. + */ +public class TestViewFileSystemLinkRegex extends ViewFileSystemBaseTest { + public static final Logger LOGGER = + LoggerFactory.getLogger(TestViewFileSystemLinkRegex.class); + + private static FileSystem fsDefault; + private static MiniDFSCluster cluster; + private static Configuration clusterConfig; + private static final int NAME_SPACES_COUNT = 3; + private static final int DATA_NODES_COUNT = 3; + private static final int FS_INDEX_DEFAULT = 0; + private static final FileSystem[] FS_HDFS = new FileSystem[NAME_SPACES_COUNT]; + private static final String CLUSTER_NAME = + "TestViewFileSystemLinkRegexCluster"; + private static final File TEST_DIR = GenericTestUtils + .getTestDir(TestViewFileSystemLinkRegex.class.getSimpleName()); + private static final String TEST_BASE_PATH = + "/tmp/TestViewFileSystemLinkRegex"; + + @Override + protected FileSystemTestHelper createFileSystemHelper() { + return new FileSystemTestHelper(TEST_BASE_PATH); + } + + @BeforeClass + public static void clusterSetupAtBeginning() throws IOException { + SupportsBlocks = true; + clusterConfig = ViewFileSystemTestSetup.createConfig(); + clusterConfig.setBoolean( + DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, + true); + cluster = new MiniDFSCluster.Builder(clusterConfig).nnTopology( + MiniDFSNNTopology.simpleFederatedTopology(NAME_SPACES_COUNT)) + .numDataNodes(DATA_NODES_COUNT).build(); + cluster.waitClusterUp(); + + for (int i = 0; i < NAME_SPACES_COUNT; i++) { + FS_HDFS[i] = cluster.getFileSystem(i); + } + fsDefault = FS_HDFS[FS_INDEX_DEFAULT]; + } + + @AfterClass + public static void clusterShutdownAtEnd() throws Exception { + if (cluster != null) { + cluster.shutdown(); + } + } + + @Override + @Before + public void setUp() throws Exception { + fsTarget = fsDefault; + super.setUp(); + } + + /** + * Override this so that we don't set the targetTestRoot to any path under the + * root of the FS, and so that we don't try to delete the test dir, but rather + * only its contents. + */ + @Override + void initializeTargetTestRoot() throws IOException { + targetTestRoot = fsDefault.makeQualified(new Path("/")); + for (FileStatus status : fsDefault.listStatus(targetTestRoot)) { + fsDefault.delete(status.getPath(), true); + } + } + + @Override + void setupMountPoints() { + super.setupMountPoints(); + } + + @Override + int getExpectedDelegationTokenCount() { + return 1; // all point to the same fs so 1 unique token + } + + @Override + int getExpectedDelegationTokenCountWithCredentials() { + return 1; + } + + public String buildReplaceInterceptorSettingString(String srcRegex, + String replaceString) { + return + RegexMountPointInterceptorType.REPLACE_RESOLVED_DST_PATH.getConfigName() + + INTERCEPTOR_INTERNAL_SEP + srcRegex + INTERCEPTOR_INTERNAL_SEP + + replaceString; + } + + public String linkInterceptorSettings( + List<String> interceptorSettingStrList) { + StringBuilder stringBuilder = new StringBuilder(); + int listSize = interceptorSettingStrList.size(); + for (int i = 0; i < listSize; ++i) { + stringBuilder.append(interceptorSettingStrList.get(i)); + if (i < listSize - 1) { + stringBuilder.append(RegexMountPoint.INTERCEPTOR_SEP); + } + } + return stringBuilder.toString(); + } + + private void createDirWithChildren( + FileSystem fileSystem, Path dir, List<Path> childrenFiles) + throws IOException { + Assert.assertTrue(fileSystem.mkdirs(dir)); + int index = 0; + for (Path childFile : childrenFiles) { + createFile(fileSystem, childFile, index, true); + } + } + + private void createFile( + FileSystem fileSystem, Path file, int dataLenToWrite, boolean overwrite) + throws IOException { + FSDataOutputStream outputStream = null; + try { + outputStream = fileSystem.create(file, overwrite); + for (int i = 0; i < dataLenToWrite; ++i) { + outputStream.writeByte(i); + } + outputStream.close(); + } finally { + if (outputStream != null) { + outputStream.close(); + } + } + } + + private void createDirWithChildren( + FileSystem fileSystem, Path dir, int childrenFilesCnt) + throws IOException { + List<Path> childrenFiles = new ArrayList<>(childrenFilesCnt); + for (int i = 0; i < childrenFilesCnt; ++i) { + childrenFiles.add(new Path(dir, "file" + i)); + } + createDirWithChildren(fileSystem, dir, childrenFiles); + } + + /** + * The function used to test regex mountpoints. + * @param config - get mountable config from this conf + * @param regexStr - the src path regex expression that applies to this config + * @param dstPathStr - the string of target path + * @param interceptorSettings - the serialized interceptor string to be + * applied while resolving the mapping + * @param dirPathBeforeMountPoint - the src path user passed in to be mapped. + * @param expectedResolveResult - the expected path after resolve + * dirPathBeforeMountPoint via regex mountpint. + * @param childrenFilesCnt - the child files under dirPathBeforeMountPoint to + * be created + * @throws IOException + * @throws URISyntaxException + */ + private void testRegexMountpoint( + Configuration config, + String regexStr, + String dstPathStr, + String interceptorSettings, + Path dirPathBeforeMountPoint, + Path expectedResolveResult, + int childrenFilesCnt) + throws IOException, URISyntaxException { + FileSystem vfs = null; + try { + // Set up test env + createDirWithChildren( + fsTarget, expectedResolveResult, childrenFilesCnt); + ConfigUtil.addLinkRegex( + config, CLUSTER_NAME, regexStr, dstPathStr, interceptorSettings); + + // Asserts + URI viewFsUri = new URI( + FsConstants.VIEWFS_SCHEME, CLUSTER_NAME, "/", null, null); + vfs = FileSystem.get(viewFsUri, config); Review comment: Good call ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 480602) Time Spent: 5.5h (was: 5h 20m) > Provide Regex Based Mount Point In Inode Tree > --------------------------------------------- > > Key: HADOOP-15891 > URL: https://issues.apache.org/jira/browse/HADOOP-15891 > Project: Hadoop Common > Issue Type: New Feature > Components: viewfs > Reporter: zhenzhao wang > Assignee: zhenzhao wang > Priority: Major > Labels: pull-request-available > Attachments: HADOOP-15891.015.patch, HDFS-13948.001.patch, > HDFS-13948.002.patch, HDFS-13948.003.patch, HDFS-13948.004.patch, > HDFS-13948.005.patch, HDFS-13948.006.patch, HDFS-13948.007.patch, > HDFS-13948.008.patch, HDFS-13948.009.patch, HDFS-13948.011.patch, > HDFS-13948.012.patch, HDFS-13948.013.patch, HDFS-13948.014.patch, HDFS-13948_ > Regex Link Type In Mont Table-V0.pdf, HDFS-13948_ Regex Link Type In Mount > Table-v1.pdf > > Time Spent: 5.5h > Remaining Estimate: 0h > > This jira is created to support regex based mount point in Inode Tree. We > noticed that mount point only support fixed target path. However, we might > have user cases when target needs to refer some fields from source. e.g. We > might want a mapping of /cluster1/user1 => /cluster1-dc1/user-nn-user1, we > want to refer `cluster` and `user` field in source to construct target. It's > impossible to archive this with current link type. Though we could set > one-to-one mapping, the mount table would become bloated if we have thousands > of users. Besides, a regex mapping would empower us more flexibility. So we > are going to build a regex based mount point which target could refer groups > from src regex mapping. -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org