use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class PersistPermissionIntegrationTest method asyncPersistPermission.
@Test
public void asyncPersistPermission() throws Exception {
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
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());
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 PersistPermissionIntegrationTest method syncPersistPermission.
@Test
public void syncPersistPermission() throws Exception {
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(mUfs) || UnderFileSystemUtils.isHdfs(mUfs));
AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
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());
short fileMode = (short) status.getMode();
short parentMode = (short) mFileSystem.getStatus(filePath.getParent()).getMode();
// 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 LoadCommand method load.
/**
* Loads a file or directory in Alluxio space, makes it resident in memory.
*
* @param filePath The {@link AlluxioURI} path to load into Alluxio memory
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void load(AlluxioURI filePath) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(filePath);
if (status.isFolder()) {
List<URIStatus> statuses = mFileSystem.listStatus(filePath);
for (URIStatus uriStatus : statuses) {
AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
load(newPath);
}
} else {
if (status.getInMemoryPercentage() == 100) {
// The file has already been fully loaded into Alluxio memory.
return;
}
Closer closer = Closer.create();
try {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
FileInStream in = closer.register(mFileSystem.openFile(filePath, options));
byte[] buf = new byte[8 * Constants.MB];
while (in.read(buf) != -1) {
}
} catch (Exception e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
System.out.println(filePath + " loaded");
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class LocationCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
System.out.println(path + " with file id " + status.getFileId() + " is on nodes: ");
AlluxioBlockStore blockStore = AlluxioBlockStore.create();
for (long blockId : status.getBlockIds()) {
for (BlockLocation location : blockStore.getInfo(blockId).getLocations()) {
System.out.println(location.getWorkerAddress().getHost());
}
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class LsCommand method ls.
/**
* Displays information for all directories and files directly under the path specified in args.
*
* @param path The {@link AlluxioURI} path as the input of the command
* @param recursive Whether list the path recursively
* @param dirAsFile list the directory status as a plain file
* @param rawSize print raw sizes
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void ls(AlluxioURI path, boolean recursive, boolean forceLoadMetadata, boolean dirAsFile, boolean rawSize) throws AlluxioException, IOException {
if (dirAsFile) {
URIStatus status = mFileSystem.getStatus(path);
System.out.print(formatLsString(rawSize, SecurityUtils.isSecurityEnabled(), status.isFolder(), FormatUtils.formatMode((short) status.getMode(), status.isFolder()), status.getOwner(), status.getGroup(), status.getLength(), status.getCreationTimeMs(), 100 == status.getInMemoryPercentage(), status.getPath()));
return;
}
ListStatusOptions options = ListStatusOptions.defaults();
if (forceLoadMetadata) {
options.setLoadMetadataType(LoadMetadataType.Always);
}
List<URIStatus> statuses = listStatusSortedByIncreasingCreationTime(path, options);
for (URIStatus status : statuses) {
System.out.print(formatLsString(rawSize, SecurityUtils.isSecurityEnabled(), status.isFolder(), FormatUtils.formatMode((short) status.getMode(), status.isFolder()), status.getOwner(), status.getGroup(), status.getLength(), status.getCreationTimeMs(), 100 == status.getInMemoryPercentage(), status.getPath()));
if (recursive && status.isFolder()) {
ls(new AlluxioURI(path.getScheme(), path.getAuthority(), status.getPath()), true, forceLoadMetadata, false, rawSize);
}
}
}
Aggregations