Search in sources :

Example 36 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class SetTtlCommandTest method setTtlWithFree.

@Test
public void setTtlWithFree() throws Exception {
    String filePath = "/testFile";
    FileSystemTestUtils.createByteFile(mFileSystem, filePath, WriteType.MUST_CACHE, 1);
    Assert.assertEquals(Constants.NO_TTL, mFileSystem.getStatus(new AlluxioURI("/testFile")).getTtl());
    AlluxioURI uri = new AlluxioURI("/testFile");
    long ttl = 1000L;
    Assert.assertEquals(0, mFsShell.run("setTtl", "-action", "free", filePath, String.valueOf(ttl)));
    URIStatus status = mFileSystem.getStatus(uri);
    Assert.assertEquals(ttl, status.getTtl());
    Assert.assertEquals(TtlAction.FREE, status.getTtlAction());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 37 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class TouchCommandTest method touch.

@Test
public void touch() throws IOException, AlluxioException {
    String[] argv = new String[] { "touch", "/testFile" };
    mFsShell.run(argv);
    URIStatus status = mFileSystem.getStatus(new AlluxioURI("/testFile"));
    Assert.assertNotNull(status);
    Assert.assertEquals(getCommandOutput(argv), mOutput.toString());
    Assert.assertFalse(status.isFolder());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 38 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class TouchCommandTest method touchTestWithFullURI.

@Test
public void touchTestWithFullURI() throws IOException, AlluxioException {
    String alluxioURI = "alluxio://" + mLocalAlluxioCluster.getHostname() + ":" + mLocalAlluxioCluster.getMasterRpcPort() + "/destFileURI";
    // when
    String[] argv = new String[] { "touch", alluxioURI };
    mFsShell.run(argv);
    // then
    URIStatus status = mFileSystem.getStatus(new AlluxioURI("/destFileURI"));
    Assert.assertNotNull(status);
    Assert.assertEquals(getCommandOutput(argv), mOutput.toString());
    Assert.assertFalse(status.isFolder());
}
Also used : URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 39 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method getattr.

/**
   * Retrieves file attributes.
   *
   * @param path The path on the FS of the file
   * @param stat FUSE data structure to fill with file attrs
   * @return 0 on success, negative value on error
   */
@Override
public int getattr(String path, FileStat stat) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
    try {
        if (!mFileSystem.exists(turi)) {
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        stat.st_size.set(status.getLength());
        final long ctime_sec = status.getLastModificationTimeMs() / 1000;
        //keeps only the "residual" nanoseconds not caputred in
        // citme_sec
        final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
        stat.st_ctim.tv_sec.set(ctime_sec);
        stat.st_ctim.tv_nsec.set(ctime_nsec);
        stat.st_mtim.tv_sec.set(ctime_sec);
        stat.st_mtim.tv_nsec.set(ctime_nsec);
        // TODO(andreareale): understand how to map FileInfo#getOwner()
        // and FileInfo#getGroup() to UIDs and GIDs of the node
        // where alluxio-fuse is mounted.
        // While this is not done, just use uid and gid of the user
        // running alluxio-fuse.
        stat.st_uid.set(UID_AND_GID[0]);
        stat.st_gid.set(UID_AND_GID[1]);
        final int mode;
        if (status.isFolder()) {
            mode = FileStat.S_IFDIR;
        } else {
            mode = FileStat.S_IFREG;
        }
        stat.st_mode.set(mode);
    } catch (InvalidPathException e) {
        LOG.debug("Invalid path {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 40 with URIStatus

use of alluxio.client.file.URIStatus in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method rmInternal.

/**
   * Convenience internal method to remove files or directories.
   *
   * @param path The path to remove
   * @param mustBeFile When true, returns an error when trying to
   *                   remove a directory
   * @return 0 on success, a negative value on error
   */
private int rmInternal(String path, boolean mustBeFile) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    try {
        if (!mFileSystem.exists(turi)) {
            LOG.error("File {} does not exist", turi);
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        if (mustBeFile && status.isFolder()) {
            LOG.error("File {} is a directory", turi);
            return -ErrorCodes.EISDIR();
        }
        mFileSystem.delete(turi);
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

URIStatus (alluxio.client.file.URIStatus)119 AlluxioURI (alluxio.AlluxioURI)111 Test (org.junit.Test)78 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)23 IOException (java.io.IOException)19 FileInStream (alluxio.client.file.FileInStream)17 ArrayList (java.util.ArrayList)15 AlluxioException (alluxio.exception.AlluxioException)13 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)13 AlluxioShellUtilsTest (alluxio.shell.AlluxioShellUtilsTest)12 FileInfo (alluxio.wire.FileInfo)12 File (java.io.File)10 FileOutStream (alluxio.client.file.FileOutStream)9 FileSystem (alluxio.client.file.FileSystem)7 InvalidPathException (alluxio.exception.InvalidPathException)7 ByteBuffer (java.nio.ByteBuffer)7 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)6 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)5 UnderFileSystem (alluxio.underfs.UnderFileSystem)5