-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDFS-16791. Add getEnclosingRoot() API to filesystem interface and im…
…plementations (#6198) The enclosing root path is a common ancestor that should be used for temp and staging dirs as well as within encryption zones and other restricted directories. Contributed by Tom McCormick
- Loading branch information
1 parent
78fc23e
commit 82285ce
Showing
29 changed files
with
877 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetEnclosingRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* 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.fs; | ||
|
||
import java.io.IOException; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.apache.hadoop.test.HadoopTestBase; | ||
import org.junit.Test; | ||
|
||
public class TestGetEnclosingRoot extends HadoopTestBase { | ||
@Test | ||
public void testEnclosingRootEquivalence() throws IOException { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
Path foobar = path("/foo/bar"); | ||
|
||
assertEquals(root, fs.getEnclosingRoot(root)); | ||
assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(foobar))); | ||
assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(foobar)); | ||
|
||
assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
assertEquals(root, fs.getEnclosingRoot(fs.getEnclosingRoot(path(foobar.toString())))); | ||
assertEquals(fs.getEnclosingRoot(root), fs.getEnclosingRoot(path(foobar.toString()))); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootPathExists() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
Path foobar = path("/foo/bar"); | ||
fs.mkdirs(foobar); | ||
|
||
assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootPathDNE() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path foobar = path("/foo/bar"); | ||
Path root = path("/"); | ||
|
||
assertEquals(root, fs.getEnclosingRoot(foobar)); | ||
assertEquals(root, fs.getEnclosingRoot(path(foobar.toString()))); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootWrapped() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
|
||
assertEquals(root, fs.getEnclosingRoot(new Path("/foo/bar"))); | ||
|
||
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("foo"); | ||
Path p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> { | ||
FileSystem wFs = getFileSystem(); | ||
return wFs.getEnclosingRoot(new Path("/foo/bar")); | ||
}); | ||
assertEquals(root, p); | ||
} | ||
|
||
private FileSystem getFileSystem() throws IOException { | ||
return FileSystem.get(new Configuration()); | ||
} | ||
|
||
/** | ||
* Create a path under the test path provided by | ||
* the FS contract. | ||
* @param filepath path string in | ||
* @return a path qualified by the test filesystem | ||
* @throws IOException IO problems | ||
*/ | ||
private Path path(String filepath) throws IOException { | ||
return getFileSystem().makeQualified( | ||
new Path(filepath)); | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractGetEnclosingRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* 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.fs.contract; | ||
|
||
import java.io.IOException; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public abstract class AbstractContractGetEnclosingRoot extends AbstractFSContractTestBase { | ||
private static final Logger LOG = LoggerFactory.getLogger(AbstractContractGetEnclosingRoot.class); | ||
|
||
@Test | ||
public void testEnclosingRootEquivalence() throws IOException { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
Path foobar = path("/foo/bar"); | ||
|
||
assertEquals("Ensure getEnclosingRoot on the root directory returns the root directory", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot called on itself returns the root directory", | ||
root, fs.getEnclosingRoot(fs.getEnclosingRoot(foobar))); | ||
assertEquals( | ||
"Ensure getEnclosingRoot for different paths in the same enclosing root " | ||
+ "returns the same path", | ||
fs.getEnclosingRoot(root), fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot on a path returns the root directory", | ||
root, fs.getEnclosingRoot(methodPath())); | ||
assertEquals("Ensure getEnclosingRoot called on itself on a path returns the root directory", | ||
root, fs.getEnclosingRoot(fs.getEnclosingRoot(methodPath()))); | ||
assertEquals( | ||
"Ensure getEnclosingRoot for different paths in the same enclosing root " | ||
+ "returns the same path", | ||
fs.getEnclosingRoot(root), | ||
fs.getEnclosingRoot(methodPath())); | ||
} | ||
|
||
|
||
@Test | ||
public void testEnclosingRootPathExists() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
Path foobar = methodPath(); | ||
fs.mkdirs(foobar); | ||
|
||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory when the root directory exists", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals("Ensure getEnclosingRoot returns the root directory when the directory exists", | ||
root, fs.getEnclosingRoot(foobar)); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootPathDNE() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path foobar = path("/foo/bar"); | ||
Path root = path("/"); | ||
|
||
// . | ||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory even when the path does not exist", | ||
root, fs.getEnclosingRoot(foobar)); | ||
assertEquals( | ||
"Ensure getEnclosingRoot returns the root directory even when the path does not exist", | ||
root, fs.getEnclosingRoot(methodPath())); | ||
} | ||
|
||
@Test | ||
public void testEnclosingRootWrapped() throws Exception { | ||
FileSystem fs = getFileSystem(); | ||
Path root = path("/"); | ||
|
||
assertEquals("Ensure getEnclosingRoot returns the root directory when the directory exists", | ||
root, fs.getEnclosingRoot(new Path("/foo/bar"))); | ||
|
||
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("foo"); | ||
Path p = ugi.doAs((PrivilegedExceptionAction<Path>) () -> { | ||
FileSystem wFs = getContract().getTestFileSystem(); | ||
return wFs.getEnclosingRoot(new Path("/foo/bar")); | ||
}); | ||
assertEquals("Ensure getEnclosingRoot works correctly within a wrapped FileSystem", root, p); | ||
} | ||
} |
Oops, something went wrong.