org.apache.hadoop.fs.permission.FsPermission#valueOf ( )源码实例Demo

下面列出了org.apache.hadoop.fs.permission.FsPermission#valueOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zeppelin   文件: FileSystemStorage.java
public void writeFile(final String content, final Path file, boolean writeTempFileFirst, Set<PosixFilePermission> permissions)
    throws IOException {
  FsPermission fsPermission;
  if (permissions == null || permissions.isEmpty()) {
    fsPermission = FsPermission.getFileDefault();
  } else {
    // FsPermission expects a 10-character string because of the leading
    // directory indicator, i.e. "drwx------". The JDK toString method returns
    // a 9-character string, so prepend a leading character.
    fsPermission = FsPermission.valueOf("-" + PosixFilePermissions.toString(permissions));
  }
  callHdfsOperation(new HdfsOperation<Void>() {
    @Override
    public Void call() throws IOException {
      InputStream in = new ByteArrayInputStream(content.getBytes(
          zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING)));
      Path tmpFile = new Path(file.toString() + ".tmp");
      IOUtils.copyBytes(in, fs.create(tmpFile), hadoopConf);
      fs.setPermission(tmpFile, fsPermission);
      fs.delete(file, true);
      fs.rename(tmpFile, file);
      return null;
    }
  });
}
 
源代码2 项目: datacollector   文件: HdfsUtils.java
/**
 * Parse String representation of permissions into HDFS FsPermission class.
 *
 * This method accepts the following formats:
 *  * Octal like '777' or '770'
 *  * HDFS style changes like 'a-rwx'
 *  * Unix style write up with 9 characters like 'rwxrwx---'
 *
 * @param permissions String representing the permissions
 * @return Parsed FsPermission object
 */
public static FsPermission parseFsPermission(String permissions) throws IllegalArgumentException {
  try {
    // Octal or symbolic representation
    return new FsPermission(permissions);
  } catch (IllegalArgumentException e) {
    // FsPermission.valueOf will work with unix style permissions which is 10 characters
    // where the first character says the type of file
    if (permissions.length() == 9) {
      // This means it is a posix standard without the first character for file type
      // We will simply set it to '-' suggesting regular file
      permissions = "-" + permissions;
    }

    // Try to parse unix style format.
    return FsPermission.valueOf(permissions);
  }
}
 
源代码3 项目: hbase   文件: TestAccessController.java
@Test
public void testBulkLoadWithoutWritePermission() throws Exception {
  // Use the USER_CREATE to initialize the source directory.
  Path testDataDir0 = TEST_UTIL.getDataTestDirOnTestFS("testBulkLoadWithoutWritePermission0");
  Path testDataDir1 = TEST_UTIL.getDataTestDirOnTestFS("testBulkLoadWithoutWritePermission1");
  AccessTestAction bulkLoadAction1 =
      new BulkLoadAccessTestAction(FsPermission.valueOf("-r-xr-xr-x"), testDataDir0);
  AccessTestAction bulkLoadAction2 =
      new BulkLoadAccessTestAction(FS_PERMISSION_ALL, testDataDir1);
  // Test the incorrect case.
  BulkLoadHelper.setPermission(TEST_UTIL.getTestFileSystem(),
    TEST_UTIL.getTestFileSystem().getWorkingDirectory(), FS_PERMISSION_ALL);
  try {
    USER_CREATE.runAs(bulkLoadAction1);
    fail("Should fail because the hbase user has no write permission on hfiles.");
  } catch (IOException e) {
  }
  // Ensure the correct case.
  USER_CREATE.runAs(bulkLoadAction2);
}
 
源代码4 项目: hadoop   文件: HftpFileSystem.java
@Override
public void startElement(String ns, String localname, String qname,
            Attributes attrs) throws SAXException {
  if ("listing".equals(qname)) return;
  if (!"file".equals(qname) && !"directory".equals(qname)) {
    if (RemoteException.class.getSimpleName().equals(qname)) {
      throw new SAXException(RemoteException.valueOf(attrs));
    }
    throw new SAXException("Unrecognized entry: " + qname);
  }
  long modif;
  long atime = 0;
  try {
    final SimpleDateFormat ldf = df.get();
    modif = ldf.parse(attrs.getValue("modified")).getTime();
    String astr = attrs.getValue("accesstime");
    if (astr != null) {
      atime = ldf.parse(astr).getTime();
    }
  } catch (ParseException e) { throw new SAXException(e); }
  FileStatus fs = "file".equals(qname)
    ? new FileStatus(
          Long.parseLong(attrs.getValue("size")), false,
          Short.valueOf(attrs.getValue("replication")).shortValue(),
          Long.parseLong(attrs.getValue("blocksize")),
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          HftpFileSystem.this.makeQualified(
              new Path(getUri().toString(), attrs.getValue("path"))))
    : new FileStatus(0L, true, 0, 0L,
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          HftpFileSystem.this.makeQualified(
              new Path(getUri().toString(), attrs.getValue("path"))));
  fslist.add(fs);
}
 
