Search in sources :

Example 76 with AmazonClientException

use of com.amazonaws.AmazonClientException in project crate by crate.

the class S3BlobContainer method delete.

@Override
public void delete() throws IOException {
    try (AmazonS3Reference clientReference = blobStore.clientReference()) {
        ObjectListing prevListing = null;
        while (true) {
            ObjectListing list;
            if (prevListing != null) {
                final ObjectListing finalPrevListing = prevListing;
                list = clientReference.client().listNextBatchOfObjects(finalPrevListing);
            } else {
                final ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
                listObjectsRequest.setBucketName(blobStore.bucket());
                listObjectsRequest.setPrefix(keyPath);
                list = clientReference.client().listObjects(listObjectsRequest);
            }
            final List<String> blobsToDelete = list.getObjectSummaries().stream().map(S3ObjectSummary::getKey).collect(Collectors.toList());
            if (list.isTruncated()) {
                doDeleteBlobs(blobsToDelete, false);
                prevListing = list;
            } else {
                final List<String> lastBlobsToDelete = new ArrayList<>(blobsToDelete);
                lastBlobsToDelete.add(keyPath);
                doDeleteBlobs(lastBlobsToDelete, false);
                break;
            }
        }
    } catch (final AmazonClientException e) {
        throw new IOException("Exception when deleting blob container [" + keyPath + "]", e);
    }
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) IOException(java.io.IOException)

Example 77 with AmazonClientException

use of com.amazonaws.AmazonClientException in project zeppelin by apache.

the class S3NotebookRepo method list.

@Override
public Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException {
    Map<String, NoteInfo> notesInfo = new HashMap<>();
    try {
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(user + "/" + "notebook");
        ObjectListing objectListing;
        do {
            objectListing = s3client.listObjects(listObjectsRequest);
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                if (objectSummary.getKey().endsWith(".zpln")) {
                    try {
                        NoteInfo info = getNoteInfo(objectSummary.getKey());
                        notesInfo.put(info.getId(), info);
                    } catch (IOException e) {
                        LOGGER.warn(e.getMessage());
                    }
                }
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());
    } catch (AmazonClientException ace) {
        throw new IOException("Fail to list objects in S3", ace);
    }
    return notesInfo;
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 78 with AmazonClientException

use of com.amazonaws.AmazonClientException in project zeppelin by apache.

the class S3NotebookRepo method move.

@Override
public void move(String folderPath, String newFolderPath, AuthenticationInfo subject) throws IOException {
    try {
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(rootFolder + folderPath + "/");
        ObjectListing objectListing;
        do {
            objectListing = s3client.listObjects(listObjectsRequest);
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                if (objectSummary.getKey().endsWith(".zpln")) {
                    String noteId = getNoteId(objectSummary.getKey());
                    String notePath = getNotePath(rootFolder, objectSummary.getKey());
                    String newNotePath = newFolderPath + notePath.substring(folderPath.length());
                    move(noteId, notePath, newNotePath, subject);
                }
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());
    } catch (AmazonClientException ace) {
        throw new IOException("Fail to move folder: " + folderPath + " to " + newFolderPath + " in S3", ace);
    }
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IOException(java.io.IOException)

Example 79 with AmazonClientException

use of com.amazonaws.AmazonClientException in project druid by druid-io.

the class KinesisRecordSupplierTest method getLatestSequenceNumberWhenKinesisRetryableException.

@Test
public void getLatestSequenceNumberWhenKinesisRetryableException() {
    EasyMock.expect(kinesis.getShardIterator(EasyMock.eq(STREAM), EasyMock.eq(SHARD_ID0), EasyMock.eq(ShardIteratorType.LATEST.toString()))).andReturn(getShardIteratorResult0).once();
    EasyMock.expect(getShardIteratorResult0.getShardIterator()).andReturn(SHARD0_ITERATOR).once();
    AmazonClientException ex = new AmazonClientException(new IOException());
    EasyMock.expect(kinesis.getRecords(generateGetRecordsReq(SHARD0_ITERATOR, 1000))).andThrow(ex).andReturn(getRecordsResult0).once();
    EasyMock.expect(getRecordsResult0.getRecords()).andReturn(SHARD0_RECORDS).once();
    EasyMock.expect(getRecordsResult0.getNextShardIterator()).andReturn(null).once();
    EasyMock.expect(getRecordsResult0.getMillisBehindLatest()).andReturn(0L).once();
    replayAll();
    recordSupplier = new KinesisRecordSupplier(kinesis, recordsPerFetch, 0, 2, true, 100, 5000, 5000, 1000, 100, true);
    Assert.assertEquals("0", recordSupplier.getLatestSequenceNumber(StreamPartition.of(STREAM, SHARD_ID0)));
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException) Test(org.junit.Test)

Example 80 with AmazonClientException

use of com.amazonaws.AmazonClientException in project airpal by airbnb.

the class S3FilePersistor method persist.

@Override
public URI persist(JobOutputBuilder outputBuilder, Job job) {
    File file = checkNotNull(outputBuilder.build(), "output builder resulting file was null");
    val objectMetaData = new ObjectMetadata();
    objectMetaData.setContentLength(file.length());
    objectMetaData.setContentType(MediaType.CSV_UTF_8.toString());
    if (compressedOutput) {
        objectMetaData.setContentEncoding("gzip");
    }
    val putRequest = new PutObjectRequest(outputBucket, getOutputKey(file.getName()), file).withMetadata(objectMetaData);
    try {
        s3Client.putObject(putRequest);
        return UriBuilder.fromPath("/api/s3/{filename}").build(file.getName());
    } catch (AmazonClientException e) {
        throw new ExecutionClient.ExecutionFailureException(job, "Could not upload CSV to S3", e);
    } finally {
        outputBuilder.delete();
    }
}
Also used : lombok.val(lombok.val) AmazonClientException(com.amazonaws.AmazonClientException) ExecutionClient(com.airbnb.airpal.core.execution.ExecutionClient) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)202 IOException (java.io.IOException)70 AmazonServiceException (com.amazonaws.AmazonServiceException)32 ArrayList (java.util.ArrayList)32 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)23 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)19 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)17 HashMap (java.util.HashMap)16 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)14 Test (org.junit.Test)14 SienaException (siena.SienaException)12 AWSCredentials (com.amazonaws.auth.AWSCredentials)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)11 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)11 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)11 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)10 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)10 InterruptedIOException (java.io.InterruptedIOException)10 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)9 File (java.io.File)9