Search in sources :

Example 31 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class CpCommand method copyWildcard.

/**
   * Copies a list of files or directories specified by srcPaths to the destination specified by
   * dstPath. This method is used when the original source path contains wildcards.
   *
   * @param srcPaths a list of files or directories in the Alluxio filesystem
   * @param dstPath the destination in the Alluxio filesystem
   * @param recursive indicates whether directories should be copied recursively
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copyWildcard(List<AlluxioURI> srcPaths, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (dstStatus != null && !dstStatus.isFolder()) {
        throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
    if (dstStatus == null) {
        mFileSystem.createDirectory(dstPath);
        System.out.println("Created directory: " + dstPath);
    }
    List<String> errorMessages = new ArrayList<>();
    for (AlluxioURI srcPath : srcPaths) {
        try {
            copy(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), srcPath.getName())), recursive);
        } catch (AlluxioException | IOException e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.size() != 0) {
        throw new IOException(Joiner.on('\n').join(errorMessages));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 32 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException 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);
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInStream(alluxio.client.file.FileInStream) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) URIStatus(alluxio.client.file.URIStatus)

Example 33 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class WebInterfaceMemoryServlet method doGet.

/**
   * Populates attributes before redirecting to a jsp.
   *
   * @param request the {@link HttpServletRequest} object
   * @param response the {@link HttpServletResponse} object
   * @throws ServletException if the target resource throws this exception
   * @throws IOException if the target resource throws this exception
   */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
        AuthenticatedClientUser.set(LoginUser.get().getName());
    }
    request.setAttribute("masterNodeAddress", mMaster.getRpcAddress().toString());
    request.setAttribute("fatalError", "");
    request.setAttribute("showPermissions", Configuration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
    List<AlluxioURI> inMemoryFiles = mMaster.getFileSystemMaster().getInMemoryFiles();
    Collections.sort(inMemoryFiles);
    List<UIFileInfo> fileInfos = new ArrayList<>(inMemoryFiles.size());
    for (AlluxioURI file : inMemoryFiles) {
        try {
            long fileId = mMaster.getFileSystemMaster().getFileId(file);
            FileInfo fileInfo = mMaster.getFileSystemMaster().getFileInfo(fileId);
            if (fileInfo != null && fileInfo.getInMemoryPercentage() == 100) {
                fileInfos.add(new UIFileInfo(fileInfo));
            }
        } catch (FileDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: File does not exist " + e.getLocalizedMessage());
            getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
            return;
        } catch (AccessControlException e) {
            request.setAttribute("permissionError", "Error: File " + file + " cannot be accessed " + e.getMessage());
            getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
            return;
        }
    }
    request.setAttribute("inMemoryFileNum", fileInfos.size());
    // and redirect to "./memory?offset=xxx&limit=xxx"
    if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    }
    try {
        int offset = Integer.parseInt(request.getParameter("offset"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        List<UIFileInfo> sub = fileInfos.subList(offset, offset + limit);
        request.setAttribute("fileInfos", sub);
    } catch (NumberFormatException e) {
        request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    } catch (IndexOutOfBoundsException e) {
        request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    } catch (IllegalArgumentException e) {
        request.setAttribute("fatalError", e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    }
    getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI)

Example 34 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class LineageMaster method reinitializeFile.

/**
   * Reinitializes the file when the file is lost or not completed.
   *
   * @param path the path to the file
   * @param blockSizeBytes the block size
   * @param ttl the TTL
   * @param ttlAction action to perform on ttl expiry
   * @return the id of the reinitialized file when the file is lost or not completed, -1 otherwise
   * @throws InvalidPathException the file path is invalid
   * @throws LineageDoesNotExistException when the file does not exist
   * @throws AccessControlException if permission checking fails
   * @throws FileDoesNotExistException if the path does not exist
   */
public synchronized long reinitializeFile(String path, long blockSizeBytes, long ttl, TtlAction ttlAction) throws InvalidPathException, LineageDoesNotExistException, AccessControlException, FileDoesNotExistException {
    long fileId = mFileSystemMaster.getFileId(new AlluxioURI(path));
    FileInfo fileInfo;
    try {
        fileInfo = mFileSystemMaster.getFileInfo(fileId);
        if (!fileInfo.isCompleted() || mFileSystemMaster.getLostFiles().contains(fileId)) {
            LOG.info("Recreate the file {} with block size of {} bytes", path, blockSizeBytes);
            return mFileSystemMaster.reinitializeFile(new AlluxioURI(path), blockSizeBytes, ttl, ttlAction);
        }
    } catch (FileDoesNotExistException e) {
        throw new LineageDoesNotExistException(ExceptionMessage.MISSING_REINITIALIZE_FILE.getMessage(path));
    }
    return -1;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) LineageDoesNotExistException(alluxio.exception.LineageDoesNotExistException) AlluxioURI(alluxio.AlluxioURI)

Example 35 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class CheckpointLatestPlanner method generatePlan.

@Override
public CheckpointPlan generatePlan(LineageStoreView store, FileSystemMasterView fileSystemMasterView) {
    Lineage toCheckpoint = null;
    long latestCreated = 0;
    for (Lineage lineage : store.getAllLineagesInTopologicalOrder()) {
        try {
            if (!LineageStateUtils.isCompleted(lineage, fileSystemMasterView) || LineageStateUtils.isPersisted(lineage, fileSystemMasterView) || LineageStateUtils.needRecompute(lineage, fileSystemMasterView) || LineageStateUtils.isInCheckpointing(lineage, fileSystemMasterView)) {
                continue;
            }
        } catch (FileDoesNotExistException | AccessControlException e) {
            LOG.error("The lineage file does not exist", e);
            continue;
        }
        if (lineage.getCreationTime() > latestCreated) {
            latestCreated = lineage.getCreationTime();
            toCheckpoint = lineage;
        }
    }
    return toCheckpoint == null ? new CheckpointPlan(new ArrayList<Long>()) : new CheckpointPlan(Lists.newArrayList(toCheckpoint.getId()));
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) Lineage(alluxio.master.lineage.meta.Lineage) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)51 AlluxioURI (alluxio.AlluxioURI)36 InvalidPathException (alluxio.exception.InvalidPathException)20 IOException (java.io.IOException)19 AlluxioException (alluxio.exception.AlluxioException)16 Test (org.junit.Test)14 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)10 AccessControlException (alluxio.exception.AccessControlException)7 FileInfo (alluxio.wire.FileInfo)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 RestApiTest (alluxio.rest.RestApiTest)4 TestCase (alluxio.rest.TestCase)4 HashMap (java.util.HashMap)4 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)3 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)3 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)3 Inode (alluxio.master.file.meta.Inode)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3