Example usage for org.apache.hadoop.fs FileStatus FileStatus

List of usage examples for org.apache.hadoop.fs FileStatus FileStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileStatus FileStatus.

Prototype

public FileStatus(long length, boolean isdir, int block_replication, long blocksize, long modification_time,
        long access_time, FsPermission permission, String owner, String group, Path path) 

Source Link

Document

Constructor for file systems on which symbolic links are not supported

Usage

From source file:gobblin.source.extractor.extract.sftp.SftpLightWeightFileSystem.java

License:Apache License

@Override
public FileStatus getFileStatus(Path path) throws IOException {
    ChannelSftp channelSftp = null;/*w w w. ja v  a2s .  c  om*/
    ChannelExec channelExec1 = null;
    ChannelExec channelExec2 = null;
    try {
        channelSftp = this.fsHelper.getSftpChannel();
        SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path));
        FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions());

        channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId());
        String userName = IOUtils.toString(channelExec1.getInputStream());

        channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId());
        String groupName = IOUtils.toString(channelExec2.getInputStream());

        FileStatus fs = new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(),
                sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName),
                StringUtils.trimToEmpty(groupName), path);

        return fs;
    } catch (SftpException e) {
        throw new IOException(e);
    } finally {
        safeDisconnect(channelSftp);
        safeDisconnect(channelExec1);
        safeDisconnect(channelExec2);
    }

}

From source file:io.confluent.connect.hdfs.utils.MemoryStorage.java

License:Apache License

@Override
public FileStatus[] listStatus(String path) throws IOException {
    List<FileStatus> result = new ArrayList<>();
    for (String key : data.keySet()) {
        if (key.startsWith(path)) {
            FileStatus status = new FileStatus(data.get(key).size(), false, 1, 0, 0, 0, null, null, null,
                    new Path(key));
            result.add(status);// ww w  . j  ava 2s  . c o  m
        }
    }
    return result.toArray(new FileStatus[result.size()]);
}

From source file:io.confluent.connect.hdfs.utils.MemoryStorage.java

License:Apache License

@Override
public FileStatus[] listStatus(String path, PathFilter filter) throws IOException {
    if (failure == Failure.listStatusFailure) {
        failure = Failure.noFailure;/*from  www .ja v a 2  s.c om*/
        throw new IOException("listStatus failed.");
    }
    List<FileStatus> result = new ArrayList<>();
    for (String key : data.keySet()) {
        if (key.startsWith(path) && filter.accept(new Path(key))) {
            FileStatus status = new FileStatus(data.get(key).size(), false, 1, 0, 0, 0, null, null, null,
                    new Path(key));
            result.add(status);
        }
    }
    return result.toArray(new FileStatus[result.size()]);
}

From source file:org.apache.accumulo.master.metrics.Metrics2ReplicationMetricsTest.java

License:Apache License

private FileStatus createStatus(long modtime) {
    return new FileStatus(0, false, 0, 0, modtime, 0, null, null, null, null);
}

From source file:org.apache.falcon.hadoop.JailedFileSystem.java

License:Apache License

@Override
public FileStatus[] listStatus(Path f) throws IOException {
    FileStatus[] fileStatuses = localFS.listStatus(toLocalPath(f));
    if (fileStatuses == null || fileStatuses.length == 0) {
        return fileStatuses;
    } else {//from  w  w w  .  j a  v a2s . c o m
        FileStatus[] jailFileStatuses = new FileStatus[fileStatuses.length];
        for (int index = 0; index < fileStatuses.length; index++) {
            FileStatus status = fileStatuses[index];
            jailFileStatuses[index] = new FileStatus(status.getLen(), status.isDirectory(),
                    status.getReplication(), status.getBlockSize(), status.getModificationTime(),
                    status.getAccessTime(), status.getPermission(), status.getOwner(), status.getGroup(),
                    fromLocalPath(status.getPath()).makeQualified(this.getUri(), this.getWorkingDirectory()));
        }
        return jailFileStatuses;
    }
}

From source file:org.apache.falcon.hadoop.JailedFileSystem.java

License:Apache License

@Override
public FileStatus getFileStatus(Path f) throws IOException {
    FileStatus status = localFS.getFileStatus(toLocalPath(f));
    if (status == null) {
        return null;
    }//from  w  ww . j  a  v  a2  s .  co  m
    return new FileStatus(status.getLen(), status.isDirectory(), status.getReplication(), status.getBlockSize(),
            status.getModificationTime(), status.getAccessTime(), status.getPermission(), status.getOwner(),
            status.getGroup(),
            fromLocalPath(status.getPath()).makeQualified(this.getUri(), this.getWorkingDirectory()));
}

From source file:org.apache.gobblin.data.management.copy.CopyableFileTest.java

