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

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

Introduction

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

Prototype

public long getAccessTime() 

Source Link

Document

Get the access time of the file.

Usage

From source file:org.apache.ignite.igfs.HadoopIgfs20FileSystemAbstractSelfTest.java

License:Apache License

/** @throws Exception If failed. */
public void testTimes() throws Exception {
    Path file = new Path("/file1");

    long now = System.currentTimeMillis();

    try (FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class),
            Options.CreateOpts.perms(FsPermission.getDefault()))) {
        os.write(new byte[1024 * 1024]);
    }//w  w  w . ja v  a2  s  . c  o m

    FileStatus status = fs.getFileStatus(file);

    assertTrue(status.getAccessTime() >= now);
    assertTrue(status.getModificationTime() >= now);

    long accessTime = now - 10 * 60 * 1000;
    long modificationTime = now - 5 * 60 * 1000;

    fs.setTimes(file, modificationTime, accessTime);

    status = fs.getFileStatus(file);
    assertEquals(accessTime, status.getAccessTime());
    assertEquals(modificationTime, status.getModificationTime());

    // Check listing is updated as well.
    FileStatus[] files = fs.listStatus(new Path("/"));

    assertEquals(1, files.length);

    assertEquals(file.getName(), files[0].getPath().getName());
    assertEquals(accessTime, files[0].getAccessTime());
    assertEquals(modificationTime, files[0].getModificationTime());

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            fs.setTimes(new Path("/unknownFile"), 0, 0);

            return null;
        }
    }, FileNotFoundException.class, null);
}

From source file:org.apache.ignite.igfs.HadoopIgfsSecondaryFileSystemTestAdapter.java

License:Apache License

/** {@inheritDoc} */
@Override//from   w  ww  .j a v a2  s.  co  m
public T2<Long, Long> times(String path) throws IOException {
    FileStatus status = get().getFileStatus(new Path(path));

    return new T2<>(status.getAccessTime(), status.getModificationTime());
}

From source file:org.apache.ignite.igfs.IgfsHadoopFileSystemAbstractSelfTest.java

License:Apache License

/**
 * @throws Exception If failed./*ww w .  j a va2 s . c om*/
 */
public void testSetTimes() throws Exception {
    Path fsHome = new Path(primaryFsUri);
    final Path file = new Path(fsHome, "/heartbeat");

    fs.create(file).close();

    FileStatus status = fs.getFileStatus(file);

    assertTrue(status.getAccessTime() > 0);
    assertTrue(status.getModificationTime() > 0);

    long mtime = System.currentTimeMillis() - 5000;
    long atime = System.currentTimeMillis() - 4000;

    fs.setTimes(file, mtime, atime);

    status = fs.getFileStatus(file);

    assertEquals(mtime, status.getModificationTime());
    assertEquals(atime, status.getAccessTime());

    mtime -= 5000;

    fs.setTimes(file, mtime, -1);

    status = fs.getFileStatus(file);

    assertEquals(mtime, status.getModificationTime());
    assertEquals(atime, status.getAccessTime());

    atime -= 5000;

    fs.setTimes(file, -1, atime);

    status = fs.getFileStatus(file);

    assertEquals(mtime, status.getModificationTime());
    assertEquals(atime, status.getAccessTime());
}

From source file:org.apache.ignite.internal.igfs.hadoop.IgfsHadoopFileSystemWrapper.java

License:Apache License

