Search in sources :

Example 6 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndNoSslCertificateIdentifier.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndNoSslCertificateIdentifier(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withUseSslEnforcement(true).withSslCertificateIdentifierDefined(false).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).doesNotContain("\"PortParameter\": {");
    assertThat(result).contains("\"DBParameterGroupNameParameter\": {");
    assertThat(result).contains("\"DBParameterGroupFamilyParameter\": {");
    assertThat(result).doesNotContain("\"SslCertificateIdentifierParameter\": {");
    assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
    assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"VPCIdParameter\": {");
    assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
    assertThat(result).doesNotContain("\"FromPort\"");
    assertThat(result).doesNotContain("\"ToPort\"");
    assertThat(result).doesNotContain("\"CidrIp\" :");
    assertThat(result).contains("\"DBParameterGroup\": {");
    assertThat(result).contains("\"Parameters\": { \"rds.force_ssl\": \"1\" },");
    assertThat(result).contains("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
    assertThat(result).doesNotContain("\"CACertificateIdentifier\": { \"Ref\": \"SslCertificateIdentifierParameter\" },");
    assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
    assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
    assertThat(result).contains("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndHavingPort.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndHavingPort(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withHasPort(true).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).contains("\"PortParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupFamilyParameter\": {");
    assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
    assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"VPCIdParameter\": {");
    assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
    assertThat(result).doesNotContain("\"FromPort\"");
    assertThat(result).doesNotContain("\"ToPort\"");
    assertThat(result).doesNotContain("\"CidrIp\" :");
    assertThat(result).doesNotContain("\"DBParameterGroup\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
    assertThat(result).contains("\"Port\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
    assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
    assertThat(result).doesNotContain("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class AwsRdsLaunchServiceTest method launchTestUseSslEnforcementInternal.

private void launchTestUseSslEnforcementInternal(boolean useSslEnforcement, boolean sslCertificateIdentifierDefined) {
    when(cfStackUtil.getOutputs(STACK_NAME_CF, cfRetryClient)).thenReturn(useSslEnforcement ? CF_OUTPUTS_WITH_DB_PARAMETER_GROUP : CF_OUTPUTS_WITHOUT_DB_PARAMETER_GROUP);
    List<CloudResourceStatus> cloudResourceStatuses = underTest.launch(authenticatedContext, createDatabaseStack(useSslEnforcement, sslCertificateIdentifierDefined), resourceNotifier);
    assertThat(cloudResourceStatuses).isNotNull();
    assertThat(cloudResourceStatuses).hasSize(useSslEnforcement ? 6 : 5);
    cloudResourceStatuses.forEach(status -> assertThat(status).isNotNull());
    cloudResourceStatuses.forEach(status -> assertThat(status.getCloudResource()).isNotNull());
    checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_HOSTNAME, OUT_HOSTNAME);
    checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_PORT, OUT_PORT);
    checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_INSTANCE, OUT_DB_INSTANCE);
    checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_DB_SUBNET_GROUP, OUT_DB_SUBNET_GROUP);
    if (useSslEnforcement) {
        checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_DB_PARAMETER_GROUP, OUT_DB_PARAMETER_GROUP);
    } else {
        checkOutputResourceIsAbsent(cloudResourceStatuses, ResourceType.RDS_DB_PARAMETER_GROUP, OUT_DB_PARAMETER_GROUP);
    }
    checkOutputResourceExists(cloudResourceStatuses, ResourceType.CLOUDFORMATION_STACK, STACK_NAME_CF);
    verify(cloudFormationTemplateBuilder).build(rdsModelContextCaptor.capture());
    RDSModelContext rdsModelContext = rdsModelContextCaptor.getValue();
    assertThat(rdsModelContext).isNotNull();
    Boolean useSslEnforcementResult = (Boolean) ReflectionTestUtils.getField(rdsModelContext, "useSslEnforcement");
    assertThat(useSslEnforcementResult).isNotNull();
    assertThat(useSslEnforcementResult.booleanValue()).isEqualTo(useSslEnforcement);
    Boolean sslCertificateIdentifierDefinedResult = (Boolean) ReflectionTestUtils.getField(rdsModelContext, "sslCertificateIdentifierDefined");
    assertThat(sslCertificateIdentifierDefinedResult).isNotNull();
    assertThat(sslCertificateIdentifierDefinedResult.booleanValue()).isEqualTo(sslCertificateIdentifierDefined);
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Example 9 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndNoPortAndNoSslEnforcementAndNoSslCertificateIdentifier.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndNoPortAndNoSslEnforcementAndNoSslCertificateIdentifier(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withUseSslEnforcement(false).withSslCertificateIdentifierDefined(false).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).doesNotContain("\"PortParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupFamilyParameter\": {");
    assertThat(result).doesNotContain("\"SslCertificateIdentifierParameter\": {");
    assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
    assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"VPCIdParameter\": {");
    assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
    assertThat(result).doesNotContain("\"FromPort\"");
    assertThat(result).doesNotContain("\"ToPort\"");
    assertThat(result).doesNotContain("\"CidrIp\" :");
    assertThat(result).doesNotContain("\"DBParameterGroup\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
    assertThat(result).doesNotContain("\"CACertificateIdentifier\": { \"Ref\": \"SslCertificateIdentifierParameter\" },");
    assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
    assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
    assertThat(result).doesNotContain("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenKmsKeyIdAbsent.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenKmsKeyIdAbsent(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withIsKmsCustom(false).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).contains("\"StorageEncrypted\": true");
    assertThat(result).doesNotContain("\"KmsKeyId\" : \"dummyKeyArn\"");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RDSModelContext (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 CREATE_FAILED (com.amazonaws.services.cloudformation.model.ResourceStatus.CREATE_FAILED)1 Waiter (com.amazonaws.waiters.Waiter)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AwsCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient)1 AwsStackRequestHelper (com.sequenceiq.cloudbreak.cloud.aws.AwsStackRequestHelper)1 CloudFormationStackUtil (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil)1 CloudFormationTemplateBuilder (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder)1 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)1 StackCancellationCheck (com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck)1 WaiterRunner.run (com.sequenceiq.cloudbreak.cloud.aws.scheduler.WaiterRunner.run)1 AwsCloudFormationErrorMessageProvider (com.sequenceiq.cloudbreak.cloud.aws.util.AwsCloudFormationErrorMessageProvider)1 AwsRdsInstanceView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsRdsInstanceView)1