源代码5 项目: hadoop   文件: AzureNativeFileSystemStore.java
private static PermissionStatus fromJSONMap(
    @SuppressWarnings("rawtypes") Map object) {
  return new PermissionStatus((String) object.get(OWNER_TAG),
      (String) object.get(GROUP_TAG),
      // The initial - below is the Unix file type,
      // which FsPermission needs there but ignores.
      FsPermission.valueOf("-" + (String) object.get(PERMISSIONS_TAG)));
}
 
源代码6 项目: hadoop   文件: LocalJavaKeyStoreProvider.java
@Override
public void flush() throws IOException {
  super.flush();
  if (!Shell.WINDOWS) {
    Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()),
        permissions);
  } else {
    // FsPermission expects a 10-character string because of the leading
    // directory indicator, i.e. "drwx------". The JDK toString method returns
    // a 9-character string, so prepend a leading character.
    FsPermission fsPermission = FsPermission.valueOf(
        "-" + PosixFilePermissions.toString(permissions));
    FileUtil.setPermission(file, fsPermission);
  }
}
 
源代码7 项目: hadoop   文件: TestFileStatus.java
/**
 * Check that FileStatus are equal if their paths are equal.
 */
@Test
public void testEquals() {
  Path path = new Path("path");
  FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path);
  FileStatus fileStatus2 = new FileStatus(2, true, 2, 2, 2, 2,
      FsPermission.valueOf("---x--x--x"), "two", "two", null, path);
  assertEquals(fileStatus1, fileStatus2);
}
 
源代码8 项目: hadoop   文件: TestFileStatus.java
/**
 * Check that FileStatus are not equal if their paths are not equal.
 */
@Test
public void testNotEquals() {
  Path path1 = new Path("path1");
  Path path2 = new Path("path2");
  FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path1);
  FileStatus fileStatus2 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path2);
  assertFalse(fileStatus1.equals(fileStatus2));
  assertFalse(fileStatus2.equals(fileStatus1));
}
 
源代码9 项目: twill   文件: FileContextLocation.java
/**
 * Parses the given permission to {@link FsPermission}.
 *
 * @param permission the permission as passed to the {@link #createNew(String)} or {@link #getOutputStream(String)}
 *                   methods.
 * @return a new {@link FsPermission}.
 */
private FsPermission parsePermissions(String permission) {
  if (permission.length() == 3) {
    return new FsPermission(permission);
  } else if (permission.length() == 9) {
    // The FsPermission expect a 10 characters string, which it will ignore the first character
    return FsPermission.valueOf("-" + permission);
  } else {
    throw new IllegalArgumentException("Invalid permission " + permission +
                                         ". Permission should either be a three digit or nine character string.");
  }
}
 
源代码10 项目: big-c   文件: HftpFileSystem.java
@Override
public void startElement(String ns, String localname, String qname,
            Attributes attrs) throws SAXException {
  if ("listing".equals(qname)) return;
  if (!"file".equals(qname) && !"directory".equals(qname)) {
    if (RemoteException.class.getSimpleName().equals(qname)) {
      throw new SAXException(RemoteException.valueOf(attrs));
    }
    throw new SAXException("Unrecognized entry: " + qname);
  }
  long modif;
  long atime = 0;
  try {
    final SimpleDateFormat ldf = df.get();
    modif = ldf.parse(attrs.getValue("modified")).getTime();
    String astr = attrs.getValue("accesstime");
    if (astr != null) {
      atime = ldf.parse(astr).getTime();
    }
  } catch (ParseException e) { throw new SAXException(e); }
  FileStatus fs = "file".equals(qname)
    ? new FileStatus(
          Long.parseLong(attrs.getValue("size")), false,
          Short.valueOf(attrs.getValue("replication")).shortValue(),
          Long.parseLong(attrs.getValue("blocksize")),
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          HftpFileSystem.this.makeQualified(
              new Path(getUri().toString(), attrs.getValue("path"))))
    : new FileStatus(0L, true, 0, 0L,
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          HftpFileSystem.this.makeQualified(
              new Path(getUri().toString(), attrs.getValue("path"))));
  fslist.add(fs);
}
 
源代码11 项目: big-c   文件: AzureNativeFileSystemStore.java
private static PermissionStatus fromJSONMap(
    @SuppressWarnings("rawtypes") Map object) {
  return new PermissionStatus((String) object.get(OWNER_TAG),
      (String) object.get(GROUP_TAG),
      // The initial - below is the Unix file type,
      // which FsPermission needs there but ignores.
      FsPermission.valueOf("-" + (String) object.get(PERMISSIONS_TAG)));
}
 
源代码12 项目: big-c   文件: LocalJavaKeyStoreProvider.java
@Override
public void flush() throws IOException {
  super.flush();
  if (!Shell.WINDOWS) {
    Files.setPosixFilePermissions(Paths.get(file.getCanonicalPath()),
        permissions);
  } else {
    // FsPermission expects a 10-character string because of the leading
    // directory indicator, i.e. "drwx------". The JDK toString method returns
    // a 9-character string, so prepend a leading character.
    FsPermission fsPermission = FsPermission.valueOf(
        "-" + PosixFilePermissions.toString(permissions));
    FileUtil.setPermission(file, fsPermission);
  }
}
 
