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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations