use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class PersistMultipleMountsIntegrationTest method syncMultipleMountsMountedPersist.
@Test
public void syncMultipleMountsMountedPersist() throws Exception {
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
String path = PathUtils.uniqPath();
AlluxioURI filePath = new AlluxioURI(MOUNT_PATH + path);
FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH));
os.write((byte) 0);
os.write((byte) 1);
os.close();
// Check the file is persisted
URIStatus status = mFileSystem.getStatus(filePath);
Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
Assert.assertTrue(status.isCompleted());
Assert.assertFalse(mUfs.exists(PathUtils.concatPath(mUfsRoot, path)));
Assert.assertTrue(mMountedUfs.exists(PathUtils.concatPath(mMountedUfsRoot, path)));
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class CountCommand method countHelper.
private long[] countHelper(AlluxioURI path) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
if (!status.isFolder()) {
return new long[] { 1L, 0L, status.getLength() };
}
long[] rtn = new long[] { 0L, 1L, 0L };
List<URIStatus> statuses;
try {
statuses = mFileSystem.listStatus(path);
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
for (URIStatus uriStatus : statuses) {
long[] toAdd = countHelper(new AlluxioURI(uriStatus.getPath()));
rtn[0] += toAdd[0];
rtn[1] += toAdd[1];
rtn[2] += toAdd[2];
}
return rtn;
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class CpCommand method copyToLocal.
/**
* Copies a file or a directory from the Alluxio filesystem to the local filesystem.
*
* @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
* @param dstPath the {@link AlluxioURI} of the destination in the local filesystem
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void copyToLocal(AlluxioURI srcPath, AlluxioURI dstPath) throws AlluxioException, IOException {
URIStatus srcStatus = mFileSystem.getStatus(srcPath);
File dstFile = new File(dstPath.getPath());
if (srcStatus.isFolder()) {
// make a local directory
if (!dstFile.exists()) {
if (!dstFile.mkdirs()) {
throw new IOException("mkdir failure for directory: " + dstPath);
} else {
System.out.println("Create directory: " + dstPath);
}
}
List<URIStatus> statuses;
try {
statuses = mFileSystem.listStatus(srcPath);
} catch (AlluxioException e) {
throw new IOException(e.getMessage());
}
List<String> errorMessages = new ArrayList<>();
for (URIStatus status : statuses) {
try {
File subDstFile = new File(dstFile.getAbsolutePath(), status.getName());
copyToLocal(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), subDstFile.getPath()));
} catch (IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
} else {
copyFileToLocal(srcPath, dstPath);
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class PersistPermissionIntegrationTest method asyncPersistEmptyFilePermission.
@Test
public void asyncPersistEmptyFilePermission() throws Exception {
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH)).close();
// check the file is completed but not persisted
URIStatus status = mFileSystem.getStatus(filePath);
Assert.assertNotEquals(PersistenceState.PERSISTED, status.getPersistenceState());
Assert.assertTrue(status.isCompleted());
short fileMode = (short) status.getMode();
short parentMode = (short) mFileSystem.getStatus(filePath.getParent()).getMode();
IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
status = mFileSystem.getStatus(filePath);
Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
// Check the permission of the created file and parent dir are in-sync between Alluxio and UFS.
Assert.assertEquals(fileMode, mUfs.getMode(PathUtils.concatPath(mUfsRoot, filePath)));
Assert.assertEquals(parentMode, mUfs.getMode(PathUtils.concatPath(mUfsRoot, filePath.getParent())));
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class FileOutStreamAsyncWriteIntegrationTest method asyncWrite.
@Test
public void asyncWrite() throws Exception {
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
final int length = 2;
FileOutStream os = mFileSystem.createFile(filePath, CreateFileOptions.defaults().setWriteType(WriteType.ASYNC_THROUGH));
os.write((byte) 0);
os.write((byte) 1);
os.close();
CommonUtils.sleepMs(1);
// check the file is completed but not persisted
URIStatus status = mFileSystem.getStatus(filePath);
Assert.assertEquals(PersistenceState.TO_BE_PERSISTED.toString(), status.getPersistenceState());
Assert.assertTrue(status.isCompleted());
IntegrationTestUtils.waitForPersist(mLocalAlluxioClusterResource, filePath);
status = mFileSystem.getStatus(filePath);
Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
checkFileInAlluxio(filePath, length);
checkFileInUnderStorage(filePath, length);
}
Aggregations