Search in sources :

Example 16 with AlluxioException

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

the class BlockMasterSync method registerWithMaster.

/**
   * Registers with the Alluxio master. This should be called before the continuous heartbeat thread
   * begins.
   *
   * @throws IOException when workerId cannot be found
   * @throws ConnectionFailedException if network connection failed
   */
private void registerWithMaster() throws IOException, ConnectionFailedException {
    BlockStoreMeta storeMeta = mBlockWorker.getStoreMetaFull();
    try {
        StorageTierAssoc storageTierAssoc = new WorkerStorageTierAssoc();
        mMasterClient.register(mWorkerId.get(), storageTierAssoc.getOrderedStorageAliases(), storeMeta.getCapacityBytesOnTiers(), storeMeta.getUsedBytesOnTiers(), storeMeta.getBlockList());
    } catch (IOException e) {
        LOG.error("Failed to register with master.", e);
        throw e;
    } catch (AlluxioException e) {
        LOG.error("Failed to register with master.", e);
        throw new IOException(e);
    }
}
Also used : StorageTierAssoc(alluxio.StorageTierAssoc) WorkerStorageTierAssoc(alluxio.WorkerStorageTierAssoc) WorkerStorageTierAssoc(alluxio.WorkerStorageTierAssoc) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 17 with AlluxioException

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

