Search in sources :

Example 81 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class TestJsonUtil method testToAclStatus.

@Test
public void testToAclStatus() throws IOException {
    String jsonString = "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
    ObjectReader reader = new ObjectMapper().readerFor(Map.class);
    Map<?, ?> json = reader.readValue(jsonString);
    List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, ALL), aclEntry(ACCESS, USER, "user1", READ_WRITE), aclEntry(ACCESS, GROUP, READ_WRITE), aclEntry(ACCESS, OTHER, READ_EXECUTE));
    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
    aclStatusBuilder.owner("testuser");
    aclStatusBuilder.group("supergroup");
    aclStatusBuilder.addEntries(aclSpec);
    aclStatusBuilder.stickyBit(false);
    Assert.assertEquals("Should be equal", aclStatusBuilder.build(), JsonUtilClient.toAclStatus(json));
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 82 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class PBHelperClient method convertAclEntryProto.

public static List<AclEntryProto> convertAclEntryProto(List<AclEntry> aclSpec) {
    ArrayList<AclEntryProto> r = Lists.newArrayListWithCapacity(aclSpec.size());
    for (AclEntry e : aclSpec) {
        AclEntryProto.Builder builder = AclEntryProto.newBuilder();
        builder.setType(convert(e.getType()));
        builder.setScope(convert(e.getScope()));
        builder.setPermissions(convert(e.getPermission()));
        if (e.getName() != null) {
            builder.setName(e.getName());
        }
        r.add(builder.build());
    }
    return r;
}
Also used : AclEntry(org.apache.hadoop.fs.permission.AclEntry) AclEntryProto(org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto)

Example 83 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class JsonUtilClient method toAclStatus.

/** Convert a Json map to a AclStatus object. */
static AclStatus toAclStatus(final Map<?, ?> json) {
    if (json == null) {
        return null;
    }
    final Map<?, ?> m = (Map<?, ?>) json.get(AclStatus.class.getSimpleName());
    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
    aclStatusBuilder.owner((String) m.get("owner"));
    aclStatusBuilder.group((String) m.get("group"));
    aclStatusBuilder.stickyBit((Boolean) m.get("stickyBit"));
    String permString = (String) m.get("permission");
    if (permString != null) {
        final FsPermission permission = toFsPermission(permString, (Boolean) m.get("aclBit"), (Boolean) m.get("encBit"));
        aclStatusBuilder.setPermission(permission);
    }
    final List<?> entries = (List<?>) m.get("entries");
    List<AclEntry> aclEntryList = new ArrayList<>();
    for (Object entry : entries) {
        AclEntry aclEntry = AclEntry.parseAclEntry((String) entry, true);
        aclEntryList.add(aclEntry);
    }
    aclStatusBuilder.addEntries(aclEntryList);
    return aclStatusBuilder.build();
}
Also used : DatanodeInfoBuilder(org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder) Builder(org.apache.hadoop.fs.ContentSummary.Builder) ArrayList(java.util.ArrayList) AclEntry(org.apache.hadoop.fs.permission.AclEntry) AclStatus(org.apache.hadoop.fs.permission.AclStatus) ArrayList(java.util.ArrayList) List(java.util.List) FsPermission(org.apache.hadoop.fs.permission.FsPermission) Map(java.util.Map)

Example 84 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class AclPermissionParam method parseAclSpec.

/**
   * @return parse {@code aclEntry} and return aclspec
   */
private static String parseAclSpec(List<AclEntry> aclEntries) {
    if (aclEntries == null) {
        return null;
    }
    if (aclEntries.isEmpty()) {
        return "";
    }
    if (aclEntries.size() == 1) {
        AclEntry entry = aclEntries.get(0);
        return entry == null ? "" : entry.toStringStable();
    }
    StringBuilder sb = new StringBuilder();
    Iterator<AclEntry> iter = aclEntries.iterator();
    sb.append(iter.next().toStringStable());
    while (iter.hasNext()) {
        AclEntry entry = iter.next();
        sb.append(',').append(entry == null ? "" : entry.toStringStable());
    }
    return sb.toString();
}
Also used : AclEntry(org.apache.hadoop.fs.permission.AclEntry)

Example 85 with AclEntry

use of org.apache.hadoop.fs.permission.AclEntry in project hadoop by apache.

the class CommandWithDestination method preserveAttributes.

/**
   * Preserve the attributes of the source to the target.
   * The method calls {@link #shouldPreserve(FileAttribute)} to check what
   * attribute to preserve.
   * @param src source to preserve
   * @param target where to preserve attributes
   * @param preserveRawXAttrs true if raw.* xattrs should be preserved
   * @throws IOException if fails to preserve attributes
   */
protected void preserveAttributes(PathData src, PathData target, boolean preserveRawXAttrs) throws IOException {
    if (shouldPreserve(FileAttribute.TIMESTAMPS)) {
        target.fs.setTimes(target.path, src.stat.getModificationTime(), src.stat.getAccessTime());
    }
    if (shouldPreserve(FileAttribute.OWNERSHIP)) {
        target.fs.setOwner(target.path, src.stat.getOwner(), src.stat.getGroup());
    }
    if (shouldPreserve(FileAttribute.PERMISSION) || shouldPreserve(FileAttribute.ACL)) {
        target.fs.setPermission(target.path, src.stat.getPermission());
    }
    if (shouldPreserve(FileAttribute.ACL)) {
        FsPermission perm = src.stat.getPermission();
        if (perm.getAclBit()) {
            List<AclEntry> srcEntries = src.fs.getAclStatus(src.path).getEntries();
            List<AclEntry> srcFullEntries = AclUtil.getAclFromPermAndEntries(perm, srcEntries);
            target.fs.setAcl(target.path, srcFullEntries);
        }
    }
    final boolean preserveXAttrs = shouldPreserve(FileAttribute.XATTR);
    if (preserveXAttrs || preserveRawXAttrs) {
        Map<String, byte[]> srcXAttrs = src.fs.getXAttrs(src.path);
        if (srcXAttrs != null) {
            Iterator<Entry<String, byte[]>> iter = srcXAttrs.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, byte[]> entry = iter.next();
                final String xattrName = entry.getKey();
                if (xattrName.startsWith(RAW) || preserveXAttrs) {
                    target.fs.setXAttr(target.path, entry.getKey(), entry.getValue());
                }
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) AclEntry(org.apache.hadoop.fs.permission.AclEntry) AclEntry(org.apache.hadoop.fs.permission.AclEntry) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Aggregations

AclEntry (org.apache.hadoop.fs.permission.AclEntry)137 Test (org.junit.Test)90 AclStatus (org.apache.hadoop.fs.permission.AclStatus)81 Path (org.apache.hadoop.fs.Path)52 FsPermission (org.apache.hadoop.fs.permission.FsPermission)25 ArrayList (java.util.ArrayList)11 FSAclBaseTest (org.apache.hadoop.hdfs.server.namenode.FSAclBaseTest)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 Configuration (org.apache.hadoop.conf.Configuration)7 FileStatus (org.apache.hadoop.fs.FileStatus)6 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)5 ScopedAclEntries (org.apache.hadoop.fs.permission.ScopedAclEntries)5 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)5 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)5 IOException (java.io.IOException)4 List (java.util.List)4 AclEntryScope (org.apache.hadoop.fs.permission.AclEntryScope)4 AclEntryProto (org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEntryProto)4 URI (java.net.URI)3 AclEntryType (org.apache.hadoop.fs.permission.AclEntryType)3