com.amazonaws.services.s3.model.DeleteVersionRequest Java Examples

The following examples show how to use com.amazonaws.services.s3.model.DeleteVersionRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDeleteS3Object.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteObjectSimple() throws IOException {
    runner.setProperty(DeleteS3Object.REGION, "us-west-2");
    runner.setProperty(DeleteS3Object.BUCKET, "test-bucket");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "delete-key");
    runner.enqueue(new byte[0], attrs);

    runner.run(1);

    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
    ArgumentCaptor<DeleteObjectRequest> captureRequest = ArgumentCaptor.forClass(DeleteObjectRequest.class);
    Mockito.verify(mockS3Client, Mockito.times(1)).deleteObject(captureRequest.capture());
    DeleteObjectRequest request = captureRequest.getValue();
    assertEquals("test-bucket", request.getBucketName());
    assertEquals("delete-key", request.getKey());
    Mockito.verify(mockS3Client, Mockito.never()).deleteVersion(Mockito.any(DeleteVersionRequest.class));
}
 
Example #2
Source File: TestDeleteS3Object.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteVersionSimple() {
    runner.setProperty(DeleteS3Object.REGION, "us-west-2");
    runner.setProperty(DeleteS3Object.BUCKET, "test-bucket");
    runner.setProperty(DeleteS3Object.VERSION_ID, "test-version");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "test-key");
    runner.enqueue(new byte[0], attrs);

    runner.run(1);

    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
    ArgumentCaptor<DeleteVersionRequest> captureRequest = ArgumentCaptor.forClass(DeleteVersionRequest.class);
    Mockito.verify(mockS3Client, Mockito.times(1)).deleteVersion(captureRequest.capture());
    DeleteVersionRequest request = captureRequest.getValue();
    assertEquals("test-bucket", request.getBucketName());
    assertEquals("test-key", request.getKey());
    assertEquals("test-version", request.getVersionId());
    Mockito.verify(mockS3Client, Mockito.never()).deleteObject(Mockito.any(DeleteObjectRequest.class));
}
 
Example #3
Source File: TestDeleteS3Object.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteVersionFromExpressions() {
    runner.setProperty(DeleteS3Object.REGION, "us-west-2");
    runner.setProperty(DeleteS3Object.BUCKET, "${s3.bucket}");
    runner.setProperty(DeleteS3Object.VERSION_ID, "${s3.version}");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "test-key");
    attrs.put("s3.bucket", "test-bucket");
    attrs.put("s3.version", "test-version");
    runner.enqueue(new byte[0], attrs);

    runner.run(1);

    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
    ArgumentCaptor<DeleteVersionRequest> captureRequest = ArgumentCaptor.forClass(DeleteVersionRequest.class);
    Mockito.verify(mockS3Client, Mockito.times(1)).deleteVersion(captureRequest.capture());
    DeleteVersionRequest request = captureRequest.getValue();
    assertEquals("test-bucket", request.getBucketName());
    assertEquals("test-key", request.getKey());
    assertEquals("test-version", request.getVersionId());
    Mockito.verify(mockS3Client, Mockito.never()).deleteObject(Mockito.any(DeleteObjectRequest.class));
}
 
Example #4
Source File: TestDeleteS3Object.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteObjectS3Exception() {
    runner.setProperty(DeleteS3Object.REGION, "us-west-2");
    runner.setProperty(DeleteS3Object.BUCKET, "test-bucket");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "delete-key");
    runner.enqueue(new byte[0], attrs);
    Mockito.doThrow(new AmazonS3Exception("NoSuchBucket")).when(mockS3Client).deleteObject(Mockito.any());

    runner.run(1);

    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_FAILURE, 1);
    ArgumentCaptor<DeleteObjectRequest> captureRequest = ArgumentCaptor.forClass(DeleteObjectRequest.class);
    Mockito.verify(mockS3Client, Mockito.never()).deleteVersion(Mockito.any(DeleteVersionRequest.class));
}
 
Example #5
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public void deleteVersion(DeleteVersionRequest delVerReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #6
Source File: Delete.java    From cloudExplorer with GNU General Public License v3.0 4 votes vote down vote up
public void run() {
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration());
    if (endpoint.contains("amazonaws.com")) {
        String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket));
        if (aws_endpoint.contains("US")) {
            s3Client.setEndpoint("https://s3.amazonaws.com");
        } else if (aws_endpoint.contains("us-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("eu-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("ap-")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("sa-east-1")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else {
            s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com");
        }
    } else {
        s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
        s3Client.setEndpoint(endpoint);
    }

    try {

        if (version != null) {
            s3Client.deleteVersion(new DeleteVersionRequest(bucket, what, version));
        } else {
            s3Client.deleteObject(new DeleteObjectRequest(bucket, what));
        }
        if (!debug) {
            NewJFrame.jTextArea1.append("\nDeleted file: " + what);
        }
        calibrate();
    } catch (AmazonServiceException ase) {
        if (NewJFrame.gui) {
            mainFrame.jTextArea1.append("\n\nError Message:    " + ase.getMessage());
            mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode());
            mainFrame.jTextArea1.append("\nAWS Error Code:   " + ase.getErrorCode());
            mainFrame.jTextArea1.append("\nError Type:       " + ase.getErrorType());
            mainFrame.jTextArea1.append("\nRequest ID:       " + ase.getRequestId());
            calibrate();
        } else {
            System.out.print("\n\nError Message:    " + ase.getMessage());
            System.out.print("\nHTTP Status Code: " + ase.getStatusCode());
            System.out.print("\nAWS Error Code:   " + ase.getErrorCode());
            System.out.print("\nError Type:       " + ase.getErrorType());
            System.out.print("\nRequest ID:       " + ase.getRequestId());
        }
    } catch (Exception delete) {
    }
}
 
Example #7
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void deleteVersion(DeleteVersionRequest deleteVersionRequest) throws AmazonClientException,
    AmazonServiceException {
  // TODO Auto-generated method stub

}