當前位置: 首頁>>代碼示例>>Java>>正文


Java FsPermission類代碼示例

本文整理匯總了Java中org.apache.hadoop.fs.permission.FsPermission的典型用法代碼示例。如果您正苦於以下問題:Java FsPermission類的具體用法?Java FsPermission怎麽用?Java FsPermission使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FsPermission類屬於org.apache.hadoop.fs.permission包,在下文中一共展示了FsPermission類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testJksProvider

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Test
public void testJksProvider() throws Exception {
  Configuration conf = new Configuration();
  final Path jksPath = new Path(tmpDir.toString(), "test.jks");
  final String ourUrl =
      JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();

  File file = new File(tmpDir, "test.jks");
  file.delete();
  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);
  checkSpecificProvider(conf, ourUrl);
  Path path = ProviderUtils.unnestUri(new URI(ourUrl));
  FileSystem fs = path.getFileSystem(conf);
  FileStatus s = fs.getFileStatus(path);
  assertTrue(s.getPermission().toString().equals("rwx------"));
  assertTrue(file + " should exist", file.isFile());

  // check permission retention after explicit change
  fs.setPermission(path, new FsPermission("777"));
  checkPermissionRetention(conf, ourUrl, path);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:22,代碼來源:TestCredentialProviderFactory.java

示例2: getFileStatus

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
/**
 * Convert the file information in LsEntry to a {@link FileStatus} object. *
 *
 * @param sftpFile
 * @param parentPath
 * @return file status
 * @throws IOException
 */
