Example usage for org.apache.hadoop.fs.permission FsAction ALL

List of usage examples for org.apache.hadoop.fs.permission FsAction ALL

Introduction

In this page you can find the example usage for org.apache.hadoop.fs.permission FsAction ALL.

Prototype

FsAction ALL

To view the source code for org.apache.hadoop.fs.permission FsAction ALL.

Click Source Link

Usage

From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.handlers.TestACCESSHandler.java

License:Apache License

@Test
public void testAllPerms() throws Exception {
    when(filePermissions.toShort())// w  w  w. j  av a  2 s.c  o m
            .thenReturn(new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL).toShort());
    ACCESSResponse response = handler.handle(hdfsState, session, request);
    assertEquals(NFS4_OK, response.getStatus());
    assertEquals(ACCESSHandler.ACCESS_READ | ACCESSHandler.ACCESS_WRITE | ACCESSHandler.ACCESS_EXECUTE,
            response.getAccess());
}

From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.handlers.TestACCESSHandler.java

License:Apache License

@Test
public void testPerms() throws Exception {
    List<PermTest> perms = Lists.newArrayList();
    // read for owner when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.READ, FsAction.NONE, FsAction.NONE),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));
    // read for group when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.READ, FsAction.NONE),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));
    // read for other when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.READ),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));
    // read for other when not owner
    perms.add(new PermTest("notroot", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.READ),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));
    // read for other when not owner
    perms.add(new PermTest("root", "notwheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.READ),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));
    // read for other when not owner or group
    perms.add(new PermTest("notroot", "notwheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.READ),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP));

    // write for owner when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.WRITE, FsAction.NONE, FsAction.NONE),
            NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE));
    // write for group when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.WRITE, FsAction.NONE),
            NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE));
    // write for other when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.WRITE),
            NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE));
    // write for other when not owner
    perms.add(new PermTest("notroot", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.WRITE),
            NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND));
    // write for other when not owner
    perms.add(new PermTest("root", "notwheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.WRITE),
            NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE));
    // write for other when not owner or group
    perms.add(//from w  w  w  .  j  av  a 2 s .  c o  m
            new PermTest("notroot", "notwheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.WRITE),
                    NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND));

    // execute for owner when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.EXECUTE, FsAction.NONE, FsAction.NONE),
            NFS_ACCESS_EXECUTE));
    // execute for group when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.EXECUTE, FsAction.NONE),
            NFS_ACCESS_EXECUTE));
    // execute for other when owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.EXECUTE),
            NFS_ACCESS_EXECUTE));
    // execute for other when not owner
    perms.add(new PermTest("notroot", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.EXECUTE),
            NFS_ACCESS_EXECUTE));
    // execute for other when not owner
    perms.add(new PermTest("root", "notwheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.EXECUTE),
            NFS_ACCESS_EXECUTE));
    // execute for other when not owner or group
    perms.add(new PermTest("notroot", "notwheel",
            new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.EXECUTE), NFS_ACCESS_EXECUTE));
    // no perms but owner, this might be rethought?
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.NONE), 0));
    // all for user/group but not user/groups
    perms.add(new PermTest("notroot", "notwheel", new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.NONE),
            0));
    // all for user/group but not user/group
    perms.add(
            new PermTest("notroot", "wheel", new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE), 0));
    // owner has all, is owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP | NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE
                    | NFS_ACCESS_EXECUTE));
    // group has all is owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.ALL, FsAction.NONE),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP | NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE
                    | NFS_ACCESS_EXECUTE));
    // other has all is owner
    perms.add(new PermTest("root", "wheel", new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.ALL),
            NFS_ACCESS_READ | NFS_ACCESS_LOOKUP | NFS_ACCESS_MODIFY | NFS_ACCESS_EXTEND | NFS_ACCESS_DELETE
                    | NFS_ACCESS_EXECUTE));

    for (PermTest permTest : perms) {
        when(filePermissions.toShort()).thenReturn(permTest.perm.toShort());
        int result = ACCESSHandler.getPermsForUserGroup(permTest.user, new String[] { permTest.group },
                fileStatus);
        assertEquals(permTest.toString(), Integer.toBinaryString(permTest.result),
                Integer.toBinaryString(result));
    }
}