the class WebInterfaceWorkerBlockInfoServlet 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
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setAttribute("fatalError", "");
    String filePath = request.getParameter("path");
    if (!(filePath == null || filePath.isEmpty())) {
        // Display file block info
        try {
            UIFileInfo uiFileInfo = getUiFileInfo(new AlluxioURI(filePath));
            List<ImmutablePair<String, List<UIFileBlockInfo>>> fileBlocksOnTier = new ArrayList<>();
            for (Entry<String, List<UIFileBlockInfo>> e : uiFileInfo.getBlocksOnTier().entrySet()) {
                fileBlocksOnTier.add(new ImmutablePair<>(e.getKey(), e.getValue()));
            }
            request.setAttribute("fileBlocksOnTier", fileBlocksOnTier);
            request.setAttribute("blockSizeBytes", uiFileInfo.getBlockSizeBytes());
            request.setAttribute("path", filePath);
            getServletContext().getRequestDispatcher("/worker/viewFileBlocks.jsp").forward(request, response);
            return;
        } catch (FileDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: Invalid Path " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (IOException e) {
            request.setAttribute("invalidPathError", "Error: File " + filePath + " is not available " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (BlockDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: block not found. " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        } catch (AlluxioException e) {
            request.setAttribute("fatalError", "Error: alluxio exception. " + e.getMessage());
            getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
            return;
        }
    }
    List<Long> fileIds = getSortedFileIds();
    request.setAttribute("nTotalFile", fileIds.size());
    request.setAttribute("orderedTierAliases", new WorkerStorageTierAssoc().getOrderedStorageAliases());
    // URL can not determine offset and limit, let javascript in jsp determine and redirect
    if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    }
    try {
        int offset = Integer.parseInt(request.getParameter("offset"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        List<Long> subFileIds = fileIds.subList(offset, offset + limit);
        List<UIFileInfo> uiFileInfos = new ArrayList<>(subFileIds.size());
        for (long fileId : subFileIds) {
            try {
                uiFileInfos.add(getUiFileInfo(fileId));
            } catch (IOException e) {
                // The file might have been deleted, log a warning and ignore this file.
                LOG.warn("Unable to get file info for fileId {}. {}", fileId, e.getMessage());
            }
        }
        request.setAttribute("fileInfos", uiFileInfos);
    } catch (FileDoesNotExistException e) {
        request.setAttribute("fatalError", "Error: Invalid FileId " + e.getMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (NumberFormatException e) {
        request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (IndexOutOfBoundsException e) {
        request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    } catch (IllegalArgumentException | AlluxioException e) {
        request.setAttribute("fatalError", e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
        return;
    }
    getServletContext().getRequestDispatcher("/worker/blockInfo.jsp").forward(request, response);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) WorkerStorageTierAssoc(alluxio.WorkerStorageTierAssoc) IOException(java.io.IOException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ArrayList(java.util.ArrayList) List(java.util.List) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 18 with AlluxioException

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

the class FileWorkerMasterSyncExecutor method heartbeat.

@Override
public void heartbeat() {
    List<Long> persistedFiles = mFileDataManager.getPersistedFiles();
    if (!persistedFiles.isEmpty()) {
        LOG.info("files {} persisted", persistedFiles);
    }
    FileSystemCommand command;
    try {
        command = mMasterClient.heartbeat(mWorkerId.get(), persistedFiles);
    } catch (IOException | AlluxioException e) {
        LOG.error("Failed to heartbeat to master", e);
        return;
    }
    // removes the persisted files that are confirmed
    mFileDataManager.clearPersistedFiles(persistedFiles);
    if (command == null) {
        LOG.error("The command sent from master is null");
        return;
    } else if (command.getCommandType() != CommandType.Persist) {
        LOG.error("The command sent from master should be PERSIST type, but was {}", command.getCommandType());
        return;
    }
    for (PersistFile persistFile : command.getCommandOptions().getPersistOptions().getPersistFiles()) {
        // Enqueue the persist request.
        mPersistFileService.execute(new FilePersister(mFileDataManager, persistFile.getFileId(), persistFile.getBlockIds()));
    }
}
Also used : PersistFile(alluxio.thrift.PersistFile) IOException(java.io.IOException) FileSystemCommand(alluxio.thrift.FileSystemCommand) AlluxioException(alluxio.exception.AlluxioException)

Example 19 with AlluxioException

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

the class AlluxioFuseFileSystem method getattr.

/**
   * Retrieves file attributes.
   *
   * @param path The path on the FS of the file
   * @param stat FUSE data structure to fill with file attrs
   * @return 0 on success, negative value on error
   */
@Override
public int getattr(String path, FileStat stat) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
    try {
        if (!mFileSystem.exists(turi)) {
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        stat.st_size.set(status.getLength());
        final long ctime_sec = status.getLastModificationTimeMs() / 1000;
        //keeps only the "residual" nanoseconds not caputred in
        // citme_sec
        final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
        stat.st_ctim.tv_sec.set(ctime_sec);
        stat.st_ctim.tv_nsec.set(ctime_nsec);
        stat.st_mtim.tv_sec.set(ctime_sec);
        stat.st_mtim.tv_nsec.set(ctime_nsec);
        // TODO(andreareale): understand how to map FileInfo#getOwner()
        // and FileInfo#getGroup() to UIDs and GIDs of the node
        // where alluxio-fuse is mounted.
        // While this is not done, just use uid and gid of the user
        // running alluxio-fuse.
        stat.st_uid.set(UID_AND_GID[0]);
        stat.st_gid.set(UID_AND_GID[1]);
        final int mode;
        if (status.isFolder()) {
            mode = FileStat.S_IFDIR;
        } else {
            mode = FileStat.S_IFREG;
        }
        stat.st_mode.set(mode);
    } catch (InvalidPathException e) {
        LOG.debug("Invalid path {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 20 with AlluxioException

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

the class AlluxioFuseFileSystem method rmInternal.

/**
   * Convenience internal method to remove files or directories.
   *
   * @param path The path to remove
   * @param mustBeFile When true, returns an error when trying to
   *                   remove a directory
   * @return 0 on success, a negative value on error
   */
private int rmInternal(String path, boolean mustBeFile) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    try {
        if (!mFileSystem.exists(turi)) {
            LOG.error("File {} does not exist", turi);
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        if (mustBeFile && status.isFolder()) {
            LOG.error("File {} is a directory", turi);
            return -ErrorCodes.EISDIR();
        }
        mFileSystem.delete(turi);
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

AlluxioException (alluxio.exception.AlluxioException)56 IOException (java.io.IOException)54 AlluxioURI (alluxio.AlluxioURI)33 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)15 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)11 InvalidPathException (alluxio.exception.InvalidPathException)9 Closer (com.google.common.io.Closer)8 FileOutStream (alluxio.client.file.FileOutStream)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 LockBlockResult (alluxio.wire.LockBlockResult)4 BlockWorkerClient (alluxio.client.block.BlockWorkerClient)3 Mode (alluxio.security.authorization.Mode)3 AlluxioTException (alluxio.thrift.AlluxioTException)3 ThriftIOException (alluxio.thrift.ThriftIOException)3 File (java.io.File)3 WorkerStorageTierAssoc (alluxio.WorkerStorageTierAssoc)2 LockBlockOptions (alluxio.client.block.options.LockBlockOptions)2 SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)2