HDFS-5650. Remove AclReadFlag and AclWriteFlag in FileSystem API. Contributed by Haohui Mai.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-4685@1550256 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris Nauroth 2013-12-11 20:54:46 +00:00
parent b4d8aabe6b
commit 709040c52e
13 changed files with 184 additions and 470 deletions

View File

@ -49,9 +49,7 @@ import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Options.ChecksumOpt;
import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.io.MultipleIOException;
import org.apache.hadoop.io.Text;
@ -2278,11 +2276,9 @@ public abstract class FileSystem extends Configured implements Closeable {
*
* @param path Path to modify
* @param aclSpec List<AclEntry> describing modifications
* @param flags EnumSet<AclWriteFlag> containing flags (such as recursive)
* @throws IOException if an ACL could not be modified
*/
public void modifyAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void modifyAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support modifyAclEntries");
}
@ -2293,11 +2289,9 @@ public abstract class FileSystem extends Configured implements Closeable {
*
* @param path Path to modify
* @param aclSpec List<AclEntry> describing entries to remove
* @param flags EnumSet<AclWriteFlag> containing flags (such as recursive)
* @throws IOException if an ACL could not be modified
*/
public void removeAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void removeAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support removeAclEntries");
}
@ -2306,10 +2300,9 @@ public abstract class FileSystem extends Configured implements Closeable {
* Removes all default ACL entries from files and directories.
*
* @param path Path to modify
* @param flags EnumSet<AclWriteFlag> containing flags (such as recursive)
* @throws IOException if an ACL could not be modified
*/
public void removeDefaultAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeDefaultAcl(Path path)
throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support removeDefaultAcl");
@ -2321,10 +2314,9 @@ public abstract class FileSystem extends Configured implements Closeable {
* bits.
*
* @param path Path to modify
* @param flags EnumSet<AclWriteFlag> containing flags (such as recursive)
* @throws IOException if an ACL could not be removed
*/
public void removeAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeAcl(Path path)
throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support removeAcl");
@ -2337,11 +2329,9 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param path Path to modify
* @param aclSpec List<AclEntry> describing modifications, must include entries
* for user, group, and others for compatibility with permission bits.
* @param flags EnumSet<AclWriteFlag> containing flags (such as recursive)
* @throws IOException if an ACL could not be modified
*/
public void setAcl(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void setAcl(Path path, Iterable<AclEntry> aclSpec) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support setAcl");
}
@ -2350,14 +2340,12 @@ public abstract class FileSystem extends Configured implements Closeable {
* Gets the ACLs of files and directories.
*
* @param path Path to get
* @param flags EnumSet<AclReadFlag> containing flags (such as recursive)
* @return RemoteIterator<AclStatus> which returns each AclStatus
* @throws IOException if an ACL could not be read
*/
public RemoteIterator<AclStatus> listAclStatus(Path path,
EnumSet<AclReadFlag> flags) throws IOException {
public AclStatus getAclStatus(Path path) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support listAclStatus");
+ " doesn't support getAclStatus");
}
// making it volatile to be able to do a double checked locking

View File

@ -22,14 +22,12 @@ import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.EnumSet;
import java.util.List;
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.AclReadFlag;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.ContentSummary;
import org.apache.hadoop.fs.Options.ChecksumOpt;
@ -514,38 +512,34 @@ public class FilterFileSystem extends FileSystem {
}
@Override
public void modifyAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
fs.modifyAclEntries(path, aclSpec, flags);
public void modifyAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
fs.modifyAclEntries(path, aclSpec);
}
@Override
public void removeAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
fs.removeAclEntries(path, aclSpec, flags);
public void removeAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
fs.removeAclEntries(path, aclSpec);
}
@Override
public void removeDefaultAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeDefaultAcl(Path path)
throws IOException {
fs.removeDefaultAcl(path, flags);
fs.removeDefaultAcl(path);
}
@Override
public void removeAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeAcl(Path path)
throws IOException {
fs.removeAcl(path, flags);
fs.removeAcl(path);
}
@Override
public void setAcl(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
fs.setAcl(path, aclSpec, flags);
public void setAcl(Path path, Iterable<AclEntry> aclSpec) throws IOException {
fs.setAcl(path, aclSpec);
}
@Override
public RemoteIterator<AclStatus> listAclStatus(Path path,
EnumSet<AclReadFlag> flags) throws IOException {
return fs.listAclStatus(path, flags);
public AclStatus getAclStatus(Path path) throws IOException {
return fs.getAclStatus(path);
}
}

View File

@ -1,141 +0,0 @@
/**
* 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.permission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.base.Objects;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
/**
* Defines an Access Control List, which is a set of rules for enforcement of
* permissions on a file or directory. An Acl contains a set of multiple
* {@link AclEntry} instances. The ACL entries define the permissions enforced
* for different classes of users: owner, named user, owning group, named group
* and others. The Acl also contains additional flags associated with the file,
* such as the sticky bit. Acl instances are immutable. Use a {@link Builder}
* to create a new instance.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class Acl {
private final List<AclEntry> entries;
private final boolean stickyBit;
/**
* Returns the sticky bit.
*
* @return boolean sticky bit
*/
public boolean getStickyBit() {
return stickyBit;
}
/**
* Returns the list of all ACL entries, ordered by their natural ordering.
* The list is unmodifiable.
*
* @return List<AclEntry> unmodifiable ordered list of all ACL entries
*/
public List<AclEntry> getEntries() {
return entries;
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (getClass() != o.getClass()) {
return false;
}
Acl other = (Acl)o;
return Objects.equal(entries, other.entries) &&
Objects.equal(stickyBit, other.stickyBit);
}
@Override
public int hashCode() {
return Objects.hashCode(entries, stickyBit);
}
@Override
public String toString() {
return new StringBuilder()
.append("entries: ").append(entries)
.append(", stickyBit: ").append(stickyBit)
.toString();
}
/**
* Builder for creating new Acl instances.
*/
public static class Builder {
private List<AclEntry> entries = new ArrayList<AclEntry>();
private boolean stickyBit = false;
/**
* Adds an ACL entry.
*
* @param entry AclEntry entry to add
* @return Builder this builder, for call chaining
*/
public Builder addEntry(AclEntry entry) {
entries.add(entry);
return this;
}
/**
* Sets sticky bit. If this method is not called, then the builder assumes
* false.
*
* @param stickyBit boolean sticky bit
* @return Builder this builder, for call chaining
*/
public Builder setStickyBit(boolean stickyBit) {
this.stickyBit = stickyBit;
return this;
}
/**
* Builds a new Acl populated with the set properties.
*
* @return Acl new Acl
*/
public Acl build() {
return new Acl(entries, stickyBit);
}
}
/**
* Private constructor.
*
* @param entries List<AclEntry> list of all ACL entries
* @param boolean sticky bit
*/
private Acl(List<AclEntry> entries, boolean stickyBit) {
List<AclEntry> entriesCopy = new ArrayList<AclEntry>(entries);
Collections.sort(entriesCopy);
this.entries = Collections.unmodifiableList(entriesCopy);
this.stickyBit = stickyBit;
}
}