From source file:com.cloudera.recordbreaker.fisheye.AccessController.java

License:Open Source License

public boolean hasReadAccess(FileSummary fs) {
    String fileOwner = fs.getOwner();
    String fileGroup = fs.getGroup();
    FsPermission fsp = fs.getPermissions();

    // Check world-readable
    FsAction otherAction = fsp.getOtherAction();
    if (otherAction == FsAction.ALL || otherAction == FsAction.READ || otherAction == FsAction.READ_EXECUTE
            || otherAction == FsAction.READ_WRITE) {
        return true;
    }//from w  ww  .java  2 s .  c om

    // Check group-readable
    // REMIND -- mjc -- implement group-readable testing when we have the user database
    // that will tell us the current logged-in-user's groups.

    // Check owner-readable
    if (currentUser != null && currentUser.equals(fileOwner)) {
        FsAction userAction = fsp.getUserAction();
        if (userAction == FsAction.ALL || userAction == FsAction.READ || userAction == FsAction.READ_EXECUTE
                || userAction == FsAction.READ_WRITE) {
            return true;
        }
    }

    return false;
}

From source file:com.collective.celos.ci.testing.fixtures.deploy.hive.HiveTableDeployer.java

License:Apache License

private Path createTempHdfsFileForInsertion(FixTable fixTable, TestRun testRun) throws Exception {

    Path pathToParent = new Path(testRun.getHdfsPrefix(), ".hive");
    Path pathTo = new Path(pathToParent, UUID.randomUUID().toString());
    FileSystem fileSystem = testRun.getCiContext().getFileSystem();
    fileSystem.mkdirs(pathTo.getParent());
    FSDataOutputStream outputStream = fileSystem.create(pathTo);

    CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream), '\t', CSVWriter.NO_QUOTE_CHARACTER);

    for (FixTable.FixRow fixRow : fixTable.getRows()) {
        List<String> rowData = Lists.newArrayList();
        for (String colName : fixTable.getColumnNames()) {
            rowData.add(fixRow.getCells().get(colName));
        }//from   w w  w.j a  v  a2s.c o  m
        String[] dataArray = rowData.toArray(new String[rowData.size()]);
        writer.writeNext(dataArray);
    }

    writer.close();

    fileSystem.setPermission(pathToParent, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
    fileSystem.setPermission(pathTo, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
    return pathTo;
}

From source file:com.datatorrent.stram.util.FSUtil.java

License:Apache License

/**
 * Download the file from dfs to local file.
 *
 * @param fs//w ww. jav  a  2 s .  co m
 * @param destinationFile
 * @param dfsFile
 * @param conf
 * @return
 * @throws IOException
 */
public static File copyToLocalFileSystem(FileSystem fs, String destinationPath, String destinationFile,
        String dfsFile, Configuration conf) throws IOException {
    File destinationDir = new File(destinationPath);
    if (!destinationDir.exists() && !destinationDir.mkdirs()) {
        throw new RuntimeException("Unable to create local directory");
    }
    RawLocalFileSystem localFileSystem = new RawLocalFileSystem();
    try {
        // allow app user to access local dir
        FsPermission permissions = new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE);
        localFileSystem.setPermission(new Path(destinationDir.getAbsolutePath()), permissions);

        Path dfsFilePath = new Path(dfsFile);
        File localFile = new File(destinationDir, destinationFile);
        FileUtil.copy(fs, dfsFilePath, localFile, false, conf);
        // set permissions on actual file to be read-only for user
        permissions = new FsPermission(FsAction.READ, FsAction.NONE, FsAction.NONE);
        localFileSystem.setPermission(new Path(localFile.getAbsolutePath()), permissions);
        return localFile;
    } finally {
        localFileSystem.close();
    }
}

