Skip to content

Commit

Permalink
replace deprecated API TachyonFS usage with TachyonFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfree committed Sep 18, 2015
1 parent 8b309a2 commit 1c45bfb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
37 changes: 17 additions & 20 deletions servers/src/main/java/tachyon/web/WebInterfaceBrowseServlet.java
Expand Up @@ -32,10 +32,11 @@


import tachyon.Constants; import tachyon.Constants;
import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.client.ReadType; import tachyon.client.ClientOptions;
import tachyon.client.TachyonFS; import tachyon.client.TachyonStorageType;
import tachyon.client.TachyonFile;
import tachyon.client.file.FileInStream; import tachyon.client.file.FileInStream;
import tachyon.client.file.TachyonFile;
import tachyon.client.file.TachyonFileSystem;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.master.TachyonMaster; import tachyon.master.TachyonMaster;
import tachyon.thrift.BlockLocation; import tachyon.thrift.BlockLocation;
Expand Down Expand Up @@ -75,19 +76,19 @@ public WebInterfaceBrowseServlet(TachyonMaster master) {
*/ */
private void displayFile(TachyonURI path, HttpServletRequest request, long offset) private void displayFile(TachyonURI path, HttpServletRequest request, long offset)
throws FileDoesNotExistException, InvalidPathException, IOException { throws FileDoesNotExistException, InvalidPathException, IOException {
String masterAddress = TachyonFileSystem tFS = TachyonFileSystem.get();
Constants.HEADER + mMaster.getMasterAddress().getHostName() + ":" TachyonFile tFile = tFS.open(path);
+ mMaster.getMasterAddress().getPort();
TachyonFS tachyonClient = TachyonFS.get(new TachyonURI(masterAddress), new TachyonConf());
TachyonFile tFile = tachyonClient.getFile(path);
String fileData = null; String fileData = null;
if (tFile == null) { if (tFile == null) {
throw new FileDoesNotExistException(path.toString()); throw new FileDoesNotExistException(path.toString());
} }
if (tFile.isComplete()) { FileInfo fileInfo = tFS.getInfo(tFile);
FileInStream is = tFile.getInStream(ReadType.NO_CACHE); if (fileInfo.isComplete) {
ClientOptions readNoCache = new ClientOptions.Builder(mTachyonConf)
.setTachyonStoreType(TachyonStorageType.NO_STORE).build();
FileInStream is = tFS.getInStream(tFile, readNoCache);
try { try {
int len = (int) Math.min(5 * Constants.KB, tFile.length() - offset); int len = (int) Math.min(5 * Constants.KB, fileInfo.length - offset);
byte[] data = new byte[len]; byte[] data = new byte[len];
long skipped = is.skip(offset); long skipped = is.skip(offset);
if (skipped < 0) { if (skipped < 0) {
Expand All @@ -112,11 +113,7 @@ private void displayFile(TachyonURI path, HttpServletRequest request, long offse
} else { } else {
fileData = "The requested file is not complete yet."; fileData = "The requested file is not complete yet.";
} }
try { tFS.close();
tachyonClient.close();
} catch (IOException e) {
LOG.error(e.getMessage());
}
List<UiBlockInfo> uiBlockInfo = new ArrayList<UiBlockInfo>(); List<UiBlockInfo> uiBlockInfo = new ArrayList<UiBlockInfo>();
for (FileBlockInfo fileBlockInfo : mMaster.getFileSystemMaster().getFileBlockInfoList(path)) { for (FileBlockInfo fileBlockInfo : mMaster.getFileSystemMaster().getFileBlockInfoList(path)) {
uiBlockInfo.add(new UiBlockInfo(fileBlockInfo)); uiBlockInfo.add(new UiBlockInfo(fileBlockInfo));
Expand Down Expand Up @@ -202,8 +199,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return; return;
} catch (IOException ie) { } catch (IOException ie) {
request.setAttribute("invalidPathError", "Error: File " + currentPath + " is not available " request.setAttribute("invalidPathError",
+ ie.getMessage()); "Error: File " + currentPath + " is not available " + ie.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return; return;
} }
Expand Down Expand Up @@ -249,12 +246,12 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
request.setAttribute("fileInfos", sub); request.setAttribute("fileInfos", sub);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
request.setAttribute("fatalError", request.setAttribute("fatalError",
"Error: offset or limit parse error, " + nfe.getLocalizedMessage()); "Error: offset or limit parse error, " + nfe.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return; return;
} catch (IndexOutOfBoundsException iobe) { } catch (IndexOutOfBoundsException iobe) {
request.setAttribute("fatalError", request.setAttribute("fatalError",
"Error: offset or offset + limit is out of bound, " + iobe.getLocalizedMessage()); "Error: offset or offset + limit is out of bound, " + iobe.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
return; return;
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
Expand Down
Expand Up @@ -15,6 +15,7 @@


package tachyon.web; package tachyon.web;


import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
Expand All @@ -33,11 +34,14 @@
import tachyon.StorageLevelAlias; import tachyon.StorageLevelAlias;
import tachyon.TachyonURI; import tachyon.TachyonURI;
import tachyon.client.TachyonFS; import tachyon.client.TachyonFS;
import tachyon.client.file.TachyonFile;
import tachyon.client.file.TachyonFileSystem;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.exception.NotFoundException; import tachyon.exception.NotFoundException;
import tachyon.master.block.BlockId; import tachyon.master.block.BlockId;
import tachyon.thrift.FileDoesNotExistException; import tachyon.thrift.FileDoesNotExistException;
import tachyon.thrift.FileInfo; import tachyon.thrift.FileInfo;
import tachyon.thrift.InvalidPathException;
import tachyon.worker.block.BlockDataManager; import tachyon.worker.block.BlockDataManager;
import tachyon.worker.block.BlockStoreMeta; import tachyon.worker.block.BlockStoreMeta;
import tachyon.worker.block.meta.BlockMeta; import tachyon.worker.block.meta.BlockMeta;
Expand Down Expand Up @@ -67,13 +71,12 @@ public WebInterfaceWorkerBlockInfoServlet(BlockDataManager blockDataManager, Tac
protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
request.setAttribute("fatalError", ""); request.setAttribute("fatalError", "");
TachyonFS tachyonClient = TachyonFS.get(mTachyonConf); TachyonFileSystem tFS = TachyonFileSystem.get();

String filePath = request.getParameter("path"); String filePath = request.getParameter("path");
if (!(filePath == null || filePath.isEmpty())) { if (!(filePath == null || filePath.isEmpty())) {
// Display file block info // Display file block info
try { try {
UiFileInfo uiFileInfo = getUiFileInfo(tachyonClient, new TachyonURI(filePath)); UiFileInfo uiFileInfo = getUiFileInfo(tFS, new TachyonURI(filePath));
request.setAttribute("fileBlocksOnTier", uiFileInfo.getBlocksOnTier()); request.setAttribute("fileBlocksOnTier", uiFileInfo.getBlocksOnTier());
request.setAttribute("blockSizeBytes", uiFileInfo.getBlockSizeBytes()); request.setAttribute("blockSizeBytes", uiFileInfo.getBlockSizeBytes());
request.setAttribute("path", filePath); request.setAttribute("path", filePath);
Expand All @@ -97,7 +100,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response); response);
return; return;
} finally { } finally {
tachyonClient.close(); tFS.close();
} }
} }


Expand All @@ -107,7 +110,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
// URL can not determine offset and limit, let javascript in jsp determine and redirect // URL can not determine offset and limit, let javascript in jsp determine and redirect
if (request.getParameter("offset") == null && request.getParameter("limit") == null) { if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response); getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
tachyonClient.close(); tFS.close();
return; return;
} }


Expand All @@ -117,7 +120,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
List<Long> subFileIds = fileIds.subList(offset, offset + limit); List<Long> subFileIds = fileIds.subList(offset, offset + limit);
List<UiFileInfo> uiFileInfos = new ArrayList<UiFileInfo>(subFileIds.size()); List<UiFileInfo> uiFileInfos = new ArrayList<UiFileInfo>(subFileIds.size());
for (long fileId : subFileIds) { for (long fileId : subFileIds) {
uiFileInfos.add(getUiFileInfo(tachyonClient, fileId)); uiFileInfos.add(getUiFileInfo(tFS, fileId));
} }
request.setAttribute("fileInfos", uiFileInfos); request.setAttribute("fileInfos", uiFileInfos);
} catch (FileDoesNotExistException fdne) { } catch (FileDoesNotExistException fdne) {
Expand All @@ -144,7 +147,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response); getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
return; return;
} finally { } finally {
tachyonClient.close(); tFS.close();
} }


getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response); getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
Expand Down Expand Up @@ -173,49 +176,58 @@ private List<Long> getSortedFileIds() {
/*** /***
* Get the UiFileInfo object based on fileId. * Get the UiFileInfo object based on fileId.
* *
* @param tachyonClient the TachyonFS client. * @param tachyonFileSystem the TachyonFileSystem client.
* @param fileId the file id of the file. * @param fileId the file id of the file.
* @return the UiFileInfo object of the file. * @return the UiFileInfo object of the file.
* @throws FileDoesNotExistException * @throws FileDoesNotExistException
* @throws IOException * @throws IOException
*/ */
private UiFileInfo getUiFileInfo(TachyonFS tachyonClient, long fileId) private UiFileInfo getUiFileInfo(TachyonFileSystem tachyonFileSystem, long fileId)
throws FileDoesNotExistException, NotFoundException, IOException { throws FileDoesNotExistException, NotFoundException, IOException {
return getUiFileInfo(tachyonClient, fileId, TachyonURI.EMPTY_URI); return getUiFileInfo(tachyonFileSystem, fileId, TachyonURI.EMPTY_URI);
} }


/*** /***
* Get the UiFileInfo object based on filePath. * Get the UiFileInfo object based on filePath.
* *
* @param tachyonClient the TachyonFS client. * @param tachyonFileSystem the TachyonFileSystem client.
* @param filePath the path of the file. * @param filePath the path of the file.
* @return the UiFileInfo object of the file. * @return the UiFileInfo object of the file.
* @throws FileDoesNotExistException * @throws FileDoesNotExistException
* @throws IOException * @throws IOException
*/ */
private UiFileInfo getUiFileInfo(TachyonFS tachyonClient, TachyonURI filePath) private UiFileInfo getUiFileInfo(TachyonFileSystem tachyonFileSystem, TachyonURI filePath)
throws FileDoesNotExistException, NotFoundException, IOException { throws FileDoesNotExistException, NotFoundException, IOException{
return getUiFileInfo(tachyonClient, -1, filePath); return getUiFileInfo(tachyonFileSystem, -1, filePath);
} }


/** /**
* Gets the UiFileInfo object that represents the fileId, or the filePath if fileId is -1. * Gets the UiFileInfo object that represents the fileId, or the filePath if fileId is -1.
* *
* @param tachyonClient the TachyonFS client. * @param tachyonFileSystem the TachyonFileSystem client.
* @param fileId the file id of the file. * @param fileId the file id of the file.
* @param filePath the path of the file. valid iff fileId is -1. * @param filePath the path of the file. valid iff fileId is -1.
* @return the UiFileInfo object of the file. * @return the UiFileInfo object of the file.
* @throws FileDoesNotExistException * @throws FileDoesNotExistException
* @throws IOException * @throws IOException
*/ */
private UiFileInfo getUiFileInfo(TachyonFS tachyonClient, long fileId, TachyonURI filePath) private UiFileInfo getUiFileInfo(TachyonFileSystem tachyonFileSystem, long fileId, TachyonURI filePath)
throws FileDoesNotExistException, NotFoundException, IOException { throws FileDoesNotExistException, NotFoundException, IOException {
FileInfo fileInfo = tachyonClient.getFileStatus(fileId, filePath, true); TachyonFile file = null;
if(fileId == -1){
file = new TachyonFile(fileId);
} else {
try {
file = tachyonFileSystem.open(filePath);
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(filePath.toString());
}
}
FileInfo fileInfo = tachyonFileSystem.getInfo(file);
if (fileInfo == null) { if (fileInfo == null) {
throw new FileDoesNotExistException(fileId != -1 ? Long.toString(fileId) throw new FileDoesNotExistException(fileId != -1 ? Long.toString(fileId)
: filePath.toString()); : filePath.toString());
} }

UiFileInfo uiFileInfo = new UiFileInfo(fileInfo); UiFileInfo uiFileInfo = new UiFileInfo(fileInfo);
boolean blockExistOnWorker = false; boolean blockExistOnWorker = false;
for (long blockId : fileInfo.getBlockIds()) { for (long blockId : fileInfo.getBlockIds()) {
Expand All @@ -224,7 +236,7 @@ private UiFileInfo getUiFileInfo(TachyonFS tachyonClient, long fileId, TachyonUR
BlockMeta blockMeta = mBlockDataManager.getVolatileBlockMeta(blockId); BlockMeta blockMeta = mBlockDataManager.getVolatileBlockMeta(blockId);
long blockSize = blockMeta.getBlockSize(); long blockSize = blockMeta.getBlockSize();
StorageLevelAlias storageLevelAlias = StorageLevelAlias storageLevelAlias =
StorageDirId.getStorageLevelAlias(blockMeta.getParentDir().getStorageDirId()); StorageDirId.getStorageLevelAlias(blockMeta.getParentDir().getStorageDirId());
// The block last access time is not available. Use -1 for now. // The block last access time is not available. Use -1 for now.
// It's not necessary to show location information here since // It's not necessary to show location information here since
// we are viewing at the context of this worker. // we are viewing at the context of this worker.
Expand Down

0 comments on commit 1c45bfb

Please sign in to comment.