@Test
 public void clientFileInfoDirectoryTest()
     throws InvalidPathException, FileDoesNotExistException, FileAlreadyExistException,
         TachyonException {
   Assert.assertTrue(mMasterInfo.mkdirs("/testFolder", true));
   ClientFileInfo fileInfo = mMasterInfo.getClientFileInfo("/testFolder");
   Assert.assertEquals("testFolder", fileInfo.getName());
   Assert.assertEquals(2, fileInfo.getId());
   Assert.assertEquals(0, fileInfo.getLength());
   Assert.assertEquals("", fileInfo.getUfsPath());
   Assert.assertTrue(fileInfo.isFolder);
   Assert.assertFalse(fileInfo.isPinned);
   Assert.assertFalse(fileInfo.isCache);
   Assert.assertTrue(fileInfo.isComplete);
 }
 @Test
 public void clientFileInfoEmptyFileTest()
     throws InvalidPathException, FileDoesNotExistException, FileAlreadyExistException,
         BlockInfoException, TachyonException {
   int fileId = mMasterInfo.createFile("/testFile", Constants.DEFAULT_BLOCK_SIZE_BYTE);
   ClientFileInfo fileInfo = mMasterInfo.getClientFileInfo("/testFile");
   Assert.assertEquals("testFile", fileInfo.getName());
   Assert.assertEquals(fileId, fileInfo.getId());
   Assert.assertEquals(0, fileInfo.getLength());
   Assert.assertEquals("", fileInfo.getUfsPath());
   Assert.assertFalse(fileInfo.isFolder);
   Assert.assertFalse(fileInfo.isPinned);
   Assert.assertTrue(fileInfo.isCache);
   Assert.assertFalse(fileInfo.isComplete);
 }
Beispiel #3
0
 public UiFileInfo(ClientFileInfo fileInfo) {
   mId = fileInfo.getId();
   mDependencyId = fileInfo.getDependencyId();
   mName = fileInfo.getName();
   mAbsolutePath = fileInfo.getPath();
   mCheckpointPath = fileInfo.getUfsPath();
   mBlockSizeBytes = fileInfo.getBlockSizeByte();
   mSize = fileInfo.getLength();
   mCreationTimeMs = fileInfo.getCreationTimeMs();
   mLastModificationTimeMs = fileInfo.getLastModificationTimeMs();
   mInMemory = (100 == fileInfo.inMemoryPercentage);
   mInMemoryPercent = fileInfo.getInMemoryPercentage();
   mIsDirectory = fileInfo.isFolder;
   mIsPinned = fileInfo.isPinned;
   mFileLocations = new ArrayList<String>();
 }
  /**
   * Populates attribute fields with data from the MasterInfo associated with this servlet. Errors
   * will be displayed in an error field. Debugging can be enabled to display additional data. Will
   * eventually redirect the request to a jsp.
   *
   * @param request The HttpServletRequest object
   * @param response The HttpServletResponse object
   * @throws ServletException
   * @throws IOException
   * @throws UnknownHostException
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, UnknownHostException {
    request.setAttribute("debug", Constants.DEBUG);

    request.setAttribute("masterNodeAddress", mMasterInfo.getMasterAddress().toString());
    request.setAttribute("invalidPathError", "");
    List<ClientFileInfo> filesInfo = null;
    String currentPath = request.getParameter("path");
    if (currentPath == null || currentPath.isEmpty()) {
      currentPath = Constants.PATH_SEPARATOR;
    }
    request.setAttribute("currentPath", currentPath);
    request.setAttribute("viewingOffset", 0);
    try {
      ClientFileInfo clientFileInfo = mMasterInfo.getClientFileInfo(currentPath);
      UiFileInfo currentFileInfo = new UiFileInfo(clientFileInfo);
      request.setAttribute("currentDirectory", currentFileInfo);
      request.setAttribute("blockSizeByte", currentFileInfo.getBlockSizeBytes());
      if (!currentFileInfo.getIsDirectory()) {
        String tmpParam = request.getParameter("offset");
        long offset = 0;
        try {
          if (tmpParam != null) {
            offset = Long.valueOf(tmpParam);
          }
        } catch (NumberFormatException nfe) {
          offset = 0;
        }
        if (offset < 0) {
          offset = 0;
        } else if (offset > clientFileInfo.getLength()) {
          offset = clientFileInfo.getLength();
        }
        displayFile(currentFileInfo.getAbsolutePath(), request, offset);
        request.setAttribute("viewingOffset", offset);
        getServletContext().getRequestDispatcher("/viewFile.jsp").forward(request, response);
        return;
      }
      CommonUtils.validatePath(currentPath);
      setPathDirectories(currentPath, request);
      filesInfo = mMasterInfo.getFilesInfo(currentPath);
    } catch (FileDoesNotExistException fdne) {
      request.setAttribute("invalidPathError", "Error: Invalid Path " + fdne.getMessage());
      getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
      return;
    } catch (InvalidPathException ipe) {
      request.setAttribute("invalidPathError", "Error: Invalid Path " + ipe.getLocalizedMessage());
      getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
      return;
    } catch (IOException ie) {
      request.setAttribute(
          "invalidPathError",
          "Error: File " + currentPath + " is not available " + ie.getMessage());
      getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
      return;
    }

    List<UiFileInfo> fileInfos = new ArrayList<UiFileInfo>(filesInfo.size());
    for (ClientFileInfo fileInfo : filesInfo) {
      UiFileInfo toAdd = new UiFileInfo(fileInfo);
      try {
        if (!toAdd.getIsDirectory() && fileInfo.getLength() > 0) {
          toAdd.setFileLocations(mMasterInfo.getFileBlocks(toAdd.getId()).get(0).getLocations());
        }
      } catch (FileDoesNotExistException fdne) {
        request.setAttribute("invalidPathError", "Error: Invalid Path " + fdne.getMessage());
        getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
        return;
      }
      fileInfos.add(toAdd);
    }
    Collections.sort(fileInfos);
    request.setAttribute("fileInfos", fileInfos);

    getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
  }