Search in sources :

Example 6 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata 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 7 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata 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 8 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata 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 9 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.

the class S3Mock method getObjectMetadata.

public S3ObjectMetadata getObjectMetadata(String bucketName, String key) {
    String objectName = getObjectName(bucketName, key);
    S3ObjectMetadata metadata = new S3ObjectMetadata();
    synchronized (this.objects) {
        ObjectData od = this.objects.get(objectName);
        if (od == null) {
            throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
        }
        metadata.setContentLength((long) od.content.getLength());
        metadata.setLastModified(new Date(System.currentTimeMillis()));
    }
    return metadata;
}
Also used : S3Exception(com.emc.object.s3.S3Exception) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) Date(java.util.Date)

Example 10 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project pravega by pravega.

the class S3Mock method putObject.

public PutObjectResult putObject(PutObjectRequest request) {
    // Fix passed in object metadata.
    if (request.getObjectMetadata() != null) {
        request.setObjectMetadata(new S3ObjectMetadata().withContentType(request.getObjectMetadata().getContentType()).withContentLength(request.getObjectMetadata().getContentLength()));
    }
    String objectName = getObjectName(request.getBucketName(), request.getKey());
    synchronized (this.objects) {
        if (this.objects.containsKey(objectName)) {
            throw new S3Exception(String.format("Object '%s/%s' exists.", request.getBucketName(), request.getKey()), 0, "PreconditionFailed", "");
        }
        if (null != request.getObject()) {
            try {
                val bufferView = new ByteArraySegment(((InputStream) request.getObject()).readAllBytes());
                this.objects.put(objectName, new ObjectData(bufferView, request.getAcl()));
            } catch (IOException ex) {
                throw new S3Exception("Copy error", HttpStatus.SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            this.objects.put(objectName, new ObjectData(BufferView.empty(), request.getAcl()));
        }
        return new PutObjectResult();
    }
}
Also used : lombok.val(lombok.val) ByteArraySegment(io.pravega.common.util.ByteArraySegment) PutObjectResult(com.emc.object.s3.bean.PutObjectResult) S3Exception(com.emc.object.s3.S3Exception) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) IOException(java.io.IOException)

Aggregations

S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)16 S3Exception (com.emc.object.s3.S3Exception)7 S3ObjectMetadata (com.formkiq.aws.s3.S3ObjectMetadata)7 S3ObjectMetadata (uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)7 S3Client (software.amazon.awssdk.services.s3.S3Client)5 AccessControlList (com.emc.object.s3.bean.AccessControlList)4 PutObjectRequest (com.emc.object.s3.request.PutObjectRequest)4 Test (org.junit.Test)4 CopyPartResult (com.emc.object.s3.bean.CopyPartResult)3 MultipartPartETag (com.emc.object.s3.bean.MultipartPartETag)3 PutObjectResult (com.emc.object.s3.bean.PutObjectResult)3 CompleteMultipartUploadRequest (com.emc.object.s3.request.CompleteMultipartUploadRequest)3 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)3 ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)3 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)3 ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)3 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)3 Date (java.util.Date)3 TreeSet (java.util.TreeSet)3 CanonicalUser (com.emc.object.s3.bean.CanonicalUser)2