Search in sources :

Example 11 with AlluxioException

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

the class AbstractFileSystem method delete.

/**
   * Attempts to delete the file or directory with the specified path.
   *
   * @param path path to delete
   * @param recursive if true, will attempt to delete all children of the path
   * @return true if one or more files/directories were deleted; false otherwise
   * @throws IOException if the path failed to be deleted due to some constraint (ie. non empty
   *         directory with recursive flag disabled)
   */
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
    LOG.debug("delete({}, {})", path, recursive);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
    try {
        mFileSystem.delete(uri, options);
        return true;
    } catch (InvalidPathException | FileDoesNotExistException e) {
        LOG.error("delete failed: {}", e.getMessage());
        return false;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeleteOptions(alluxio.client.file.options.DeleteOptions) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 12 with AlluxioException

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

the class BlockInStream method createLocalBlockInStream.

/**
   * Creates an instance of local {@link BlockInStream} that reads from local worker.
   *
   * @param blockId the block ID
   * @param blockSize the block size
   * @param workerNetAddress the worker network address
   * @param context the file system context
   * @param options the options
   * @throws IOException if it fails to create an instance
   * @return the {@link BlockInStream} created
   */
// TODO(peis): Use options idiom (ALLUXIO-2579).
public static BlockInStream createLocalBlockInStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, InStreamOptions options) throws IOException {
    Closer closer = Closer.create();
    try {
        BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
        LockBlockResource lockBlockResource = closer.register(blockWorkerClient.lockBlock(blockId, LockBlockOptions.defaults()));
        PacketInStream inStream = closer.register(PacketInStream.createLocalPacketInstream(lockBlockResource.getResult().getBlockPath(), blockId, blockSize));
        blockWorkerClient.accessBlock(blockId);
        return new BlockInStream(inStream, blockWorkerClient, closer, options);
    } catch (AlluxioException | IOException e) {
        CommonUtils.closeQuitely(closer);
        throw CommonUtils.castToIOException(e);
    }
}
Also used : Closer(com.google.common.io.Closer) LockBlockResource(alluxio.client.resource.LockBlockResource) BlockWorkerClient(alluxio.client.block.BlockWorkerClient) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 13 with AlluxioException

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

the class FileSystemTestUtils method createByteFile.

/**
   * Creates a simple file with {@code len} bytes.
   *
   * @param fs a {@link FileSystem} handler
   * @param fileURI URI of the file
   * @param options client options to create the file with
   * @param len file size
   * @throws IOException if {@code path} is invalid (e.g., illegal URI)
   */
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, CreateFileOptions options, int len) throws IOException {
    try (FileOutStream os = fs.createFile(fileURI, options)) {
        byte[] arr = new byte[len];
        for (int k = 0; k < len; k++) {
            arr[k] = (byte) k;
        }
        os.write(arr);
    } catch (AlluxioException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 14 with AlluxioException

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

the class FileSystemTestUtils method listFiles.

/**
   * Returns a list of files at a given {@code path}.
   *
   * @param fs a {@link FileSystem} handler
   * @param path a path in alluxio file system
   * @return a list of strings representing the file names under the given path
   * @throws IOException if {@code path} does not exist or is invalid
   */
public static List<String> listFiles(FileSystem fs, String path) throws IOException {
    try {
        List<URIStatus> statuses = fs.listStatus(new AlluxioURI(path));
        List<String> res = new ArrayList<>();
        for (URIStatus status : statuses) {
            res.add(status.getPath());
            if (status.isFolder()) {
                res.addAll(listFiles(fs, status.getPath()));
            }
        }
        return res;
    } catch (AlluxioException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 15 with AlluxioException

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

the class AlluxioBlockStore method getOutStream.

/**
   * Gets a stream to write data to a block based on the options. The stream can only be backed by
   * Alluxio storage.
   *
   * @param blockId the block to write
   * @param blockSize the standard block size to write, or -1 if the block already exists (and this
   *        stream is just storing the block in Alluxio again)
   * @param options the output stream option
   * @return an {@link OutputStream} which can be used to write data to the block in a
   *         streaming fashion
   * @throws IOException if the block cannot be written
   */
public OutputStream getOutStream(long blockId, long blockSize, OutStreamOptions options) throws IOException {
    WorkerNetAddress address;
    FileWriteLocationPolicy locationPolicy = Preconditions.checkNotNull(options.getLocationPolicy(), PreconditionMessage.FILE_WRITE_LOCATION_POLICY_UNSPECIFIED);
    try {
        address = locationPolicy.getWorkerForNextBlock(getWorkerInfoList(), blockSize);
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    return getOutStream(blockId, blockSize, address, options);
}
Also used : FileWriteLocationPolicy(alluxio.client.file.policy.FileWriteLocationPolicy) WorkerNetAddress(alluxio.wire.WorkerNetAddress) IOException(java.io.IOException) 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