View File

@ -1,34 +0,0 @@
/**
* 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.permission;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
/**
* Flags that control behavior of operations for reading ACL information.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public enum AclReadFlag {
/**
* Read ACLs for all files and directories recursively in the sub-tree of the
* specified path.
*/
RECURSIVE
}

View File

@ -17,33 +17,26 @@
*/
package org.apache.hadoop.fs.permission;
import com.google.common.base.Objects;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.fs.Path;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
/**
* An AclStatus represents an association of a specific file {@link Path} with
* an {@link Acl}. AclStatus instances are immutable. Use a {@link Builder} to
* create a new instance.
* An AclStatus contains the ACL information of a specific file. AclStatus
* instances are immutable. Use a {@link Builder} to create a new instance.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class AclStatus {
private final Path file;
private final String owner;
private final String group;
private final Acl acl;
/**
* Returns the file associated to this ACL.
*
* @return Path file associated to this ACL
*/
public Path getFile() {
return file;
}
private final boolean stickyBit;
private final Iterable<AclEntry> entries;
/**
* Returns the file owner.
@ -64,12 +57,21 @@ public class AclStatus {
}
/**
* Returns the ACL.
*
* @return Acl the ACL
* Returns the sticky bit.
*
* @return boolean sticky bit
*/
public Acl getAcl() {
return acl;
public boolean isStickyBit() {
return stickyBit;
}
/**
* Returns the list of all ACL entries, ordered by their natural ordering.
*
* @return Iterable<AclEntry> unmodifiable ordered list of all ACL entries
*/
public Iterable<AclEntry> getEntries() {
return entries;
}
@Override
@ -81,24 +83,26 @@ public class AclStatus {
return false;
}
AclStatus other = (AclStatus)o;
return Objects.equal(file, other.file) &&
Objects.equal(owner, other.owner) &&
Objects.equal(group, other.group) &&
Objects.equal(acl, other.acl);
return Objects.equal(owner, other.owner)
&& Objects.equal(group, other.group)
&& stickyBit == other.stickyBit
&& Objects.equal(entries, other.entries);
}
@Override
public int hashCode() {
return Objects.hashCode(file, owner, group, acl);
return Objects.hashCode(owner, group, stickyBit, entries);
}
@Override
public String toString() {
return new StringBuilder()
.append("file: ").append(file)
.append(", owner: ").append(owner)
.append("owner: ").append(owner)
.append(", group: ").append(group)
.append(", acl: {").append(acl).append('}')
.append(", acl: {")
.append("entries: ").append(entries)
.append(", stickyBit: ").append(stickyBit)
.append('}')
.toString();
}
@ -106,21 +110,10 @@ public class AclStatus {
* Builder for creating new Acl instances.
*/
public static class Builder {
private Path file;
private String owner;
private String group;
private Acl acl;
/**
* Sets the file associated to this ACL.
*
* @param file Path file associated to this ACL
* @return Builder this builder, for call chaining
*/
public Builder setFile(Path file) {
this.file = file;
return this;
}
private boolean stickyBit;
private List<AclEntry> entries = Lists.newArrayList();
/**
* Sets the file owner.
@ -128,7 +121,7 @@ public class AclStatus {
* @param owner String file owner
* @return Builder this builder, for call chaining
*/
public Builder setOwner(String owner) {
public Builder owner(String owner) {
this.owner = owner;
return this;
}
@ -139,29 +132,54 @@ public class AclStatus {
* @param group String file group
* @return Builder this builder, for call chaining
*/
public Builder setGroup(String group) {
public Builder group(String group) {
this.group = group;
return this;
}
/**
* Sets the ACL.
* Adds an ACL entry.
*
* @param acl Acl the ACL
* @param e AclEntry entry to add
* @return Builder this builder, for call chaining
*/
public Builder setAcl(Acl acl) {
this.acl = acl;
public Builder addEntry(AclEntry e) {
this.entries.add(e);
return this;
}
/**
* Builds a new Acl populated with the set properties.
* Adds a list of ACL entries.
*
* @return Acl new Acl
* @param entries AclEntry entries to add
* @return Builder this builder, for call chaining
*/
public Builder addEntries(Iterable<AclEntry> entries) {
for (AclEntry e : entries)
this.entries.add(e);
return this;
}
/**
* Sets sticky bit. If this method is not called, then the builder assumes
* false.
*
* @param stickyBit
* boolean sticky bit
* @return Builder this builder, for call chaining
*/
public Builder stickyBit(boolean stickyBit) {
this.stickyBit = stickyBit;
return this;
}
/**
* Builds a new AclStatus populated with the set properties.
*
* @return AclStatus new AclStatus
*/
public AclStatus build() {
return new AclStatus(file, owner, group, acl);
return new AclStatus(owner, group, stickyBit, entries);
}
}
@ -171,12 +189,16 @@ public class AclStatus {
* @param file Path file associated to this ACL
* @param owner String file owner
* @param group String file group
* @param acl Acl the ACL
* @param stickyBit the sticky bit
* @param entries the ACL entries
*/
private AclStatus(Path file, String owner, String group, Acl acl) {
this.file = file;
private AclStatus(String owner, String group, boolean stickyBit,
Iterable<AclEntry> entries) {
this.owner = owner;
this.group = group;
this.acl = acl;
this.stickyBit = stickyBit;
List<AclEntry> entriesCopy = Lists.newArrayList(entries);
Collections.sort(entriesCopy);
this.entries = entriesCopy;
}
}

View File

@ -1,34 +0,0 @@
/**
* 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.permission;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
/**
* Flags that control behavior of operations for writing ACL information.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public enum AclWriteFlag {
/**
* Modify ACLs for all files and directories recursively in the sub-tree of
* the specified path.
*/
RECURSIVE
}

View File

@ -20,7 +20,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.EnumSet;
import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
@ -37,11 +36,8 @@ import org.apache.hadoop.fs.FilterFileSystem;
import org.apache.hadoop.fs.FsServerDefaults;
import org.apache.hadoop.fs.FsStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.util.Progressable;
@ -285,39 +281,35 @@ class ChRootedFileSystem extends FilterFileSystem {
}
@Override
public void modifyAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
super.modifyAclEntries(fullPath(path), aclSpec, flags);
public void modifyAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
super.modifyAclEntries(fullPath(path), aclSpec);
}
@Override
public void removeAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
super.removeAclEntries(fullPath(path), aclSpec, flags);
public void removeAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
super.removeAclEntries(fullPath(path), aclSpec);
}
@Override
public void removeDefaultAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeDefaultAcl(Path path)
throws IOException {
super.removeDefaultAcl(fullPath(path), flags);
super.removeDefaultAcl(fullPath(path));
}
@Override
public void removeAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeAcl(Path path)
throws IOException {
super.removeAcl(fullPath(path), flags);
super.removeAcl(fullPath(path));
}
@Override
public void setAcl(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
super.setAcl(fullPath(path), aclSpec, flags);
public void setAcl(Path path, Iterable<AclEntry> aclSpec) throws IOException {
super.setAcl(fullPath(path), aclSpec);
}
@Override
public RemoteIterator<AclStatus> listAclStatus(Path path,
EnumSet<AclReadFlag> flags) throws IOException {
return super.listAclStatus(fullPath(path), flags);
public AclStatus getAclStatus(Path path) throws IOException {
return super.getAclStatus(fullPath(path));
}
@Override

View File

@ -28,7 +28,6 @@ import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import org.apache.hadoop.classification.InterfaceAudience;
@ -45,14 +44,10 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsConstants;
import org.apache.hadoop.fs.FsServerDefaults;
import org.apache.hadoop.fs.InvalidPathException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.fs.UnsupportedFileSystemException;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.viewfs.InodeTree.INode;
import org.apache.hadoop.fs.viewfs.InodeTree.INodeLink;
@ -479,51 +474,47 @@ public class ViewFileSystem extends FileSystem {
}
@Override
public void modifyAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void modifyAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
res.targetFileSystem.modifyAclEntries(res.remainingPath, aclSpec, flags);
res.targetFileSystem.modifyAclEntries(res.remainingPath, aclSpec);
}
@Override
public void removeAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void removeAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
res.targetFileSystem.removeAclEntries(res.remainingPath, aclSpec, flags);
res.targetFileSystem.removeAclEntries(res.remainingPath, aclSpec);
}
@Override
public void removeDefaultAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeDefaultAcl(Path path)
throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
res.targetFileSystem.removeDefaultAcl(res.remainingPath, flags);
res.targetFileSystem.removeDefaultAcl(res.remainingPath);
}
@Override
public void removeAcl(Path path, EnumSet<AclWriteFlag> flags)
public void removeAcl(Path path)
throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
res.targetFileSystem.removeAcl(res.remainingPath, flags);
res.targetFileSystem.removeAcl(res.remainingPath);
}
@Override
public void setAcl(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException {
public void setAcl(Path path, Iterable<AclEntry> aclSpec) throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
res.targetFileSystem.setAcl(res.remainingPath, aclSpec, flags);
res.targetFileSystem.setAcl(res.remainingPath, aclSpec);
}
@Override
public RemoteIterator<AclStatus> listAclStatus(Path path,
EnumSet<AclReadFlag> flags) throws IOException {
public AclStatus getAclStatus(Path path) throws IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(path), true);
return res.targetFileSystem.listAclStatus(res.remainingPath, flags);
return res.targetFileSystem.getAclStatus(res.remainingPath);
}
@Override

View File

@ -22,9 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclStatus;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.security.token.Token;
@ -37,7 +35,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import static org.apache.hadoop.fs.Options.ChecksumOpt;
import static org.apache.hadoop.fs.Options.CreateOpts;
@ -170,18 +167,12 @@ public class TestHarFileSystem {
String snapshotNewName) throws IOException;
public void deleteSnapshot(Path path, String snapshotName)
throws IOException;
public void modifyAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException;
public void removeAclEntries(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException;
public void removeDefaultAcl(Path path, EnumSet<AclWriteFlag> flags)
throws IOException;
public void removeAcl(Path path, EnumSet<AclWriteFlag> flags)
throws IOException;
public void setAcl(Path path, List<AclEntry> aclSpec,
EnumSet<AclWriteFlag> flags) throws IOException;
public RemoteIterator<AclStatus> listAclStatus(Path path,
EnumSet<AclReadFlag> flags) throws IOException;
public void modifyAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException;
public void removeAclEntries(Path path, Iterable<AclEntry> aclSpec) throws IOException;
public void removeDefaultAcl(Path path) throws IOException;
public void removeAcl(Path path) throws IOException;
public void setAcl(Path path, Iterable<AclEntry> aclSpec) throws IOException;
public AclStatus getAclStatus(Path path) throws IOException;
}
@Test

View File

@ -21,20 +21,21 @@ import static org.junit.Assert.*;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.hadoop.fs.Path;
import com.google.common.collect.Lists;
/**
* Tests covering basic functionality of the ACL objects.
*/
public class TestAcl {
private static final Acl ACL1, ACL2, ACL3, ACL4;
private static final AclEntry ENTRY1, ENTRY2, ENTRY3, ENTRY4, ENTRY5, ENTRY6,
private static AclEntry ENTRY1, ENTRY2, ENTRY3, ENTRY4, ENTRY5, ENTRY6,
ENTRY7, ENTRY8, ENTRY9, ENTRY10, ENTRY11, ENTRY12, ENTRY13;
private static final AclStatus STATUS1, STATUS2, STATUS3;
private static AclStatus STATUS1, STATUS2, STATUS3, STATUS4;
static {
@BeforeClass
public static void setUp() {
// named user
AclEntry.Builder aclEntryBuilder = new AclEntry.Builder()
.setType(AclEntryType.USER)
@ -107,31 +108,21 @@ public class TestAcl {
.setScope(AclEntryScope.DEFAULT)
.build();
Acl.Builder aclBuilder = new Acl.Builder()
AclStatus.Builder aclStatusBuilder = new AclStatus.Builder()
.owner("owner1")
.group("group1")
.addEntry(ENTRY1)
.addEntry(ENTRY3)
.addEntry(ENTRY4);
ACL1 = aclBuilder.build();
ACL2 = aclBuilder.build();
ACL3 = new Acl.Builder()
.setStickyBit(true)
.build();
AclStatus.Builder aclStatusBuilder = new AclStatus.Builder()
.setFile(new Path("file1"))
.setOwner("owner1")
.setGroup("group1")
.setAcl(ACL1);
STATUS1 = aclStatusBuilder.build();
STATUS2 = aclStatusBuilder.build();
STATUS3 = new AclStatus.Builder()
.setFile(new Path("file2"))
.setOwner("owner2")
.setGroup("group2")
.setAcl(ACL3)
.owner("owner2")
.group("group2")
.stickyBit(true)
.build();
ACL4 = new Acl.Builder()
STATUS4 = new AclStatus.Builder()
.addEntry(ENTRY1)
.addEntry(ENTRY3)
.addEntry(ENTRY4)
@ -147,39 +138,6 @@ public class TestAcl {
.build();
}
@Test
public void testAclEquals() {
assertNotSame(ACL1, ACL2);
assertNotSame(ACL1, ACL3);
assertNotSame(ACL2, ACL3);
assertEquals(ACL1, ACL1);
assertEquals(ACL2, ACL2);
assertEquals(ACL1, ACL2);
assertEquals(ACL2, ACL1);
assertFalse(ACL1.equals(ACL3));
assertFalse(ACL2.equals(ACL3));
assertFalse(ACL1.equals(null));
assertFalse(ACL1.equals(new Object()));
}
@Test
public void testAclHashCode() {
assertEquals(ACL1.hashCode(), ACL2.hashCode());
assertFalse(ACL1.hashCode() == ACL3.hashCode());
}
@Test
public void testAclEntriesImmutable() {
AclEntry entry = new AclEntry.Builder().build();
List<AclEntry> entries = ACL1.getEntries();
try {
entries.add(entry);
fail("expected adding ACL entry to fail");
} catch (UnsupportedOperationException e) {
// expected
}
}
@Test
public void testEntryEquals() {
assertNotSame(ENTRY1, ENTRY2);
@ -223,7 +181,7 @@ public class TestAcl {
ENTRY10, // default mask
ENTRY4 // default other
};
List<AclEntry> actual = ACL4.getEntries();
List<AclEntry> actual = Lists.newArrayList(STATUS4.getEntries());
assertNotNull(actual);
assertEquals(expected.length, actual.size());
for (int i = 0; i < expected.length; ++i) {
@ -267,25 +225,19 @@ public class TestAcl {
@Test
public void testToString() {
assertEquals(
"entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false",
ACL1.toString());
assertEquals(
"entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false",
ACL2.toString());
assertEquals("entries: [], stickyBit: true", ACL3.toString());
assertEquals("user:user1:rwx", ENTRY1.toString());
assertEquals("user:user1:rwx", ENTRY2.toString());
assertEquals("group:group2:rw-", ENTRY3.toString());
assertEquals("default:other::---", ENTRY4.toString());
assertEquals(
"file: file1, owner: owner1, group: group1, acl: {entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false}",
"owner: owner1, group: group1, acl: {entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false}",
STATUS1.toString());
assertEquals(
"file: file1, owner: owner1, group: group1, acl: {entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false}",
"owner: owner1, group: group1, acl: {entries: [user:user1:rwx, group:group2:rw-, default:other::---], stickyBit: false}",
STATUS2.toString());
assertEquals(
"file: file2, owner: owner2, group: group2, acl: {entries: [], stickyBit: true}",
"owner: owner2, group: group2, acl: {entries: [], stickyBit: true}",
STATUS3.toString());
}
}

View File

@ -21,7 +21,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
@ -33,8 +32,6 @@ import org.apache.hadoop.fs.FilterFileSystem;
import org.apache.hadoop.fs.FsConstants;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.viewfs.ChRootedFileSystem;
import org.junit.After;
import org.junit.Assert;
@ -378,26 +375,24 @@ public class TestChRootedFileSystem {
Path chrootPath = new Path("/c");
Path rawPath = new Path("/a/b/c");
List<AclEntry> entries = Collections.emptyList();
EnumSet<AclWriteFlag> writeFlags = EnumSet.noneOf(AclWriteFlag.class);
EnumSet<AclReadFlag> readFlags = EnumSet.noneOf(AclReadFlag.class);
chrootFs.modifyAclEntries(chrootPath, entries, writeFlags);
verify(mockFs).modifyAclEntries(rawPath, entries, writeFlags);
chrootFs.modifyAclEntries(chrootPath, entries);
verify(mockFs).modifyAclEntries(rawPath, entries);
chrootFs.removeAclEntries(chrootPath, entries, writeFlags);
verify(mockFs).removeAclEntries(rawPath, entries, writeFlags);
chrootFs.removeAclEntries(chrootPath, entries);
verify(mockFs).removeAclEntries(rawPath, entries);
chrootFs.removeDefaultAcl(chrootPath, writeFlags);
verify(mockFs).removeDefaultAcl(rawPath, writeFlags);
chrootFs.removeDefaultAcl(chrootPath);
verify(mockFs).removeDefaultAcl(rawPath);
chrootFs.removeAcl(chrootPath, writeFlags);
verify(mockFs).removeAcl(rawPath, writeFlags);
chrootFs.removeAcl(chrootPath);
verify(mockFs).removeAcl(rawPath);
chrootFs.setAcl(chrootPath, entries, writeFlags);
verify(mockFs).setAcl(rawPath, entries, writeFlags);
chrootFs.setAcl(chrootPath, entries);
verify(mockFs).setAcl(rawPath, entries);
chrootFs.listAclStatus(chrootPath, readFlags);
verify(mockFs).listAclStatus(rawPath, readFlags);
chrootFs.getAclStatus(chrootPath);
verify(mockFs).getAclStatus(rawPath);
}
static class MockFileSystem extends FilterFileSystem {

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.fs.viewfs;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@ -30,8 +29,6 @@ import org.apache.hadoop.fs.FsConstants;
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.AclEntry;
import org.apache.hadoop.fs.permission.AclReadFlag;
import org.apache.hadoop.fs.permission.AclWriteFlag;
import org.apache.hadoop.fs.viewfs.TestChRootedFileSystem.MockFileSystem;
import org.junit.*;
import static org.junit.Assert.*;
@ -103,38 +100,36 @@ public class TestViewFileSystemDelegation { //extends ViewFileSystemTestSetup {
Path viewFsPath2 = new Path("/mounts/mockfs2/d/e/f");
Path mockFsPath2 = new Path("/d/e/f");
List<AclEntry> entries = Collections.emptyList();
EnumSet<AclWriteFlag> writeFlags = EnumSet.noneOf(AclWriteFlag.class);
EnumSet<AclReadFlag> readFlags = EnumSet.noneOf(AclReadFlag.class);
viewFs.modifyAclEntries(viewFsPath1, entries, writeFlags);
verify(mockFs1).modifyAclEntries(mockFsPath1, entries, writeFlags);
viewFs.modifyAclEntries(viewFsPath2, entries, writeFlags);
verify(mockFs2).modifyAclEntries(mockFsPath2, entries, writeFlags);
viewFs.modifyAclEntries(viewFsPath1, entries);
verify(mockFs1).modifyAclEntries(mockFsPath1, entries);
viewFs.modifyAclEntries(viewFsPath2, entries);
verify(mockFs2).modifyAclEntries(mockFsPath2, entries);
viewFs.removeAclEntries(viewFsPath1, entries, writeFlags);
verify(mockFs1).removeAclEntries(mockFsPath1, entries, writeFlags);
viewFs.removeAclEntries(viewFsPath2, entries, writeFlags);
verify(mockFs2).removeAclEntries(mockFsPath2, entries, writeFlags);
viewFs.removeAclEntries(viewFsPath1, entries);
verify(mockFs1).removeAclEntries(mockFsPath1, entries);
viewFs.removeAclEntries(viewFsPath2, entries);
verify(mockFs2).removeAclEntries(mockFsPath2, entries);
viewFs.removeDefaultAcl(viewFsPath1, writeFlags);
verify(mockFs1).removeDefaultAcl(mockFsPath1, writeFlags);
viewFs.removeDefaultAcl(viewFsPath2, writeFlags);
verify(mockFs2).removeDefaultAcl(mockFsPath2, writeFlags);
viewFs.removeDefaultAcl(viewFsPath1);
verify(mockFs1).removeDefaultAcl(mockFsPath1);
viewFs.removeDefaultAcl(viewFsPath2);
verify(mockFs2).removeDefaultAcl(mockFsPath2);
viewFs.removeAcl(viewFsPath1, writeFlags);
verify(mockFs1).removeAcl(mockFsPath1, writeFlags);
viewFs.removeAcl(viewFsPath2, writeFlags);
verify(mockFs2).removeAcl(mockFsPath2, writeFlags);
viewFs.removeAcl(viewFsPath1);
verify(mockFs1).removeAcl(mockFsPath1);
viewFs.removeAcl(viewFsPath2);
verify(mockFs2).removeAcl(mockFsPath2);
viewFs.setAcl(viewFsPath1, entries, writeFlags);
verify(mockFs1).setAcl(mockFsPath1, entries, writeFlags);
viewFs.setAcl(viewFsPath2, entries, writeFlags);
verify(mockFs2).setAcl(mockFsPath2, entries, writeFlags);
viewFs.setAcl(viewFsPath1, entries);
verify(mockFs1).setAcl(mockFsPath1, entries);
viewFs.setAcl(viewFsPath2, entries);
verify(mockFs2).setAcl(mockFsPath2, entries);
viewFs.listAclStatus(viewFsPath1, readFlags);
verify(mockFs1).listAclStatus(mockFsPath1, readFlags);
viewFs.listAclStatus(viewFsPath2, readFlags);
verify(mockFs2).listAclStatus(mockFsPath2, readFlags);
viewFs.getAclStatus(viewFsPath1);
verify(mockFs1).getAclStatus(mockFsPath1);
viewFs.getAclStatus(viewFsPath2);
verify(mockFs2).getAclStatus(mockFsPath2);
}
void checkVerifyChecksum(boolean flag) {

View File

@ -9,6 +9,9 @@ HDFS-4685 (Unreleased)
IMPROVEMENTS
HDFS-5594. FileSystem API for ACLs. (cnauroth)
HDFS-5650. Remove AclReadFlag and AclWriteFlag in FileSystem API.
(Haohui Mai via cnauroth)
OPTIMIZATIONS
BUG FIXES