private FileStatus getFileStatus(ChannelSftp channel, LsEntry sftpFile,
    Path parentPath) throws IOException {

  SftpATTRS attr = sftpFile.getAttrs();
  long length = attr.getSize();
  boolean isDir = attr.isDir();
  boolean isLink = attr.isLink();
  if (isLink) {
    String link = parentPath.toUri().getPath() + "/" + sftpFile.getFilename();
    try {
      link = channel.realpath(link);

      Path linkParent = new Path("/", link);

      FileStatus fstat = getFileStatus(channel, linkParent);
      isDir = fstat.isDirectory();
      length = fstat.getLen();
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
  int blockReplication = 1;
  // Using default block size since there is no way in SFTP channel to know of
  // block sizes on server. The assumption could be less than ideal.
  long blockSize = DEFAULT_BLOCK_SIZE;
  long modTime = attr.getMTime() * 1000; // convert to milliseconds
  long accessTime = 0;
  FsPermission permission = getPermissions(sftpFile);
  // not be able to get the real user group name, just use the user and group
  // id
  String user = Integer.toString(attr.getUId());
  String group = Integer.toString(attr.getGId());
  Path filePath = new Path(parentPath, sftpFile.getFilename());

  return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
      accessTime, permission, user, group, filePath.makeQualified(
          this.getUri(), this.getWorkingDirectory()));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:47,代碼來源:SFTPFileSystem.java

示例3: createOutputPath

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
/**
 * Create the output folder and optionally set ownership.
 */
private void createOutputPath(final Path path) throws IOException {
  if (filesUser == null && filesGroup == null) {
    outputFs.mkdirs(path);
  } else {
    Path parent = path.getParent();
    if (!outputFs.exists(parent) && !parent.isRoot()) {
      createOutputPath(parent);
    }
    outputFs.mkdirs(path);
    if (filesUser != null || filesGroup != null) {
      // override the owner when non-null user/group is specified
      outputFs.setOwner(path, filesUser, filesGroup);
    }
    if (filesMode > 0) {
      outputFs.setPermission(path, new FsPermission(filesMode));
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:ExportSnapshot.java

示例4: mkdirs

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
/**
 * @param permission Currently ignored.
 */
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
  Path absolutePath = makeAbsolute(path);
  List<Path> paths = new ArrayList<Path>();
  do {
    paths.add(0, absolutePath);
    absolutePath = absolutePath.getParent();
  } while (absolutePath != null);
  
  boolean result = true;
  for (Path p : paths) {
    result &= mkdir(p);
  }
  return result;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:S3FileSystem.java

示例5: ChecksumFSOutputSummer

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
public ChecksumFSOutputSummer(ChecksumFileSystem fs, 
                      Path file, 
                      boolean overwrite,
                      int bufferSize,
                      short replication,
                      long blockSize,
                      Progressable progress,
                      FsPermission permission)
  throws IOException {
  super(DataChecksum.newDataChecksum(DataChecksum.Type.CRC32,
      fs.getBytesPerSum()));
  int bytesPerSum = fs.getBytesPerSum();
  this.datas = fs.getRawFileSystem().create(file, permission, overwrite,
                                     bufferSize, replication, blockSize,
                                     progress);
  int sumBufferSize = fs.getSumBufferSize(bytesPerSum, bufferSize);
  this.sums = fs.getRawFileSystem().create(fs.getChecksumFile(file),
                                           permission, true, sumBufferSize,
                                           replication, blockSize, null);
  sums.write(CHECKSUM_VERSION, 0, CHECKSUM_VERSION.length);
  sums.writeInt(bytesPerSum);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:ChecksumFileSystem.java

示例6: testGlobStatusWithNoMatchesInPath

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Test
public void testGlobStatusWithNoMatchesInPath() throws Exception {
  Path[] testDirs = {
      getTestRootPath(fc, TEST_DIR_AAA),
      getTestRootPath(fc, TEST_DIR_AXA),
      getTestRootPath(fc, TEST_DIR_AXX),
      getTestRootPath(fc, TEST_DIR_AAA2), };

  if (exists(fc, testDirs[0]) == false) {
    for (Path path : testDirs) {
      fc.mkdir(path, FsPermission.getDefault(), true);
    }
  }

  // should return nothing
  FileStatus[] paths = fc.util().globStatus(
      getTestRootPath(fc, "test/hadoop/?"));
  Assert.assertEquals(0, paths.length);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:FileContextMainOperationsBaseTest.java

示例7: testSetPermission

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Test
public void testSetPermission() throws IOException {
  if (Path.WINDOWS) {
    System.out.println("Cannot run test for Windows");
    return;
  }

  String filename = "foo";
  Path f = fileContextTestHelper.getTestRootPath(fc, filename);
  createFile(fc, f);

  try {
    // create files and manipulate them.
    FsPermission all = new FsPermission((short)0777);
    FsPermission none = new FsPermission((short)0);

    fc.setPermission(f, none);
    doFilePermissionCheck(none, fc.getFileStatus(f).getPermission());

    fc.setPermission(f, all);
    doFilePermissionCheck(all, fc.getFileStatus(f).getPermission());
  }
  finally {cleanupFile(fc, f);}
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:FileContextPermissionBase.java

示例8: testRemoveAclEntriesOnlyAccess

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Test
public void testRemoveAclEntriesOnlyAccess() throws IOException {
  fs.create(path).close();
  fs.setPermission(path, FsPermission.createImmutable((short)0640));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, USER, "bar", READ_WRITE),
    aclEntry(ACCESS, GROUP, READ_WRITE),
    aclEntry(ACCESS, OTHER, NONE));
  fs.setAcl(path, aclSpec);
  aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, "foo"));
  fs.removeAclEntries(path, aclSpec);
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "bar", READ_WRITE),
    aclEntry(ACCESS, GROUP, READ_WRITE) }, returned);
  assertPermission((short)010760);
  assertAclFeature(true);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:FSAclBaseTest.java

示例9: primitiveMkdir

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
/**
 * This version of the mkdirs method assumes that the permission is absolute.
 * It has been added to support the FileContext that processes the permission
 * with umask before calling this method.
 * This a temporary method added to support the transition from FileSystem
 * to FileContext for user applications.
 */
@Deprecated
protected void primitiveMkdir(Path f, FsPermission absolutePermission, 
                  boolean createParent)
  throws IOException {
  
  if (!createParent) { // parent must exist.
    // since the this.mkdirs makes parent dirs automatically
    // we must throw exception if parent does not exist.
    final FileStatus stat = getFileStatus(f.getParent());
    if (stat == null) {
      throw new FileNotFoundException("Missing parent:" + f);
    }
    if (!stat.isDirectory()) {
      throw new ParentNotDirectoryException("parent is not a dir");
    }
    // parent does exist - go ahead with mkdir of leaf
  }
  // Default impl is to assume that permissions do not matter and hence
  // calling the regular mkdirs is good enough.
  // FSs that implement permissions should override this.
  if (!this.mkdirs(f, absolutePermission)) {
    throw new IOException("mkdir of "+ f + " failed");
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:32,代碼來源:FileSystem.java

示例10: checkAccessPermissions

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
/**
 * This method provides the default implementation of
 * {@link #access(Path, FsAction)}.
 *
 * @param stat FileStatus to check
 * @param mode type of access to check
 * @throws IOException for any error
 */
@InterfaceAudience.Private
static void checkAccessPermissions(FileStatus stat, FsAction mode)
    throws IOException {
  FsPermission perm = stat.getPermission();
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  String user = ugi.getShortUserName();
  List<String> groups = Arrays.asList(ugi.getGroupNames());
  if (user.equals(stat.getOwner())) {
    if (perm.getUserAction().implies(mode)) {
      return;
    }
  } else if (groups.contains(stat.getGroup())) {
    if (perm.getGroupAction().implies(mode)) {
      return;
    }
  } else {
    if (perm.getOtherAction().implies(mode)) {
      return;
    }
  }
  throw new AccessControlException(String.format(
    "Permission denied: user=%s, path=\"%s\":%s:%s:%s%s", user, stat.getPath(),
    stat.getOwner(), stat.getGroup(), stat.isDirectory() ? "d" : "-", perm));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:33,代碼來源:FileSystem.java

示例11: setUpLocalFS

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Before
public void setUpLocalFS() throws IOException {
  final FileStatus rootStatus = new FileStatus(4096, true, 0, 0, 37, 42, FsPermission.createImmutable((short) 0555), "root", "wheel", new Path("sabot://10.0.0.1:1234/"));
  final FileStatus fooStatus = new FileStatus(38214, true, 0, 0, 45, 67, FsPermission.createImmutable((short) 0755), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo"));
  final FileStatus fooBarStatus = new FileStatus(67128, true, 1, 4096, 69, 68, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar"));
  final FileStatus fooBarDirStatus = new FileStatus(47, true, 0, 0, 1234, 3645, FsPermission.createImmutable((short) 0755), "admin", "admin", new Path("sabot://10.0.0.1:1234/foo/bar/dir"));
  final FileStatus fooBarFile1Status = new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar/file1"));
  final FileStatus fooBarFile2Status = new FileStatus(2048, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar/file2"));

  doReturn(rootStatus).when(mockLocalFS).getFileStatus(new Path("/"));
  doThrow(new FileNotFoundException()).when(mockLocalFS).getFileStatus(any(Path.class));
  doReturn(fooBarFile2Status).when(mockLocalFS).getFileStatus(new Path("/foo/bar/file2"));
  doReturn(fooBarFile1Status).when(mockLocalFS).getFileStatus(new Path("/foo/bar/file1"));
  doReturn(fooBarDirStatus).when(mockLocalFS).getFileStatus(new Path("/foo/bar/dir"));
  doReturn(fooBarStatus).when(mockLocalFS).getFileStatus(new Path("/foo/bar"));
  doReturn(fooStatus).when(mockLocalFS).getFileStatus(new Path("/foo"));
  doReturn(rootStatus).when(mockLocalFS).getFileStatus(new Path("/"));

  doThrow(new FileNotFoundException()).when(mockLocalFS).listStatus(any(Path.class));
  doReturn(new FileStatus[] { fooBarDirStatus, fooBarFile1Status, fooBarFile2Status }).when(mockLocalFS).listStatus(new Path("/foo/bar"));
  doReturn(new FileStatus[] { fooBarStatus }).when(mockLocalFS).listStatus(new Path("/foo"));
  doReturn(new FileStatus[] { fooStatus }).when(mockLocalFS).listStatus(new Path("/"));
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:24,代碼來源:TestPseudoDistributedFileSystem.java

示例12: processPath

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Override
protected void processPath(PathData item) throws IOException {
  out.println("# file: " + item);
  out.println("# owner: " + item.stat.getOwner());
  out.println("# group: " + item.stat.getGroup());
  FsPermission perm = item.stat.getPermission();
  if (perm.getStickyBit()) {
    out.println("# flags: --" +
      (perm.getOtherAction().implies(FsAction.EXECUTE) ? "t" : "T"));
  }

  AclStatus aclStatus = item.fs.getAclStatus(item.path);
  List<AclEntry> entries = perm.getAclBit() ? aclStatus.getEntries()
      : Collections.<AclEntry> emptyList();
  ScopedAclEntries scopedEntries = new ScopedAclEntries(
    AclUtil.getAclFromPermAndEntries(perm, entries));
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getAccessEntries());
  printAclEntriesForSingleScope(aclStatus, perm,
      scopedEntries.getDefaultEntries());
  out.println();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:AclCommands.java

示例13: testSetPermission

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@Test
public void testSetPermission() throws IOException {
  FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750));
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(ACCESS, USER, ALL),
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(ACCESS, OTHER, NONE),
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(path, aclSpec);
  fs.setPermission(path, FsPermission.createImmutable((short)0700));
  AclStatus s = fs.getAclStatus(path);
  AclEntry[] returned = s.getEntries().toArray(new AclEntry[0]);
  assertArrayEquals(new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, NONE) }, returned);
  assertPermission((short)010700);
  assertAclFeature(true);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:FSAclBaseTest.java

示例14: mockCreate

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static void mockCreate(ClientProtocol mcp,
    CipherSuite suite, CryptoProtocolVersion version) throws Exception {
  Mockito.doReturn(
      new HdfsFileStatus(0, false, 1, 1024, 0, 0, new FsPermission(
          (short) 777), "owner", "group", new byte[0], new byte[0],
          1010, 0, new FileEncryptionInfo(suite,
          version, new byte[suite.getAlgorithmBlockSize()],
          new byte[suite.getAlgorithmBlockSize()],
          "fakeKey", "fakeVersion"),
          (byte) 0))
      .when(mcp)
      .create(anyString(), (FsPermission) anyObject(), anyString(),
          (EnumSetWritable<CreateFlag>) anyObject(), anyBoolean(),
          anyShort(), anyLong(), (CryptoProtocolVersion[]) anyObject());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestEncryptionZones.java

示例15: loadAndReturnPerm

import org.apache.hadoop.fs.permission.FsPermission; //導入依賴的package包/類
private FsPermission loadAndReturnPerm(Path pathToLoad, Path pathToDelete)
    throws NoSuchAlgorithmException, CertificateException,
    IOException {
  FsPermission perm = null;
  try {
    perm = loadFromPath(pathToLoad, password);
    renameOrFail(pathToLoad, path);
    if (LOG.isDebugEnabled()) {
      LOG.debug(String.format("KeyStore loaded successfully from '%s'!!",
          pathToLoad));
    }
    if (fs.exists(pathToDelete)) {
      fs.delete(pathToDelete, true);
    }
  } catch (IOException e) {
    // Check for password issue : don't want to trash file due
    // to wrong password
    if (isBadorWrongPassword(e)) {
      throw e;
    }
  }
  return perm;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:24,代碼來源:JavaKeyStoreProvider.java


注:本文中的org.apache.hadoop.fs.permission.FsPermission類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。