Search in sources :

Example 1 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException 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 ChunkStorageException

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

the class ExtendedS3ChunkStorage method doGetInfo.

@Override
protected ChunkInfo doGetInfo(String chunkName) throws ChunkStorageException {
    try {
        S3ObjectMetadata result = client.getObjectMetadata(config.getBucket(), getObjectPath(chunkName));
        ChunkInfo information = ChunkInfo.builder().name(chunkName).length(result.getContentLength()).build();
        return information;
    } catch (Exception e) {
        throw convertException(chunkName, "doGetInfo", e);
    }
}
Also used : ChunkInfo(io.pravega.segmentstore.storage.chunklayer.ChunkInfo) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) 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 3 with ChunkStorageException

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

the class ExtendedS3ChunkStorage method doCreateWithContent.

@Override
protected ChunkHandle doCreateWithContent(String chunkName, int length, InputStream data) throws ChunkStorageException {
    try {
        val objectPath = getObjectPath(chunkName);
        S3ObjectMetadata metadata = new S3ObjectMetadata().withContentType("application/octet-stream").withContentLength(length);
        val request = new PutObjectRequest(this.config.getBucket(), objectPath, data).withObjectMetadata(metadata);
        client.putObject(request);
        return ChunkHandle.writeHandle(chunkName);
    } catch (Exception e) {
        throw convertException(chunkName, "doCreateWithContent", e);
    }
}
Also used : lombok.val(lombok.val) 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 4 with ChunkStorageException

use of io.pravega.segmentstore.storage.chunklayer.ChunkStorageException 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 5 with ChunkStorageException

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

the class ExtendedS3ChunkStorage method doWrite.

@Override
protected int doWrite(ChunkHandle handle, long offset, int length, InputStream data) throws ChunkStorageException {
    Preconditions.checkState(supportsAppend, "supportsAppend is false.");
    try {
        val objectPath = getObjectPath(handle.getChunkName());
        // Check object exists.
        val metadata = client.getObjectMetadata(config.getBucket(), objectPath);
        if (metadata.getContentLength() != offset) {
            throw new InvalidOffsetException(handle.getChunkName(), metadata.getContentLength(), offset, "doWrite");
        }
        // Put data.
        client.putObject(this.config.getBucket(), objectPath, Range.fromOffsetLength(offset, length), data);
        return length;
    } catch (Exception e) {
        throw convertException(handle.getChunkName(), "doWrite", e);
    }
}
Also used : lombok.val(lombok.val) InvalidOffsetException(io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException) 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)

Aggregations

ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)18 ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)13 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)12 lombok.val (lombok.val)9 S3Exception (com.emc.object.s3.S3Exception)6 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)6 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)6 S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 PutObjectRequest (com.emc.object.s3.request.PutObjectRequest)2 Cleanup (lombok.Cleanup)2 CopyPartResult (com.emc.object.s3.bean.CopyPartResult)1 MultipartPartETag (com.emc.object.s3.bean.MultipartPartETag)1 AbortMultipartUploadRequest (com.emc.object.s3.request.AbortMultipartUploadRequest)1 CompleteMultipartUploadRequest (com.emc.object.s3.request.CompleteMultipartUploadRequest)1 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)1 ChunkHandle (io.pravega.segmentstore.storage.chunklayer.ChunkHandle)1 ChunkInfo (io.pravega.segmentstore.storage.chunklayer.ChunkInfo)1 ConcatArgument (io.pravega.segmentstore.storage.chunklayer.ConcatArgument)1