Search in sources :

Example 6 with Tag

use of software.amazon.awssdk.services.s3.model.Tag in project janusgraph by JanusGraph.

the class AwsCodePipelinesCi method run.

private void run() throws IOException {
    final File file = new File(getOptionValue(PIPELINES_JSON_OPTION));
    final Region region = Region.of(getOptionValue(REGION_OPTION));
    final AwsCredentialsProvider provider = ProfileCredentialsProvider.builder().profileName(getOptionValue(PROFILE_OPTION)).build();
    final ClientHttpConfiguration http = ClientHttpConfiguration.builder().httpClient(// consider netty some other time
    ApacheSdkHttpClientFactory.builder().socketTimeout(Duration.ofSeconds(10)).connectionTimeout(Duration.ofMillis(750)).build().createHttpClient()).build();
    final AwsCodePipelinesLogic.AwsCodePipelinesLogicBuilder builder = AwsCodePipelinesLogic.builder().githubToken(getOptionValue(GITHUB_TOKEN_OPTION)).githubOwner(getOptionValue(GITHUB_OWNER_OPTION)).githubRepo(getOptionValue(GITHUB_REPO_OPTION)).githubBranch(getOptionValue(GITHUB_BRANCH_OPTION)).codeBuildServiceRoleArn(getOptionValue(CODE_BUILD_SERVICE_ROLE_ARN_OPTION)).codePipelineRoleArn(getOptionValue(CODEPIPELINE_ROLE_ARN_OPTION)).s3Bucket(getOptionValue(BUCKET_OPTION)).s3BucketLocationConstraint(BucketLocationConstraint.fromValue(region.value())).s3(S3Client.builder().httpConfiguration(http).region(region).credentialsProvider(provider).build()).codeBuild(CodeBuildClient.builder().httpConfiguration(http).region(region).credentialsProvider(provider).build()).codePipeline(CodePipelineClient.builder().httpConfiguration(http).region(region).credentialsProvider(provider).build());
    final Tag timeTag = Tag.builder().key("date").value(Long.toString(System.currentTimeMillis())).build();
    final PipelineDefinitions definitions = new ObjectMapper(new YAMLFactory()).readValue(file, PipelineDefinitions.class);
    definitions.getPipelines().stream().map(def -> builder.pipelineName(def.getName()).sourceOutputArtifactName(def.getName() + "Source").parallelBuildActions(def.getParallelBuildActions()).defaultComputeImage(definitions.getDefaultComputeImage()).defaultComputeType(definitions.getDefaultComputeType()).defaultPrivilegedMode(definitions.isDefaultPrivilegedMode()).tags(ImmutableList.of(Tag.builder().key("project").value(def.getName()).build(), timeTag)).build()).forEach(AwsCodePipelinesLogic::run);
}
Also used : IAMException(software.amazon.awssdk.services.iam.model.IAMException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Options(org.apache.commons.cli.Options) PipelineDefinitions(org.janusgraph.codepipelines.model.PipelineDefinitions) CodeBuildClient(software.amazon.awssdk.services.codebuild.CodeBuildClient) BucketLocationConstraint(software.amazon.awssdk.services.s3.model.BucketLocationConstraint) DefaultParser(org.apache.commons.cli.DefaultParser) ImmutableList(com.google.common.collect.ImmutableList) ApacheSdkHttpClientFactory(software.amazon.awssdk.http.apache.ApacheSdkHttpClientFactory) Duration(java.time.Duration) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) CommandLine(org.apache.commons.cli.CommandLine) Region(software.amazon.awssdk.regions.Region) Option(org.apache.commons.cli.Option) ClientHttpConfiguration(software.amazon.awssdk.client.builder.ClientHttpConfiguration) S3Client(software.amazon.awssdk.services.s3.S3Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) CodePipelineClient(software.amazon.awssdk.services.codepipeline.CodePipelineClient) File(java.io.File) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ParseException(org.apache.commons.cli.ParseException) AwsCredentialsProvider(software.amazon.awssdk.auth.AwsCredentialsProvider) ProfileCredentialsProvider(software.amazon.awssdk.auth.ProfileCredentialsProvider) Tag(software.amazon.awssdk.services.s3.model.Tag) ClientHttpConfiguration(software.amazon.awssdk.client.builder.ClientHttpConfiguration) AwsCredentialsProvider(software.amazon.awssdk.auth.AwsCredentialsProvider) Region(software.amazon.awssdk.regions.Region) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) PipelineDefinitions(org.janusgraph.codepipelines.model.PipelineDefinitions) Tag(software.amazon.awssdk.services.s3.model.Tag) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with Tag