License:Apache License

@Test
public void testResolveOwnerAndPermission() throws Exception {

    Path path = new Path("/test/path");

    FileStatus fileStatus = new FileStatus(1, false, 0, 0, 0, 0, FsPermission.getDefault(), "owner", "group",
            path);//from   w  w w .  j  av  a 2s  .  c  o m

    FileSystem fs = mock(FileSystem.class);
    Mockito.doReturn(fileStatus).when(fs).getFileStatus(path);
    Mockito.doReturn(path).when(fs).makeQualified(path);
    Mockito.doReturn(new URI("hdfs://uri")).when(fs).getUri();

    Properties properties = new Properties();
    properties.put(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, "/final/dir");

    OwnerAndPermission ownerAndPermission = CopyableFile.resolveReplicatedOwnerAndPermission(fs, path,
            new CopyConfiguration.CopyConfigurationBuilder(fs, properties).build());
    Assert.assertEquals(ownerAndPermission.getOwner(), null);
    Assert.assertEquals(ownerAndPermission.getGroup(), null);
    Assert.assertEquals(ownerAndPermission.getFsPermission(), null);

    ownerAndPermission = CopyableFile.resolveReplicatedOwnerAndPermission(fs, path,
            new CopyConfiguration.CopyConfigurationBuilder(fs, properties).targetGroup(Optional.of("target"))
                    .build());
    Assert.assertEquals(ownerAndPermission.getOwner(), null);
    Assert.assertEquals(ownerAndPermission.getGroup(), "target");
    Assert.assertEquals(ownerAndPermission.getFsPermission(), null);

    ownerAndPermission = CopyableFile.resolveReplicatedOwnerAndPermission(fs, path,
            new CopyConfiguration.CopyConfigurationBuilder(fs, properties).targetGroup(Optional.of("target"))
                    .preserve(PreserveAttributes.fromMnemonicString("ug")).build());
    Assert.assertEquals(ownerAndPermission.getOwner(), "owner");
    Assert.assertEquals(ownerAndPermission.getGroup(), "target");
    Assert.assertEquals(ownerAndPermission.getFsPermission(), null);

    ownerAndPermission = CopyableFile.resolveReplicatedOwnerAndPermission(fs, path,
            new CopyConfiguration.CopyConfigurationBuilder(fs, properties)
                    .preserve(PreserveAttributes.fromMnemonicString("ug")).build());
    Assert.assertEquals(ownerAndPermission.getOwner(), "owner");
    Assert.assertEquals(ownerAndPermission.getGroup(), "group");
    Assert.assertEquals(ownerAndPermission.getFsPermission(), null);

    ownerAndPermission = CopyableFile.resolveReplicatedOwnerAndPermission(fs, path,
            new CopyConfiguration.CopyConfigurationBuilder(fs, properties)
                    .preserve(PreserveAttributes.fromMnemonicString("ugp")).build());
    Assert.assertEquals(ownerAndPermission.getOwner(), "owner");
    Assert.assertEquals(ownerAndPermission.getGroup(), "group");
    Assert.assertEquals(ownerAndPermission.getFsPermission(), FsPermission.getDefault());

}

From source file:org.apache.hive.common.util.MockFileSystem.java

License:Apache License

public void touch(MockFile file) {
    if (fileStatusMap.containsKey(file)) {
        FileStatus fileStatus = fileStatusMap.get(file);
        FileStatus fileStatusNew = new FileStatus(fileStatus.getLen(), fileStatus.isDirectory(),
                fileStatus.getReplication(), fileStatus.getBlockSize(), fileStatus.getModificationTime() + 1,
                fileStatus.getAccessTime(), fileStatus.getPermission(), fileStatus.getOwner(),
                fileStatus.getGroup(), fileStatus.getPath());
        fileStatusMap.put(file, fileStatusNew);
    }//from w  w w .  ja  v  a  2  s .  c  o m
}

From source file:org.apache.hive.common.util.MockFileSystem.java

License:Apache License

private FileStatus createStatus(MockFile file) {
    if (fileStatusMap.containsKey(file)) {
        return fileStatusMap.get(file);
    }/*from  ww  w  . j a  v  a  2s  . c o  m*/
    FileStatus fileStatus = new FileStatus(file.length, false, 1, file.blockSize, 0, 0,
            FsPermission.createImmutable((short) 644), "owen", "group", file.path);
    fileStatusMap.put(file, fileStatus);
    return fileStatus;
}

From source file:org.apache.hive.common.util.MockFileSystem.java

License:Apache License

private FileStatus createDirectory(Path dir) {
    return new FileStatus(0, true, 0, 0, 0, 0, FsPermission.createImmutable((short) 755), "owen", "group", dir);
}