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());
}
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;
});
}
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);
}
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);
}
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);
}
Aggregations