[
https://issues.apache.org/jira/browse/HADOOP-15891?focusedWorklogId=480601&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-480601
]
ASF GitHub Bot logged work on HADOOP-15891:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 09/Sep/20 05:27
Start Date: 09/Sep/20 05:27
Worklog Time Spent: 10m
Work Description: JohnZZGithub commented on a change in pull request
#2185:
URL: https://github.com/apache/hadoop/pull/2185#discussion_r485346542
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestRegexMountPoint.java
##########
@@ -0,0 +1,160 @@
+/**
+ * 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.IOException;
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test Regex Mount Point.
+ */
+public class TestRegexMountPoint {
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(TestRegexMountPoint.class.getName());
+
+ private InodeTree inodeTree;
+ private Configuration conf;
+
+ class TestRegexMountPointFileSystem {
+ public URI getUri() {
+ return uri;
+ }
+
+ private URI uri;
+
+ TestRegexMountPointFileSystem(URI uri) {
+ String uriStr = uri == null ? "null" : uri.toString();
+ LOGGER.info("Create TestRegexMountPointFileSystem Via URI:" + uriStr);
+ this.uri = uri;
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ conf = new Configuration();
+ ConfigUtil.addLink(conf, TestRegexMountPoint.class.getName(), "/mnt",
+ URI.create("file:///"));
+
+ inodeTree = new InodeTree<TestRegexMountPointFileSystem>(conf,
+ TestRegexMountPoint.class.getName(), null, false) {
+ @Override
+ protected TestRegexMountPointFileSystem getTargetFileSystem(
+ final URI uri) {
+ return new TestRegexMountPointFileSystem(uri);
+ }
+
+ @Override
+ protected TestRegexMountPointFileSystem getTargetFileSystem(
+ final INodeDir<TestRegexMountPointFileSystem> dir) {
+ return new TestRegexMountPointFileSystem(null);
+ }
+
+ @Override
+ protected TestRegexMountPointFileSystem getTargetFileSystem(
+ final String settings, final URI[] mergeFsURIList) {
+ return new TestRegexMountPointFileSystem(null);
+ }
+ };
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ inodeTree = null;
+ }
+
+ @Test
+ public void testGetVarListInString() throws IOException {
+ String srcRegex = "/(\\w+)";
+ String target = "/$0/${1}/$1/${2}/${2}";
+ RegexMountPoint regexMountPoint =
+ new RegexMountPoint(inodeTree, srcRegex, target, null);
+ regexMountPoint.initialize();
+ Map<String, Set<String>> varMap = regexMountPoint.getVarInDestPathMap();
+ Assert.assertEquals(varMap.size(), 3);
+ Assert.assertEquals(varMap.get("0").size(), 1);
+ Assert.assertTrue(varMap.get("0").contains("$0"));
+ Assert.assertEquals(varMap.get("1").size(), 2);
+ Assert.assertTrue(varMap.get("1").contains("${1}"));
+ Assert.assertTrue(varMap.get("1").contains("$1"));
+ Assert.assertEquals(varMap.get("2").size(), 1);
+ Assert.assertTrue(varMap.get("2").contains("${2}"));
+ }
+
+ @Test
+ public void testResolve() throws IOException {
+ String regexStr = "^/user/(?<username>\\w+)";
+ String dstPathStr = "/namenode1/testResolve/$username";
+ String settingsStr = null;
+ RegexMountPoint regexMountPoint =
+ new RegexMountPoint(inodeTree, regexStr, dstPathStr, settingsStr);
+ regexMountPoint.initialize();
+ InodeTree.ResolveResult resolveResult =
+ regexMountPoint.resolve("/user/hadoop/file1", true);
+ Assert.assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
+ Assert.assertTrue(
+ resolveResult.targetFileSystem
+ instanceof TestRegexMountPointFileSystem);
+ Assert.assertTrue(resolveResult.resolvedPath.equals("/user/hadoop"));
+ Assert.assertTrue(
+ resolveResult.targetFileSystem
+ instanceof TestRegexMountPointFileSystem);
+ Assert.assertTrue(
+ ((TestRegexMountPointFileSystem) resolveResult.targetFileSystem)
+ .getUri().toString().equals("/namenode1/testResolve/hadoop"));
+ Assert.assertTrue(resolveResult.remainingPath.toString().equals("/file1"));
+ }
+
+ @Test
+ public void testResolveWithInterceptor() throws IOException {
+ String regexStr = "^/user/(?<username>\\w+)";
+ String dstPathStr = "/namenode1/testResolve/$username";
+ // Replace "_" with "-"
+ RegexMountPointResolvedDstPathReplaceInterceptor interceptor =
+ new RegexMountPointResolvedDstPathReplaceInterceptor("_", "-");
+ // replaceresolvedpath:_:-
+ String settingsStr = interceptor.serializeToString();
+ RegexMountPoint regexMountPoint =
+ new RegexMountPoint(inodeTree, regexStr, dstPathStr, settingsStr);
+ regexMountPoint.initialize();
+ InodeTree.ResolveResult resolveResult =
+ regexMountPoint.resolve("/user/hadoop_user1/file_index", true);
+ Assert.assertEquals(resolveResult.kind, InodeTree.ResultKind.EXTERNAL_DIR);
+ Assert.assertTrue(
+ resolveResult.targetFileSystem
+ instanceof TestRegexMountPointFileSystem);
+ Assert.assertTrue(resolveResult.resolvedPath.equals("/user/hadoop_user1"));
Review comment:
Nice catch, let me clean them up.
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 480601)
Time Spent: 5h 20m (was: 5h 10m)
> 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: 5h 20m
> 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: [email protected]
For additional commands, e-mail: [email protected]