源代码13 项目: big-c   文件: TestFileStatus.java
/**
 * Check that FileStatus are equal if their paths are equal.
 */
@Test
public void testEquals() {
  Path path = new Path("path");
  FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path);
  FileStatus fileStatus2 = new FileStatus(2, true, 2, 2, 2, 2,
      FsPermission.valueOf("---x--x--x"), "two", "two", null, path);
  assertEquals(fileStatus1, fileStatus2);
}
 
源代码14 项目: big-c   文件: TestFileStatus.java
/**
 * Check that FileStatus are not equal if their paths are not equal.
 */
@Test
public void testNotEquals() {
  Path path1 = new Path("path1");
  Path path2 = new Path("path2");
  FileStatus fileStatus1 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path1);
  FileStatus fileStatus2 = new FileStatus(1, true, 1, 1, 1, 1,
      FsPermission.valueOf("-rw-rw-rw-"), "one", "one", null, path2);
  assertFalse(fileStatus1.equals(fileStatus2));
  assertFalse(fileStatus2.equals(fileStatus1));
}
 
源代码15 项目: RDFS   文件: HftpFileSystem.java
public void startElement(String ns, String localname, String qname,
            Attributes attrs) throws SAXException {
  if ("listing".equals(qname)) return;
  if (!"file".equals(qname) && !"directory".equals(qname)) {
    if (RemoteException.class.getSimpleName().equals(qname)) {
      throw new SAXException(RemoteException.valueOf(attrs));
    }
    throw new SAXException("Unrecognized entry: " + qname);
  }
  long modif;
  long atime = 0;
  try {
    final SimpleDateFormat ldf = df.get();
    modif = ldf.parse(attrs.getValue("modified")).getTime();
    String astr = attrs.getValue("accesstime");
    if (astr != null) {
      atime = ldf.parse(astr).getTime();
    }
  } catch (ParseException e) { throw new SAXException(e); }
  FileStatus fs = "file".equals(qname)
    ? new FileStatus(
          Long.valueOf(attrs.getValue("size")).longValue(), false,
          Short.valueOf(attrs.getValue("replication")).shortValue(),
          Long.valueOf(attrs.getValue("blocksize")).longValue(),
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          new Path(getUri().toString(), attrs.getValue("path"))
            .makeQualified(HftpFileSystem.this))
    : new FileStatus(0L, true, 0, 0L,
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          new Path(getUri().toString(), attrs.getValue("path"))
            .makeQualified(HftpFileSystem.this));
  fslist.add(fs);
}
 
源代码16 项目: hadoop-gpu   文件: HftpFileSystem.java
public void startElement(String ns, String localname, String qname,
            Attributes attrs) throws SAXException {
  if ("listing".equals(qname)) return;
  if (!"file".equals(qname) && !"directory".equals(qname)) {
    if (RemoteException.class.getSimpleName().equals(qname)) {
      throw new SAXException(RemoteException.valueOf(attrs));
    }
    throw new SAXException("Unrecognized entry: " + qname);
  }
  long modif;
  long atime = 0;
  try {
    final SimpleDateFormat ldf = df.get();
    modif = ldf.parse(attrs.getValue("modified")).getTime();
    String astr = attrs.getValue("accesstime");
    if (astr != null) {
      atime = ldf.parse(astr).getTime();
    }
  } catch (ParseException e) { throw new SAXException(e); }
  FileStatus fs = "file".equals(qname)
    ? new FileStatus(
          Long.valueOf(attrs.getValue("size")).longValue(), false,
          Short.valueOf(attrs.getValue("replication")).shortValue(),
          Long.valueOf(attrs.getValue("blocksize")).longValue(),
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          new Path(getUri().toString(), attrs.getValue("path"))
            .makeQualified(HftpFileSystem.this))
    : new FileStatus(0L, true, 0, 0L,
          modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
          attrs.getValue("owner"), attrs.getValue("group"),
          new Path(getUri().toString(), attrs.getValue("path"))
            .makeQualified(HftpFileSystem.this));
  fslist.add(fs);
}
 
源代码17 项目: dremio-oss   文件: HadoopFileSystem.java
@VisibleForTesting
static FsPermission toFsPermission(Set<PosixFilePermission> permissions) {
  return FsPermission.valueOf("-" + PosixFilePermissions.toString(permissions));
}
 
源代码18 项目: dremio-oss   文件: DremioHadoopFileSystemWrapper.java
@VisibleForTesting
static FsPermission toFsPermission(Set<PosixFilePermission> permissions) {
  return FsPermission.valueOf("-" + PosixFilePermissions.toString(permissions));
}
 
源代码19 项目: dremio-oss   文件: DremioHadoopFileSystemWrapper.java
@VisibleForTesting
static FsPermission toFsPermission(Set<PosixFilePermission> permissions) {
  return FsPermission.valueOf("-" + PosixFilePermissions.toString(permissions));
}