Search in sources :

Example 1 with ChunkAlreadyExistsException

use of io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException in project pravega by pravega.

the class ExtendedS3ChunkStorage method doCreate.

@Override
protected ChunkHandle doCreate(String chunkName) throws ChunkStorageException {
    Preconditions.checkState(supportsAppend, "supportsAppend is false.");
    try {
        if (!client.listObjects(config.getBucket(), getObjectPath(chunkName)).getObjects().isEmpty()) {
            throw new ChunkAlreadyExistsException(chunkName, "Chunk already exists");
        }
        S3ObjectMetadata metadata = new S3ObjectMetadata();
        metadata.setContentLength((long) 0);
        PutObjectRequest request = new PutObjectRequest(config.getBucket(), getObjectPath(chunkName), null).withObjectMetadata(metadata);
        if (config.isUseNoneMatch()) {
            request.setIfNoneMatch("*");
        }
        client.putObject(request);
        return ChunkHandle.writeHandle(chunkName);
    } catch (Exception e) {
        throw convertException(chunkName, "doCreate", e);
    }
}
Also used : ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) PutObjectRequest(com.emc.object.s3.request.PutObjectRequest) InvalidOffsetException(io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException) S3Exception(com.emc.object.s3.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)

Example 2 with ChunkAlreadyExistsException

use of io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException in project pravega by pravega.

the class ExtendedS3ChunkStorage method convertException.

private ChunkStorageException convertException(String chunkName, String message, Exception e) {
    ChunkStorageException retValue = null;
    if (e instanceof ChunkStorageException) {
        return (ChunkStorageException) e;
    }
    if (e instanceof S3Exception) {
        S3Exception s3Exception = (S3Exception) e;
        String errorCode = Strings.nullToEmpty(s3Exception.getErrorCode());
        if (errorCode.equals("NoSuchKey")) {
            retValue = new ChunkNotFoundException(chunkName, message, e);
        }
        if (errorCode.equals("PreconditionFailed")) {
            retValue = new ChunkAlreadyExistsException(chunkName, message, e);
        }
        if (errorCode.equals("InvalidRange") || errorCode.equals("InvalidArgument") || errorCode.equals("MethodNotAllowed") || s3Exception.getHttpCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            throw new IllegalArgumentException(chunkName, e);
        }
        if (errorCode.equals("AccessDenied")) {
            retValue = new ChunkStorageException(chunkName, String.format("Access denied for chunk %s - %s.", chunkName, message), e);
        }
    }
    if (retValue == null) {
        retValue = new ChunkStorageException(chunkName, message, e);
    }
    return retValue;
}
Also used : ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) S3Exception(com.emc.object.s3.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)

Example 3 with ChunkAlreadyExistsException

use of io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException in project pravega by pravega.

the class HDFSChunkStorage method doCreate.

@Override
protected ChunkHandle doCreate(String chunkName) throws ChunkStorageException {
    ensureInitializedAndNotClosed();
    try {
        Path fullPath = getFilePath(chunkName);
        // Create the file, and then immediately close the returned OutputStream, so that HDFS may properly create the file.
        this.fileSystem.create(fullPath, READWRITE_PERMISSION, false, 0, this.config.getReplication(), this.config.getBlockSize(), null).close();
        log.debug("Created '{}'.", fullPath);
        // return handle
        return ChunkHandle.writeHandle(chunkName);
    } catch (FileAlreadyExistsException e) {
        throw new ChunkAlreadyExistsException(chunkName, "HDFSChunkStorage::doCreate");
    } catch (IOException e) {
        throw convertException(chunkName, "doCreate", e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) IOException(java.io.IOException)

Example 4 with ChunkAlreadyExistsException

use of io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException in project pravega by pravega.

the class S3ChunkStorage method convertException.

private ChunkStorageException convertException(String chunkName, String message, Exception e) {
    ChunkStorageException retValue = null;
    if (e instanceof ChunkStorageException) {
        return (ChunkStorageException) e;
    }
    if (e instanceof S3Exception) {
        S3Exception s3Exception = (S3Exception) e;
        String errorCode = Strings.nullToEmpty(s3Exception.awsErrorDetails().errorCode());
        if (errorCode.equals(NO_SUCH_KEY)) {
            retValue = new ChunkNotFoundException(chunkName, message, e);
        }
        if (errorCode.equals(PRECONDITION_FAILED)) {
            retValue = new ChunkAlreadyExistsException(chunkName, message, e);
        }
        if (errorCode.equals(INVALID_RANGE) || errorCode.equals(INVALID_ARGUMENT) || errorCode.equals(METHOD_NOT_ALLOWED) || s3Exception.awsErrorDetails().sdkHttpResponse().statusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            throw new IllegalArgumentException(chunkName, e);
        }
        if (errorCode.equals(ACCESS_DENIED)) {
            retValue = new ChunkStorageException(chunkName, String.format("Access denied for chunk %s - %s.", chunkName, message), e);
        }
    }
    if (retValue == null) {
        retValue = new ChunkStorageException(chunkName, message, e);
    }
    return retValue;
}
Also used : ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)

Example 5 with ChunkAlreadyExistsException

use of io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException in project pravega by pravega.

the class InMemoryChunkStorage method doCreateWithContent.

@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
    Preconditions.checkNotNull(chunkName);
    if (null != chunks.putIfAbsent(chunkName, new InMemoryChunk(chunkName))) {
        throw new ChunkAlreadyExistsException(chunkName, "InMemoryChunkStorage::doCreate");
    }
    ChunkHandle handle = new ChunkHandle(chunkName, false);
    int bytesWritten = doWriteInternal(handle, 0, length, data);
    if (bytesWritten < length) {
        doDelete(ChunkHandle.writeHandle(chunkName));
        throw new ChunkStorageException(chunkName, "doCreateWithContent - invalid length returned");
    }
    return handle;
}
Also used : ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) ChunkHandle(io.pravega.segmentstore.storage.chunklayer.ChunkHandle) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)

Aggregations

ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)5 ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)4 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)3 S3Exception (com.emc.object.s3.S3Exception)2 S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)1 PutObjectRequest (com.emc.object.s3.request.PutObjectRequest)1 ChunkHandle (io.pravega.segmentstore.storage.chunklayer.ChunkHandle)1 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)1 IOException (java.io.IOException)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 Path (org.apache.hadoop.fs.Path)1 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)1