use of alluxio.client.file.URIStatus in project zeppelin by apache.
the class AlluxioInterpreterTest method lsTest.
@Test
public void lsTest() throws IOException, AlluxioException {
URIStatus[] files = new URIStatus[3];
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA", WriteType.MUST_CACHE, 10, 10);
FileSystemTestUtils.createByteFile(fs, "/testRoot/testDir/testFileB", WriteType.MUST_CACHE, 20, 20);
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileC", WriteType.THROUGH, 30, 30);
files[0] = fs.getStatus(new AlluxioURI("/testRoot/testFileA"));
files[1] = fs.getStatus(new AlluxioURI("/testRoot/testDir"));
files[2] = fs.getStatus(new AlluxioURI("/testRoot/testFileC"));
InterpreterResult output = alluxioInterpreter.interpret("ls /testRoot", null);
String expected = "";
String format = "%-10s%-25s%-15s%-5s\n";
expected += String.format(format, FormatUtils.getSizeFromBytes(10), CommandUtils.convertMsToDate(files[0].getCreationTimeMs()), "In Memory", "/testRoot/testFileA");
expected += String.format(format, FormatUtils.getSizeFromBytes(0), CommandUtils.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir");
expected += String.format(format, FormatUtils.getSizeFromBytes(30), CommandUtils.convertMsToDate(files[2].getCreationTimeMs()), "Not In Memory", "/testRoot/testFileC");
expected += "\n";
Assert.assertEquals(Code.SUCCESS, output.code());
Assert.assertEquals(expected, output.message().get(0).getData());
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class WebInterfaceDownloadServlet method downloadFile.
/**
* This function prepares for downloading a file.
*
* @param path the path of the file to download
* @param request the {@link HttpServletRequest} object
* @param response the {@link HttpServletResponse} object
* @throws FileDoesNotExistException if the file does not exist
* @throws IOException if an I/O error occurs
* @throws InvalidPathException if an invalid path is encountered
* @throws AlluxioException if an unexpected Alluxio exception is thrown
*/
private void downloadFile(AlluxioURI path, HttpServletRequest request, HttpServletResponse response) throws FileDoesNotExistException, IOException, InvalidPathException, AlluxioException {
FileSystem alluxioClient = FileSystem.Factory.get();
URIStatus status = alluxioClient.getStatus(path);
long len = status.getLength();
String fileName = path.getName();
response.setContentType("application/octet-stream");
if (len <= Integer.MAX_VALUE) {
response.setContentLength((int) len);
} else {
response.addHeader("Content-Length", Long.toString(len));
}
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
FileInStream is = null;
ServletOutputStream out = null;
try {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
is = alluxioClient.openFile(path, options);
out = response.getOutputStream();
ByteStreams.copy(is, out);
} finally {
if (out != null) {
out.flush();
out.close();
}
if (is != null) {
is.close();
}
}
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class WebInterfaceBrowseServlet method displayFile.
/**
* This function displays 5KB of a file from a specific offset if it is in ASCII format.
*
* @param path the path of the file to display
* @param request the {@link HttpServletRequest} object
* @param offset where the file starts to display
* @throws FileDoesNotExistException if the file does not exist
* @throws IOException if an I/O error occurs
* @throws InvalidPathException if an invalid path is encountered
* @throws AlluxioException if an unexpected Alluxio exception is thrown
*/
private void displayFile(AlluxioURI path, HttpServletRequest request, long offset) throws FileDoesNotExistException, InvalidPathException, IOException, AlluxioException {
FileSystem fs = FileSystem.Factory.get();
String fileData;
URIStatus status = fs.getStatus(path);
if (status.isCompleted()) {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
try (FileInStream is = fs.openFile(path, options)) {
int len = (int) Math.min(5 * Constants.KB, status.getLength() - offset);
byte[] data = new byte[len];
long skipped = is.skip(offset);
if (skipped < 0) {
// nothing was skipped
fileData = "Unable to traverse to offset; is file empty?";
} else if (skipped < offset) {
// couldn't skip all the way to offset
fileData = "Unable to traverse to offset; is offset larger than the file?";
} else {
// read may not read up to len, so only convert what was read
int read = is.read(data, 0, len);
if (read < 0) {
// stream couldn't read anything, skip went to EOF?
fileData = "Unable to read file";
} else {
fileData = WebUtils.convertByteArrayToStringWithoutEscape(data, 0, read);
}
}
}
} else {
fileData = "The requested file is not complete yet.";
}
List<UIFileBlockInfo> uiBlockInfo = new ArrayList<>();
for (FileBlockInfo fileBlockInfo : mMaster.getFileSystemMaster().getFileBlockInfoList(path)) {
uiBlockInfo.add(new UIFileBlockInfo(fileBlockInfo));
}
request.setAttribute("fileBlocks", uiBlockInfo);
request.setAttribute("fileData", fileData);
request.setAttribute("highestTierAlias", mMaster.getBlockMaster().getGlobalStorageTierAssoc().getAlias(0));
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class IsolatedFileSystemIntegrationTest method lockBlockTest2.
@Test
public void lockBlockTest2() 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.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);
}
use of alluxio.client.file.URIStatus in project alluxio by Alluxio.
the class PersistMultipleMountsIntegrationTest method syncMultipleMountsDefaultPersist.
@Test
public void syncMultipleMountsDefaultPersist() 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(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.assertTrue(mUfs.exists(PathUtils.concatPath(mUfsRoot, path)));
Assert.assertFalse(mMountedUfs.exists(PathUtils.concatPath(mMountedUfsRoot, path)));
}
Aggregations