use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class CatCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
if (status.isFolder()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
}
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
byte[] buf = new byte[512];
try (FileInStream is = mFileSystem.openFile(path, options)) {
int read = is.read(buf);
while (read != -1) {
System.out.write(buf, 0, read);
read = is.read(buf);
}
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class CheckConsistencyCommand method checkConsistency.
private void checkConsistency(AlluxioURI path, boolean repairConsistency) throws AlluxioException, IOException {
CheckConsistencyOptions options = CheckConsistencyOptions.defaults();
List<AlluxioURI> inconsistentUris = FileSystemUtils.checkConsistency(path, options);
if (inconsistentUris.isEmpty()) {
System.out.println(path + " is consistent with the under storage system.");
return;
}
if (!repairConsistency) {
Collections.sort(inconsistentUris);
System.out.println("The following files are inconsistent:");
for (AlluxioURI uri : inconsistentUris) {
System.out.println(uri);
}
} else {
Collections.sort(inconsistentUris);
System.out.println(path + " has: " + inconsistentUris.size() + " inconsistent files.");
List<AlluxioURI> inconsistentDirs = new ArrayList<AlluxioURI>();
for (int i = 0; i < inconsistentUris.size(); i++) {
AlluxioURI inconsistentUri = inconsistentUris.get(i);
URIStatus status = mFileSystem.getStatus(inconsistentUri);
if (status.isFolder()) {
inconsistentDirs.add(inconsistentUri);
continue;
}
System.out.println("repairing path: " + inconsistentUri);
DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true);
mFileSystem.delete(inconsistentUri, deleteOptions);
mFileSystem.exists(inconsistentUri);
System.out.println(inconsistentUri + " repaired");
System.out.println();
}
for (AlluxioURI uri : inconsistentDirs) {
DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true).setRecursive(true);
System.out.println("repairing path: " + uri);
mFileSystem.delete(uri, deleteOptions);
mFileSystem.exists(uri);
System.out.println(uri + "repaired");
System.out.println();
}
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class PersistCommand method persist.
/**
* Persists a file or directory currently stored only in Alluxio to the UnderFileSystem.
*
* @param filePath the {@link AlluxioURI} path to persist to the UnderFileSystem
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void persist(AlluxioURI filePath) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(filePath);
if (status.isFolder()) {
List<URIStatus> statuses = mFileSystem.listStatus(filePath);
List<String> errorMessages = new ArrayList<>();
for (URIStatus uriStatus : statuses) {
AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
try {
persist(newPath);
} catch (IOException e) {
errorMessages.add(e.getMessage());
}
}
if (errorMessages.size() != 0) {
throw new IOException(Joiner.on('\n').join(errorMessages));
}
} else if (status.isPersisted()) {
System.out.println(filePath + " is already persisted");
} else {
FileSystemUtils.persistFile(mFileSystem, filePath);
System.out.println("persisted file " + filePath + " with size " + status.getLength());
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class TailCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
int numOfBytes = Constants.KB;
if (cl.hasOption('c')) {
numOfBytes = Integer.parseInt(cl.getOptionValue('c'));
Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0");
}
if (status.isFolder()) {
throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
}
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
try (FileInStream is = mFileSystem.openFile(path, options)) {
byte[] buf = new byte[numOfBytes];
long bytesToRead;
if (status.getLength() > numOfBytes) {
bytesToRead = numOfBytes;
} else {
bytesToRead = status.getLength();
}
is.skip(status.getLength() - bytesToRead);
int read = is.read(buf);
if (read != -1) {
System.out.write(buf, 0, read);
}
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class IsolatedFileSystemIntegrationTest method unlockBlockTest2.
@Test
public void unlockBlockTest2() throws Exception {
String uniqPath = PathUtils.uniqPath();
FileInStream is;
ByteBuffer buf;
int numOfFiles = 5;
int fileSize = WORKER_CAPACITY_BYTES / numOfFiles;
List<AlluxioURI> files = new ArrayList<>();
for (int k = 0; k < numOfFiles; k++) {
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + k, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + k));
}
for (int k = 0; k < numOfFiles; k++) {
URIStatus info = mFileSystem.getStatus(files.get(k));
Assert.assertTrue(info.getInMemoryPercentage() == 100);
is = mFileSystem.openFile(files.get(k), FileSystemTestUtils.toOpenFileOptions(mWriteBoth));
buf = ByteBuffer.allocate((int) info.getBlockSizeBytes());
Assert.assertTrue(is.read(buf.array()) != -1);
is.seek(0);
buf.clear();
Assert.assertTrue(is.read(buf.array()) != -1);
is.close();
}
FileSystemTestUtils.createByteFile(mFileSystem, uniqPath + numOfFiles, fileSize, mWriteBoth);
files.add(new AlluxioURI(uniqPath + numOfFiles));
for (int k = 1; k < numOfFiles; k++) {
URIStatus info = mFileSystem.getStatus(files.get(k));
Assert.assertTrue(info.getInMemoryPercentage() == 100);
}
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
URIStatus info = mFileSystem.getStatus(files.get(numOfFiles));
Assert.assertTrue(info.getInMemoryPercentage() == 100);
}
Aggregations