use of software.amazon.awssdk.services.s3.model.Tag in project wildfly-camel by wildfly-extras.

the class EC2IntegrationTest method testCreateInstance.

@Test
public void testCreateInstance() throws Exception {
    AmazonEC2Client ec2Client = provider.getClient();
    Assume.assumeNotNull("AWS client not null", ec2Client);
    assertNoStaleInstances(ec2Client, "before");
    try {
        WildFlyCamelContext camelctx = new WildFlyCamelContext();
        camelctx.getNamingContext().bind("ec2Client", ec2Client);
        camelctx.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:createAndRun").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=createAndRunInstances");
                from("direct:terminate").to("aws-ec2://TestDomain?amazonEc2Client=#ec2Client&operation=terminateInstances");
            }
        });
        camelctx.start();
        try {
            // Create and run an instance
            Map<String, Object> headers = new HashMap<>();
            headers.put(EC2Constants.IMAGE_ID, "ami-02ace471");
            headers.put(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            headers.put(EC2Constants.SUBNET_ID, EC2Utils.getSubnetId(ec2Client));
            headers.put(EC2Constants.INSTANCE_MIN_COUNT, 1);
            headers.put(EC2Constants.INSTANCE_MAX_COUNT, 1);
            headers.put(EC2Constants.INSTANCES_TAGS, Arrays.asList(new Tag("Name", "wildfly-camel")));
            ProducerTemplate template = camelctx.createProducerTemplate();
            RunInstancesResult result1 = template.requestBodyAndHeaders("direct:createAndRun", null, headers, RunInstancesResult.class);
            String instanceId = result1.getReservation().getInstances().get(0).getInstanceId();
            System.out.println("InstanceId: " + instanceId);
            // Terminate the instance
            headers = new HashMap<>();
            headers.put(EC2Constants.INSTANCES_IDS, Collections.singleton(instanceId));
            TerminateInstancesResult result2 = template.requestBodyAndHeaders("direct:terminate", null, headers, TerminateInstancesResult.class);
            Assert.assertEquals(instanceId, result2.getTerminatingInstances().get(0).getInstanceId());
        } finally {
            camelctx.stop();
        }
    } finally {
        assertNoStaleInstances(ec2Client, "after");
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Tag(com.amazonaws.services.ec2.model.Tag) Test(org.junit.Test)

Example 8 with Tag

use of software.amazon.awssdk.services.s3.model.Tag in project herd by FINRAOS.

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method runExecuteS3SpecificStepsTest.

private void runExecuteS3SpecificStepsTest() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a storage file path.
    String storageFilePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE;
    // Create a business object data destroy parameters DTO.
    BusinessObjectDataDestroyDto businessObjectDataDestroyDto = new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
    // Create an S3 file transfer parameters DTO to access the S3 bucket.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    // Create an S3 file transfer parameters DTO to be used for S3 object tagging operation.
    S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
    // Create a list of all S3 files matching the S3 key prefix form the S3 bucket.
    List<S3ObjectSummary> actualS3Files = Arrays.asList(new S3ObjectSummary());
    // Create a list of storage files selected for S3 object tagging.
    List<StorageFile> storageFilesSelectedForTagging = Arrays.asList(new StorageFile());
    // Create a list of storage files selected for S3 object tagging.
    List<File> filesSelectedForTagging = Arrays.asList(new File(storageFilePath));
    // Create an updated S3 file transfer parameters DTO to access the S3 bucket.
    S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
    updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
    updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
    updatedS3FileTransferRequestParamsDto.setFiles(filesSelectedForTagging);
    // Create an updated S3 file transfer parameters DTO to be used for S3 object tagging operation.
    S3FileTransferRequestParamsDto updatedS3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    updatedS3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    updatedS3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    updatedS3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
    updatedS3ObjectTaggerParamsDto.setS3Endpoint(S3_ENDPOINT);
    // Mock the external calls.
    when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
    when(storageHelper.getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME)).thenReturn(s3ObjectTaggerParamsDto);
    when(s3Service.listDirectory(s3FileTransferRequestParamsDto, false)).thenReturn(actualS3Files);
    when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(actualS3Files)).thenReturn(storageFilesSelectedForTagging);
    when(storageFileHelper.getFiles(storageFilesSelectedForTagging)).thenReturn(filesSelectedForTagging);
    // Call the method under test.
    businessObjectDataInitiateDestroyHelperServiceImpl.executeS3SpecificSteps(businessObjectDataDestroyDto);
    // Verify the external calls.
    verify(storageHelper).getS3FileTransferRequestParamsDto();
    verify(storageHelper).getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, false);
    verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(actualS3Files);
    verify(storageFileHelper).getFiles(storageFilesSelectedForTagging);
    verify(s3Service).tagObjects(updatedS3FileTransferRequestParamsDto, updatedS3ObjectTaggerParamsDto, new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE));
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), businessObjectDataDestroyDto);
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageFile(org.finra.herd.model.api.xml.StorageFile) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Tag(com.amazonaws.services.s3.model.Tag) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) File(java.io.File) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataDestroyDto(org.finra.herd.model.dto.BusinessObjectDataDestroyDto)

