List of usage examples for org.apache.hadoop.fs FileStatus getOwner
public String getOwner()
From source file:gobblin.data.management.copy.writer.TarArchiveInputStreamDataWriterTest.java
License:Apache License
/** * Find the test compressed file <code><filePath/code> in classpath and read it as a {@link FileAwareInputStream} *//*from w w w . j a v a 2s. co m*/ private FileAwareInputStream getCompressedInputStream(final String filePath, final String newFileName) throws Exception { UnGzipConverter converter = new UnGzipConverter(); FileSystem fs = FileSystem.getLocal(new Configuration()); String fullPath = getClass().getClassLoader().getResource(filePath).getFile(); FileStatus status = fs.getFileStatus(testTempPath); OwnerAndPermission ownerAndPermission = new OwnerAndPermission(status.getOwner(), status.getGroup(), new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL)); CopyableFile cf = CopyableFileUtils.getTestCopyableFile(filePath, new Path(testTempPath, newFileName).toString(), newFileName, ownerAndPermission); FileAwareInputStream fileAwareInputStream = new FileAwareInputStream(cf, fs.open(new Path(fullPath))); Iterable<FileAwareInputStream> iterable = converter.convertRecord("outputSchema", fileAwareInputStream, new WorkUnitState()); return Iterables.getFirst(iterable, null); }
From source file:gobblin.data.management.retention.action.AccessControlAction.java
License:Apache License
private boolean needsOwnerUpdate(FileStatus fileStatus) { return this.owner.isPresent() && !StringUtils.equals(owner.get(), fileStatus.getOwner()); }
From source file:gobblin.util.filesystem.InstrumentedFileSystemUtils.java
License:Apache License
/** * Replace the scheme of the input {@link FileStatus} if it matches the string to replace. */// ww w .j av a 2 s .c om public static FileStatus replaceScheme(FileStatus st, String replace, String replacement) { if (replace != null && replace.equals(replacement)) { return st; } try { return new FileStatus(st.getLen(), st.isDir(), st.getReplication(), st.getBlockSize(), st.getModificationTime(), st.getAccessTime(), st.getPermission(), st.getOwner(), st.getGroup(), st.isSymlink() ? st.getSymlink() : null, replaceScheme(st.getPath(), replace, replacement)); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:hadoop.example.hdfs.ShowFileStatusTestCase.java
License:Open Source License
@Test public void fileStatusForFile() throws IOException { Path file = new Path("/dir/file"); FileStatus stat = fs.getFileStatus(file); Assert.assertEquals("/dir/file", stat.getPath().toUri().getPath()); Assert.assertFalse(stat.isDir());/*from www . ja v a 2 s .c o m*/ Assert.assertEquals(stat.getLen(), 7L); Assert.assertEquals(stat.getReplication(), 1); Assert.assertEquals(stat.getBlockSize(), 64 * 1024 * 1024L); Assert.assertEquals(stat.getOwner(), "haint"); Assert.assertEquals(stat.getGroup(), "supergroup"); Assert.assertEquals(stat.getPermission().toString(), "rw-r--r--"); }
From source file:hadoop.example.hdfs.ShowFileStatusTestCase.java
License:Open Source License
@Test public void fileStatusForDirectory() throws IOException { Path dir = new Path("/dir"); FileStatus stat = fs.getFileStatus(dir); Assert.assertTrue(stat.isDir());//from w w w . j a va 2 s .co m Assert.assertEquals(stat.getLen(), 0L); Assert.assertEquals(stat.getReplication(), 0L); Assert.assertEquals(stat.getBlockSize(), 0L); Assert.assertEquals(stat.getOwner(), "haint"); Assert.assertEquals(stat.getGroup(), "supergroup"); Assert.assertEquals(stat.getPermission().toString(), "rwxr-xr-x"); }
From source file:hdfs.jsr203.attribute.HadoopFileAttributeView.java
License:Apache License
Object attribute(AttrID id, FileStatus hfas) { switch (id) { case accessTime: return hfas.getAccessTime(); case blockSize: return hfas.getBlockSize(); case group:/* ww w . j ava 2 s . c om*/ return hfas.getGroup(); case len: return hfas.getLen(); case modificationTime: return hfas.getModificationTime(); case owner: return hfas.getOwner(); case replication: return hfas.getReplication(); case isDirectory: return hfas.isDirectory(); // TODO enable encryption //case isEncrypted: // return hfas.isEncrypted(); case isFile: return hfas.isFile(); case isSymLink: return hfas.isSymlink(); } return null; }
From source file:hdfs.jsr203.attribute.HadoopFileOwnerAttributeView.java
License:Apache License
@Override public UserPrincipal getOwner() throws IOException { try {/*from w w w. j av a2 s.c o m*/ UserPrincipalLookupService ls = this.path.getFileSystem().getUserPrincipalLookupService(); FileStatus fileStatus = path.getFileSystem().getHDFS().getFileStatus(path.getRawResolvedPath()); return ls.lookupPrincipalByName(fileStatus.getOwner()); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:hdfs.jsr203.HadoopFileOwnerAttributeView.java
License:Apache License
@Override public UserPrincipal getOwner() throws IOException { UserPrincipalLookupService ls = this.path.getFileSystem().getUserPrincipalLookupService(); FileStatus fileStatus = path.getFileSystem().getHDFS().getFileStatus(path.getRawResolvedPath()); return ls.lookupPrincipalByName(fileStatus.getOwner()); }
From source file:hdfs.jsr203.HadoopPosixFileAttributes.java
License:Apache License
public HadoopPosixFileAttributes(HadoopFileSystem hdfs, Object fileKey, FileStatus fileStatus) throws IOException { super(fileKey, fileStatus); this.owner = hdfs.getUserPrincipalLookupService().lookupPrincipalByGroupName(fileStatus.getOwner()); this.group = hdfs.getUserPrincipalLookupService().lookupPrincipalByGroupName(fileStatus.getGroup()); FsPermission fsPermission = getFileStatus().getPermission(); String perms = fsPermission.getUserAction().SYMBOL + fsPermission.getGroupAction().SYMBOL + fsPermission.getOtherAction().SYMBOL; this.permissions = PosixFilePermissions.fromString(perms); }
From source file:io.aos.hdfs.ShowFileStatusTest.java
License:Apache License
@Test public void fileStatusForFile() throws IOException { Path file = new Path("/dir/file"); FileStatus stat = fs.getFileStatus(file); assertThat(stat.getPath().toUri().getPath(), is("/dir/file")); assertThat(stat.isDir(), is(false)); assertThat(stat.getLen(), is(7L));/*from w w w.j a va 2s .c om*/ assertThat(stat.getModificationTime(), is(lessThanOrEqualTo(System.currentTimeMillis()))); assertThat(stat.getReplication(), is((short) 1)); assertThat(stat.getBlockSize(), is(64 * 1024 * 1024L)); assertThat(stat.getOwner(), is("tom")); assertThat(stat.getGroup(), is("supergroup")); assertThat(stat.getPermission().toString(), is("rw-r--r--")); }