/** {@inheritDoc} */
@Override//from   w ww. ja v a2  s . com
public IgfsFile info(final IgfsPath path) {
    try {
        final FileStatus status = fileSys.getFileStatus(convert(path));

        if (status == null)
            return null;

        final Map<String, String> props = properties(status);

        return new IgfsFile() {
            @Override
            public IgfsPath path() {
                return path;
            }

            @Override
            public boolean isFile() {
                return status.isFile();
            }

            @Override
            public boolean isDirectory() {
                return status.isDirectory();
            }

            @Override
            public int blockSize() {
                return (int) status.getBlockSize();
            }

            @Override
            public long groupBlockSize() {
                return status.getBlockSize();
            }

            @Override
            public long accessTime() {
                return status.getAccessTime();
            }

            @Override
            public long modificationTime() {
                return status.getModificationTime();
            }

            @Override
            public String property(String name) throws IllegalArgumentException {
                String val = props.get(name);

                if (val == null)
                    throw new IllegalArgumentException(
                            "File property not found [path=" + path + ", name=" + name + ']');

                return val;
            }

            @Nullable
            @Override
            public String property(String name, @Nullable String dfltVal) {
                String val = props.get(name);

                return val == null ? dfltVal : val;
            }

            @Override
            public long length() {
                return status.getLen();
            }

            /** {@inheritDoc} */
            @Override
            public Map<String, String> properties() {
                return props;
            }
        };

    } catch (FileNotFoundException ignore) {
        return null;
    } catch (IOException e) {
        throw handleSecondaryFsError(e, "Failed to get file status [path=" + path + "]");
    }
}

From source file:org.apache.ignite.internal.processors.hadoop.impl.delegate.HadoopIgfsSecondaryFileSystemDelegateImpl.java

License:Apache License

/** {@inheritDoc} */
@Override//from ww  w  .ja v a  2s .c om
public Collection<IgfsFile> listFiles(IgfsPath path) {
    try {
        FileStatus[] statuses = fileSystemForUser().listStatus(convert(path));

        if (statuses == null)
            throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);

        Collection<IgfsFile> res = new ArrayList<>(statuses.length);

        for (FileStatus s : statuses) {
            IgfsEntryInfo fsInfo = s.isDirectory()
                    ? IgfsUtils.createDirectory(IgniteUuid.randomUuid(), null, properties(s), s.getAccessTime(),
                            s.getModificationTime())
                    : IgfsUtils.createFile(IgniteUuid.randomUuid(), (int) s.getBlockSize(), s.getLen(), null,
                            null, false, properties(s), s.getAccessTime(), s.getModificationTime());

            res.add(new IgfsFileImpl(new IgfsPath(path, s.getPath().getName()), fsInfo, 1));
        }

        return res;
    } catch (FileNotFoundException ignored) {
        throw new IgfsPathNotFoundException("Failed to list files (path not found): " + path);
    } catch (IOException e) {
        throw handleSecondaryFsError(e,
                "Failed to list statuses due to secondary file system exception: " + path);
    }
}

From source file:org.apache.ignite.internal.processors.hadoop.impl.delegate.HadoopIgfsSecondaryFileSystemDelegateImpl.java

License:Apache License

/** {@inheritDoc} */
@Override//from w  w w.jav  a  2s .c  o  m
public IgfsFile info(final IgfsPath path) {
    try {
        final FileStatus status = fileSystemForUser().getFileStatus(convert(path));

        if (status == null)
            return null;

        final Map<String, String> props = properties(status);

        return new IgfsFileImpl(new IgfsFile() {
            @Override
            public IgfsPath path() {
                return path;
            }

            @Override
            public boolean isFile() {
                return status.isFile();
            }

            @Override
            public boolean isDirectory() {
                return status.isDirectory();
            }

            @Override
            public int blockSize() {
                // By convention directory has blockSize == 0, while file has blockSize > 0:
                return isDirectory() ? 0 : (int) status.getBlockSize();
            }

            @Override
            public long groupBlockSize() {
                return status.getBlockSize();
            }

            @Override
            public long accessTime() {
                return status.getAccessTime();
            }

            @Override
            public long modificationTime() {
                return status.getModificationTime();
            }

            @Override
            public String property(String name) throws IllegalArgumentException {
                String val = props.get(name);

                if (val == null)
                    throw new IllegalArgumentException(
                            "File property not found [path=" + path + ", name=" + name + ']');

                return val;
            }

            @Nullable
            @Override
            public String property(String name, @Nullable String dfltVal) {
                String val = props.get(name);

                return val == null ? dfltVal : val;
            }

            @Override
            public long length() {
                return status.getLen();
            }

            /** {@inheritDoc} */
            @Override
            public Map<String, String> properties() {
                return props;
            }
        }, 0);
    } catch (FileNotFoundException ignore) {
        return null;
    } catch (IOException e) {
        throw handleSecondaryFsError(e, "Failed to get file status [path=" + path + "]");
    }
}

