From a6e3cbc7f3ada9ac3150b9dcb887bc9571d1af6b Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Tue, 11 Mar 2014 16:21:45 +0000 Subject: [PATCH] HDFS-5638. Merging change r1576405 from trunk to branch-2. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1576410 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 + .../main/java/org/apache/hadoop/fs/Hdfs.java | 35 +++++- .../org/apache/hadoop/hdfs/DFSClient.java | 12 +- .../server/namenode/TestFileContextAcl.java | 103 ++++++++++++++++++ 4 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileContextAcl.java diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index d100df41884..413e5894940 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -506,6 +506,9 @@ Release 2.4.0 - UNRELEASED HDFS-6069. Quash stack traces when ACLs are disabled. (cnauroth) + HDFS-5638. HDFS implementation of FileContext API for ACLs. + (Vinayakumar B via cnauroth) + HDFS-5535 subtasks: HDFS-5496. Make replication queue initialization asynchronous. (Vinay via diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/fs/Hdfs.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/fs/Hdfs.java index b1df90aca0c..0fcb43dfe79 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/fs/Hdfs.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/fs/Hdfs.java @@ -30,11 +30,12 @@ import java.util.NoSuchElementException; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.permission.AclEntry; +import org.apache.hadoop.fs.permission.AclStatus; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.Options.ChecksumOpt; import org.apache.hadoop.hdfs.CorruptFileBlockIterator; import org.apache.hadoop.hdfs.DFSClient; -import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.client.HdfsDataInputStream; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream; @@ -383,6 +384,38 @@ public class Hdfs extends AbstractFileSystem { return tokenList; } + @Override + public void modifyAclEntries(Path path, List aclSpec) + throws IOException { + dfs.modifyAclEntries(getUriPath(path), aclSpec); + } + + @Override + public void removeAclEntries(Path path, List aclSpec) + throws IOException { + dfs.removeAclEntries(getUriPath(path), aclSpec); + } + + @Override + public void removeDefaultAcl(Path path) throws IOException { + dfs.removeDefaultAcl(getUriPath(path)); + } + + @Override + public void removeAcl(Path path) throws IOException { + dfs.removeAcl(getUriPath(path)); + } + + @Override + public void setAcl(Path path, List aclSpec) throws IOException { + dfs.setAcl(getUriPath(path), aclSpec); + } + + @Override + public AclStatus getAclStatus(Path path) throws IOException { + return dfs.getAclStatus(getUriPath(path)); + } + /** * Renew an existing delegation token. * diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index bf979dfc602..f45aa68923c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -2665,7 +2665,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { return clientContext; } - void modifyAclEntries(String src, List aclSpec) + public void modifyAclEntries(String src, List aclSpec) throws IOException { checkOpen(); try { @@ -2681,7 +2681,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { } } - void removeAclEntries(String src, List aclSpec) + public void removeAclEntries(String src, List aclSpec) throws IOException { checkOpen(); try { @@ -2697,7 +2697,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { } } - void removeDefaultAcl(String src) throws IOException { + public void removeDefaultAcl(String src) throws IOException { checkOpen(); try { namenode.removeDefaultAcl(src); @@ -2712,7 +2712,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { } } - void removeAcl(String src) throws IOException { + public void removeAcl(String src) throws IOException { checkOpen(); try { namenode.removeAcl(src); @@ -2727,7 +2727,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { } } - void setAcl(String src, List aclSpec) throws IOException { + public void setAcl(String src, List aclSpec) throws IOException { checkOpen(); try { namenode.setAcl(src, aclSpec); @@ -2742,7 +2742,7 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory { } } - AclStatus getAclStatus(String src) throws IOException { + public AclStatus getAclStatus(String src) throws IOException { checkOpen(); try { return namenode.getAclStatus(src); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileContextAcl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileContextAcl.java new file mode 100644 index 00000000000..51baa386723 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileContextAcl.java @@ -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.hdfs.server.namenode; + +import java.io.IOException; +import java.net.URI; +import java.util.List; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileContext; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.AclEntry; +import org.apache.hadoop.fs.permission.AclStatus; +import org.apache.hadoop.hdfs.DFSConfigKeys; +import org.apache.hadoop.hdfs.DistributedFileSystem; +import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.junit.BeforeClass; + +/** + * Tests for ACL operation through FileContext APIs + */ +public class TestFileContextAcl extends FSAclBaseTest { + + @BeforeClass + public static void init() throws Exception { + conf = new Configuration(); + conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); + cluster.waitActive(); + } + + @Override + protected FileSystem createFileSystem() throws Exception { + FileContextFS fcFs = new FileContextFS(); + fcFs.initialize(FileSystem.getDefaultUri(conf), conf); + return fcFs; + } + + /* + * To Re-use the FSAclBaseTest's testcases, creating a filesystem + * implementation which works based on fileContext. In this only overriding + * acl related methods, other operations will happen using normal filesystem + * itself which is out of scope for this test + */ + public static class FileContextFS extends DistributedFileSystem { + + private FileContext fc; + + @Override + public void initialize(URI uri, Configuration conf) throws IOException { + super.initialize(uri, conf); + fc = FileContext.getFileContext(conf); + } + + @Override + public void modifyAclEntries(Path path, List aclSpec) + throws IOException { + fc.modifyAclEntries(path, aclSpec); + } + + @Override + public void removeAclEntries(Path path, List aclSpec) + throws IOException { + fc.removeAclEntries(path, aclSpec); + } + + @Override + public void removeDefaultAcl(Path path) throws IOException { + fc.removeDefaultAcl(path); + } + + @Override + public void removeAcl(Path path) throws IOException { + fc.removeAcl(path); + } + + @Override + public void setAcl(Path path, List aclSpec) throws IOException { + fc.setAcl(path, aclSpec); + } + + @Override + public AclStatus getAclStatus(Path path) throws IOException { + return fc.getAclStatus(path); + } + } +}