Search in sources :

Example 46 with AlluxioException

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

the class AbstractFileSystem method getFileStatus.

/**
   * {@inheritDoc}
   *
   * If the file does not exist in Alluxio, query it from HDFS.
   */
@Override
public FileStatus getFileStatus(Path path) throws IOException {
    LOG.debug("getFileStatus({})", path);
    if (mStatistics != null) {
        mStatistics.incrementReadOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    URIStatus fileStatus;
    try {
        fileStatus = mFileSystem.getStatus(uri);
    } catch (FileDoesNotExistException e) {
        throw new FileNotFoundException(e.getMessage());
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    return new FileStatus(fileStatus.getLength(), fileStatus.isFolder(), BLOCK_REPLICATION_CONSTANT, fileStatus.getBlockSizeBytes(), fileStatus.getLastModificationTimeMs(), fileStatus.getCreationTimeMs(), new FsPermission((short) fileStatus.getMode()), fileStatus.getOwner(), fileStatus.getGroup(), new Path(mAlluxioHeader + uri));
}
Also used : Path(org.apache.hadoop.fs.Path) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 47 with AlluxioException

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

the class AbstractFileSystem method mkdirs.

/**
   * Attempts to create a folder with the specified path. Parent directories will be created.
   *
   * @param path path to create
   * @param permission permissions to grant the created folder
   * @return true if the indicated folder is created successfully or already exists
   * @throws IOException if the folder cannot be created
   */
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
    LOG.debug("mkdirs({}, {})", path, permission);
    if (mStatistics != null) {
        mStatistics.incrementWriteOps(1);
    }
    AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
    CreateDirectoryOptions options = CreateDirectoryOptions.defaults().setRecursive(true).setAllowExists(true).setMode(new Mode(permission.toShort()));
    try {
        mFileSystem.createDirectory(uri, options);
        return true;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : CreateDirectoryOptions(alluxio.client.file.options.CreateDirectoryOptions) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 48 with AlluxioException

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

the class AlluxioFuseFileSystem method create.

/**
   * Creates and opens a new file.
   *
   * @param path The FS path of the file to open
   * @param mode mode flags
   * @param fi FileInfo data struct kept by FUSE
   * @return 0 on success. A negative value on error
   */
@Override
public int create(String path, @mode_t long mode, FuseFileInfo fi) {
    // mode is ignored in alluxio-fuse
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    // (see {@code man 2 open} for the structure of the flags bitfield)
    // File creation flags are the last two bits of flags
    final int flags = fi.flags.get();
    LOG.trace("create({}, {}) [Alluxio: {}]", path, Integer.toHexString(flags), turi);
    final int openFlag = flags & 3;
    if (openFlag != O_WRONLY.intValue()) {
        OpenFlags flag = OpenFlags.valueOf(openFlag);
        LOG.error("Passed a {} flag to create(). Files can only be created in O_WRONLY mode ({})", flag.toString(), path);
        return -ErrorCodes.EACCES();
    }
    try {
        synchronized (mOpenFiles) {
            if (mOpenFiles.size() >= MAX_OPEN_FILES) {
                LOG.error("Cannot open {}: too many open files (MAX_OPEN_FILES: {})", turi, MAX_OPEN_FILES);
                return -ErrorCodes.EMFILE();
            }
            final OpenFileEntry ofe = new OpenFileEntry(null, mFileSystem.createFile(turi));
            LOG.debug("Alluxio OutStream created for {}", path);
            mOpenFiles.put(mNextOpenFileId, ofe);
            fi.fh.set(mNextOpenFileId);
            // Assuming I will never wrap around (2^64 open files are quite a lot anyway)
            mNextOpenFileId += 1;
        }
        LOG.debug("{} created and opened in O_WRONLY mode", path);
    } catch (FileAlreadyExistsException e) {
        LOG.debug("File {} already exists", turi, e);
        return -ErrorCodes.EEXIST();
    } 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 : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) OpenFlags(jnr.constants.platform.OpenFlags) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 49 with AlluxioException

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

the class AlluxioFuseFileSystem method mkdir.

/**
   * Creates a new dir.
   *
   * @param path the path on the FS of the new dir
   * @param mode Dir creation flags (IGNORED)
   * @return 0 on success, a negative value on error
   */
@Override
public int mkdir(String path, @mode_t long mode) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("mkdir({}) [Alluxio: {}]", path, turi);
    try {
        mFileSystem.createDirectory(turi);
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Cannot make dir. {} already exists", path, e);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Cannot make dir. Invalid path: {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("Cannot make dir. IOException: {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("Cannot make dir. {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 50 with AlluxioException

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

the class BaseKeyValueStoreWriter method close.

@Override
public void close() throws IOException {
    if (mClosed) {
        return;
    }
    try {
        if (mCanceled) {
            mWriter.cancel();
        // TODO(binfan): cancel all other written partitions
        } else {
            completePartition();
            mMasterClient.completeStore(mStoreUri);
        }
    } catch (AlluxioException e) {
        throw new IOException(e);
    } finally {
        mMasterClient.close();
    }
    mClosed = true;
}
Also used : 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