From source file:org.apache.ignite.internal.processors.hadoop.impl.igfs.HadoopIgfsSecondaryFileSystemTestAdapter.java

License:Apache License

/** {@inheritDoc} */
@Override//w  w  w .j  a  v  a  2  s.  com
public T2<Long, Long> times(String path) throws IOException {
    FileStatus status = get().getFileStatus(new Path(path));

    return new T2<>(status.getModificationTime(), status.getAccessTime());
}

From source file:org.cgc.wfx.impl.FileInformationImpl.java

License:Open Source License

public FileInformationImpl(FileStatus fstatus) {
    boolean isDir = fstatus.isDirectory();
    this.fileAttributes |= FILE_ATTRIBUTE_UNIX_MODE;
    if (isDir) {//from w  w  w  .j av  a2s  .  c  o  m
        this.fileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
    }

    this.fileCreationTime = javaTimeToFileTime(fstatus.getModificationTime());
    this.fileLastAccessTime = javaTimeToFileTime(fstatus.getAccessTime());
    if (isDir == false) {
        this.fileSize = fstatus.getLen();
    } else {
        this.fileSize = 0;
    }
    this.reserved0 = 0;

    if ((this.fileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
        this.reserved0 |= S_IFDIR;
    }
    if (fstatus.isSymlink()) {
        this.reserved0 |= S_IFLNK;
    }
    FsPermission fperm = fstatus.getPermission();
    this.reserved0 |= fsActionToUnixVal(fperm.getUserAction());
    this.reserved0 |= (fsActionToUnixVal(fperm.getGroupAction()) >> 3);
    this.reserved0 |= (fsActionToUnixVal(fperm.getOtherAction()) >> 6);

    this.fileName = fstatus.getPath().getName();

}

From source file:org.elasticsearch.hadoop.mr.NTFSLocalFileSystem.java

License:Apache License

@Override
public FileStatus getFileStatus(Path f) throws IOException {
    // it's the RawFS in place which messes things up as it dynamically returns the permissions...
    // workaround by doing a copy
    FileStatus fs = super.getFileStatus(f);

    // work-around for Hive 0.14
    if (SCRATCH_DIR.equals(f.toString())) {
        System.out.println("Faking scratch dir permissions on Windows...");

        return new FileStatus(fs.getLen(), fs.isDir(), fs.getReplication(), fs.getBlockSize(),
                fs.getModificationTime(), fs.getAccessTime(), SCRATCH_DIR_PERMS, fs.getOwner(), fs.getGroup(),
                fs.getPath());/*from w  ww .ja  v  a  2 s . c  o m*/
        // this doesn't work since the RawFS impl has its own algo that does the lookup dynamically
        //fs.getPermission().fromShort((short) 777);
    }
    return fs;
}

From source file:org.exem.flamingo.agent.nn.hdfs.HdfsFileInfo.java

License:Apache License

public HdfsFileInfo(FileStatus fileStatus, ContentSummary contentSummary) {
    this.fullyQualifiedPath = fileStatus.getPath().toUri().getPath();
    this.filename = isEmpty(getFilename(fullyQualifiedPath)) ? getDirectoryName(fullyQualifiedPath)
            : getFilename(fullyQualifiedPath);
    this.length = fileStatus.isFile() ? fileStatus.getLen() : contentSummary.getLength();
    this.path = getPath(fullyQualifiedPath);
    this.directory = fileStatus.isDirectory();
    this.file = !fileStatus.isDirectory();
    this.owner = fileStatus.getOwner();
    this.group = fileStatus.getGroup();
    this.blockSize = fileStatus.getBlockSize();
    this.replication = fileStatus.getReplication();
    this.modificationTime = fileStatus.getModificationTime();
    if (contentSummary != null) {
        this.spaceConsumed = contentSummary.getSpaceConsumed();
        this.spaceQuota = contentSummary.getSpaceQuota();
        this.quota = contentSummary.getQuota();
        this.directoryCount = contentSummary.getDirectoryCount();
        this.fileCount = contentSummary.getFileCount();
    }//  w ww  . jav a2s  . c  om
    this.accessTime = fileStatus.getAccessTime();
    this.permission = fileStatus.getPermission().toString();
}