Search in sources :

Example 6 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project zeppelin by apache.

the class OSSNotebookRepo method remove.

@Override
public void remove(String folderPath, AuthenticationInfo subject) {
    String nextMarker = null;
    ObjectListing objectListing = null;
    do {
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName).withPrefix(rootFolder + folderPath + "/").withMarker(nextMarker);
        objectListing = ossClient.listObjects(listObjectsRequest);
        if (!objectListing.getObjectSummaries().isEmpty()) {
            List<String> keys = new ArrayList<>();
            for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
                keys.add(s.getKey());
            }
            DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName).withKeys(keys);
            ossClient.deleteObjects(deleteObjectsRequest);
        }
        nextMarker = objectListing.getNextMarker();
    } while (objectListing.isTruncated());
}
Also used : ListObjectsRequest(com.aliyun.oss.model.ListObjectsRequest) OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) ArrayList(java.util.ArrayList) ObjectListing(com.aliyun.oss.model.ObjectListing) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest)

Example 7 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssUtils method deleteBucketKeys.

private static void deleteBucketKeys(OSS client, String bucket, List<String> keysToDelete) throws Exception {
    DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucket).withKeys(keysToDelete);
    OssUtils.retry(() -> {
        client.deleteObjects(deleteRequest);
        return null;
    });
}
Also used : DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest)

Example 8 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssTaskLogsTest method test_killAll_recoverableExceptionWhenDeletingObjects_deletesAllTaskLogs.

@Test
public void test_killAll_recoverableExceptionWhenDeletingObjects_deletesAllTaskLogs() throws IOException {
    OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
    EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
    OssTestUtils.expectListObjects(ossClient, PREFIX_URI, ImmutableList.of(objectSummary1));
    DeleteObjectsRequest expectedRequest = new DeleteObjectsRequest(TEST_BUCKET);
    expectedRequest.setKeys(Collections.singletonList(KEY_1));
    OssTestUtils.mockClientDeleteObjects(ossClient, ImmutableList.of(expectedRequest), ImmutableMap.of(expectedRequest, RECOVERABLE_EXCEPTION));
    EasyMock.replay(ossClient, timeSupplier);
    OssTaskLogsConfig config = new OssTaskLogsConfig();
    config.setBucket(TEST_BUCKET);
    config.setPrefix(TEST_PREFIX);
    OssInputDataConfig inputDataConfig = new OssInputDataConfig();
    inputDataConfig.setMaxListingLength(MAX_KEYS);
    OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
    taskLogs.killAll();
    EasyMock.verify(ossClient, timeSupplier);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 9 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssTaskLogsTest method test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs.

@Test
public void test_killAll_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs() {
    boolean ioExceptionThrown = false;
    try {
        OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
        EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
        OssTestUtils.expectListObjects(ossClient, PREFIX_URI, ImmutableList.of(objectSummary1));
        DeleteObjectsRequest deleteRequest1 = new DeleteObjectsRequest(TEST_BUCKET);
        deleteRequest1.setKeys(Collections.singletonList(KEY_1));
        OssTestUtils.mockClientDeleteObjects(ossClient, ImmutableList.of(), ImmutableMap.of(deleteRequest1, NON_RECOVERABLE_EXCEPTION));
        EasyMock.replay(ossClient, timeSupplier);
        OssTaskLogsConfig config = new OssTaskLogsConfig();
        config.setBucket(TEST_BUCKET);
        config.setPrefix(TEST_PREFIX);
        OssInputDataConfig inputDataConfig = new OssInputDataConfig();
        inputDataConfig.setMaxListingLength(MAX_KEYS);
        OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
        taskLogs.killAll();
    } catch (IOException e) {
        ioExceptionThrown = true;
    }
    Assert.assertTrue(ioExceptionThrown);
    EasyMock.verify(ossClient, timeSupplier);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) IOException(java.io.IOException) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 10 with DeleteObjectsRequest

use of com.aliyun.oss.model.DeleteObjectsRequest in project druid by druid-io.

the class OssTaskLogsTest method test_killOlderThan_recoverableExceptionWhenListingObjects_deletesAllTaskLogs.

@Test
public void test_killOlderThan_recoverableExceptionWhenListingObjects_deletesAllTaskLogs() throws IOException {
    OSSObjectSummary objectSummary1 = OssTestUtils.newOSSObjectSummary(TEST_BUCKET, KEY_1, TIME_0);
    OssTestUtils.expectListObjects(ossClient, PREFIX_URI, ImmutableList.of(objectSummary1));
    DeleteObjectsRequest deleteRequest1 = new DeleteObjectsRequest(TEST_BUCKET);
    deleteRequest1.setKeys(Collections.singletonList(KEY_1));
    OssTestUtils.mockClientDeleteObjects(ossClient, ImmutableList.of(deleteRequest1), ImmutableMap.of(deleteRequest1, RECOVERABLE_EXCEPTION));
    EasyMock.replay(ossClient, timeSupplier);
    OssTaskLogsConfig config = new OssTaskLogsConfig();
    config.setBucket(TEST_BUCKET);
    config.setPrefix(TEST_PREFIX);
    OssInputDataConfig inputDataConfig = new OssInputDataConfig();
    inputDataConfig.setMaxListingLength(MAX_KEYS);
    OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
    taskLogs.killOlderThan(TIME_NOW);
    EasyMock.verify(ossClient, timeSupplier);
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) DeleteObjectsRequest(com.aliyun.oss.model.DeleteObjectsRequest) Test(org.junit.Test)

Aggregations

DeleteObjectsRequest (com.aliyun.oss.model.DeleteObjectsRequest)23 Test (org.junit.Test)15 OSSObjectSummary (com.aliyun.oss.model.OSSObjectSummary)12 ArrayList (java.util.ArrayList)10 DeleteObjectsResult (com.aliyun.oss.model.DeleteObjectsResult)9 IOException (java.io.IOException)4 ListObjectsRequest (com.aliyun.oss.model.ListObjectsRequest)3 ObjectListing (com.aliyun.oss.model.ObjectListing)3 ClientException (com.aliyun.oss.ClientException)2 OSS (com.aliyun.oss.OSS)2 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)2 OSSException (com.aliyun.oss.OSSException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 AbortMultipartUploadRequest (com.aliyun.oss.model.AbortMultipartUploadRequest)1 AppendObjectRequest (com.aliyun.oss.model.AppendObjectRequest)1 AppendObjectResult (com.aliyun.oss.model.AppendObjectResult)1 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)1 CopyObjectResult (com.aliyun.oss.model.CopyObjectResult)1