From source file:com.inmobi.conduit.distcp.tools.mapred.TestCopyMapper.java

License:Apache License

private static void changeUserGroup(String user, String group) throws IOException {
    FileSystem fs = cluster.getFileSystem();
    FsPermission changedPermission = new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL);
    for (Path path : pathList)
        if (fs.isFile(path)) {
            fs.setOwner(path, user, group);
            fs.setPermission(path, changedPermission);
        }//from   w w w  . j av  a  2  s.c om
}

From source file:com.lightboxtechnologies.spectrum.ExtractData.java

License:Apache License

protected static void chmodR(FileSystem fs, Path p) throws IOException {
    final FsPermission perm = new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL);
    final FileStatus[] list = fs.listStatus(p);
    for (FileStatus f : list) {
        if (f.isDir()) {
            chmodR(fs, f.getPath());/* w w w  . java2s. c  om*/
        }
        fs.setPermission(f.getPath(), perm);
    }
    fs.setPermission(p, perm);
}

From source file:com.linkedin.cubert.utils.AvroUtils.java

License:Open Source License

public static void createFileIfNotExists(BlockSchema fileSchema, String path) throws IOException {
    Configuration conf = new JobConf();
    FileSystem fs = FileSystem.get(conf);
    if (fs.exists(new Path(path)))
        return;//from  ww w .  ja v  a2  s . com

    Schema avroSchema = convertFromBlockSchema("CUBERT_MV_RECORD", fileSchema);
    System.out.println("Creating avro file with schema = " + avroSchema);
    GenericDatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(avroSchema);
    DataFileWriter<GenericRecord> writer = new DataFileWriter<GenericRecord>(datumWriter);

    FSDataOutputStream fout = FileSystem.create(fs, new Path(path),
            new FsPermission(FsAction.ALL, FsAction.READ_EXECUTE, FsAction.READ_EXECUTE));
    writer.create(avroSchema, fout);
    writer.flush();
    writer.close();

}

From source file:com.pentaho.big.data.bundles.impl.shim.hdfs.HadoopFileSystemImplTest.java

License:Apache License

@Test
public void testChmod() throws IOException {
    when(hadoopFileSystemPath.toString()).thenReturn(pathString);
    hadoopFileSystem.chmod(hadoopFileSystemPath, 753);
    verify(fileSystem).setPermission(eq(new Path(pathString)),
            eq(new FsPermission(FsAction.ALL, FsAction.READ_EXECUTE, FsAction.WRITE_EXECUTE)));
}

From source file:com.streamsets.pipeline.stage.destination.hdfs.util.TestHdfsUtils.java

License:Apache License

@Test
public void testParseFsPermission() {
    FsPermission permission;//from ww w  .j  a  va  2 s. c o  m

    /*
    // Not testing string constants as they behave differently in different Hadoop versions
    permission = HdfsUtils.parseFsPermission("a-rwx"); // Pre HADOOP-13508
    permission = HdfsUtils.parseFsPermission("a=rwx"); // Post HADOOP-13508
    assertEquals(FsAction.ALL, permission.getUserAction());
    assertEquals(FsAction.ALL, permission.getGroupAction());
    assertEquals(FsAction.ALL, permission.getOtherAction());
    */

    // Octal format
    permission = HdfsUtils.parseFsPermission("770");
    assertEquals(FsAction.ALL, permission.getUserAction());
    assertEquals(FsAction.ALL, permission.getGroupAction());
    assertEquals(FsAction.NONE, permission.getOtherAction());

    // Unix format
    permission = HdfsUtils.parseFsPermission("rwxrwx---");
    assertEquals(FsAction.ALL, permission.getUserAction());
    assertEquals(FsAction.ALL, permission.getGroupAction());
    assertEquals(FsAction.NONE, permission.getOtherAction());
}