Example 9 with Tag

use of software.amazon.awssdk.services.s3.model.Tag in project herd by FINRAOS.

the class StoragePolicyProcessorHelperServiceImplTest method testExecuteStoragePolicyTransitionImpl.

@Test
public void testExecuteStoragePolicyTransitionImpl() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a storage file path.
    String storageFilePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE;
    // Create a list of storage files to be passed as an input.
    List<StorageFile> storageFiles = Arrays.asList(new StorageFile(storageFilePath, FILE_SIZE_1_KB, ROW_COUNT_1000));
    // Create a storage policy transition parameters DTO.
    StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto = new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    // Create an S3 file transfer parameters DTO to access the S3 bucket.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    // Create an S3 file transfer parameters DTO to be used for S3 object tagging operation.
    S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
    // Create a list of S3 object summaries selected without zero byte directory markers.
    List<S3ObjectSummary> actualS3FilesWithoutZeroByteDirectoryMarkers = Arrays.asList(new S3ObjectSummary());
    // Create a list of all S3 files matching the S3 key prefix form the S3 bucket.
    List<S3ObjectSummary> actualS3Files = Arrays.asList(new S3ObjectSummary());
    // Create a list of storage files selected for S3 object tagging.
    List<StorageFile> storageFilesSelectedForTagging = Arrays.asList(new StorageFile());
    // Create a list of storage files selected for S3 object tagging.
    List<File> filesSelectedForTagging = Arrays.asList(new File(storageFilePath));
    // Create an updated S3 file transfer parameters DTO to access the S3 bucket.
    S3FileTransferRequestParamsDto updatedS3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    updatedS3FileTransferRequestParamsDto.setS3Endpoint(S3_ENDPOINT);
    updatedS3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
    updatedS3FileTransferRequestParamsDto.setS3KeyPrefix(TEST_S3_KEY_PREFIX + "/");
    updatedS3FileTransferRequestParamsDto.setFiles(filesSelectedForTagging);
    // Create an updated S3 file transfer parameters DTO to be used for S3 object tagging operation.
    S3FileTransferRequestParamsDto updatedS3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    updatedS3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    updatedS3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    updatedS3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
    updatedS3ObjectTaggerParamsDto.setS3Endpoint(S3_ENDPOINT);
    // Mock the external calls.
    when(storageHelper.getS3FileTransferRequestParamsDto()).thenReturn(s3FileTransferRequestParamsDto);
    when(storageHelper.getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME)).thenReturn(s3ObjectTaggerParamsDto);
    when(s3Service.listDirectory(s3FileTransferRequestParamsDto, true)).thenReturn(actualS3FilesWithoutZeroByteDirectoryMarkers);
    when(s3Service.listDirectory(s3FileTransferRequestParamsDto, false)).thenReturn(actualS3Files);
    when(storageFileHelper.createStorageFilesFromS3ObjectSummaries(actualS3Files)).thenReturn(storageFilesSelectedForTagging);
    when(storageFileHelper.getFiles(storageFilesSelectedForTagging)).thenReturn(filesSelectedForTagging);
    // Call the method under test.
    storagePolicyProcessorHelperServiceImpl.executeStoragePolicyTransitionImpl(storagePolicyTransitionParamsDto);
    // Verify the external calls.
    verify(storageHelper).getS3FileTransferRequestParamsDto();
    verify(storageHelper).getS3FileTransferRequestParamsDtoByRole(S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME);
    verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, true);
    verify(storageFileHelper).validateRegisteredS3Files(storageFiles, actualS3FilesWithoutZeroByteDirectoryMarkers, STORAGE_NAME, businessObjectDataKey);
    verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, true);
    verify(s3Service).listDirectory(s3FileTransferRequestParamsDto, false);
    verify(storageFileHelper).createStorageFilesFromS3ObjectSummaries(actualS3Files);
    verify(storageFileHelper).getFiles(storageFilesSelectedForTagging);
    verify(s3Service).tagObjects(updatedS3FileTransferRequestParamsDto, updatedS3ObjectTaggerParamsDto, new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE));
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(new StoragePolicyTransitionParamsDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ENABLED, storageFiles, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME), storagePolicyTransitionParamsDto);
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageFile(org.finra.herd.model.api.xml.StorageFile) StoragePolicyTransitionParamsDto(org.finra.herd.model.dto.StoragePolicyTransitionParamsDto) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Tag(com.amazonaws.services.s3.model.Tag) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) File(java.io.File) StorageFile(org.finra.herd.model.api.xml.StorageFile) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 10 with Tag

use of software.amazon.awssdk.services.s3.model.Tag in project herd by FINRAOS.

the class S3DaoImplTest method testTagObjectsS3ClientCreationFails.

@Test
public void testTagObjectsS3ClientCreationFails() {
    // Create an S3 key.
    String s3Key = S3_KEY_PREFIX + "/" + LOCAL_FILE;
    // Create an S3 file transfer request parameters DTO to access S3 objects without specifying S3 files.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);
    s3FileTransferRequestParamsDto.setFiles(Arrays.asList(new File(s3Key)));
    // Create an S3 file transfer request parameters DTO to tag S3 objects.
    S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
    // Create an S3 object tag.
    Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE);
    // Mock the external calls.
    when(retryPolicyFactory.getRetryPolicy()).thenThrow(new AmazonServiceException(ERROR_MESSAGE));
    // Try to call the method under test.
    try {
        s3DaoImpl.tagObjects(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto, tag);
    } catch (IllegalStateException e) {
        assertEquals(String.format("Failed to tag S3 object with \"%s\" key in \"%s\" bucket. Reason: %s (Service: null; Status Code: 0; Error Code: null; Request ID: null)", s3Key, S3_BUCKET_NAME, ERROR_MESSAGE), e.getMessage());
    }
    // Verify the external calls.
    verify(retryPolicyFactory).getRetryPolicy();
    verifyNoMoreInteractionsHelper();
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) AmazonServiceException(com.amazonaws.AmazonServiceException) Tag(com.amazonaws.services.s3.model.Tag) File(java.io.File) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Aggregations

Tag (com.amazonaws.services.ec2.model.Tag)38 ArrayList (java.util.ArrayList)27 Tag (com.amazonaws.services.s3.model.Tag)18 HashMap (java.util.HashMap)17 Test (org.junit.Test)16 Instance (com.amazonaws.services.ec2.model.Instance)15 List (java.util.List)15 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)14 File (java.io.File)11 Map (java.util.Map)10 GetObjectTaggingRequest (com.amazonaws.services.s3.model.GetObjectTaggingRequest)9 GetObjectTaggingResult (com.amazonaws.services.s3.model.GetObjectTaggingResult)9 HashSet (java.util.HashSet)9 Utils (com.vmware.xenon.common.Utils)8 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)7 Reservation (com.amazonaws.services.ec2.model.Reservation)7 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)5 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)5 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)5 DeferredResult (com.vmware.xenon.common.DeferredResult)5