Search in sources :

Example 6 with JsonUtil

use of com.sequenceiq.cloudbreak.common.json.JsonUtil in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestEbsEncryptionWithDefaultKey.

@Test
public void buildTestEbsEncryptionWithDefaultKey() {
    // GIVEN
    instance.getTemplate().putParameter(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true);
    instance.getTemplate().putParameter(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name());
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"Encrypted\"").contains("{ \"Ref\" : \"AMI\" }").contains("SecurityGroupIngress").doesNotContain("\"KmsKeyId\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Example 7 with JsonUtil

use of com.sequenceiq.cloudbreak.common.json.JsonUtil in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestEfsNullFields.

@Test
public void buildTestEfsNullFields() {
    // GIVEN
    AwsEfsFileSystem awsEfsFileSystem = setupEfsFileSystemNullFields();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withEnableEfs(true).withEfsFileSystem(awsEfsFileSystem);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("AWS::EFS::FileSystem").contains("\"Encrypted\" : \"true\"").contains("\"PerformanceMode\": \"generalPurpose\"").contains("\"ThroughputMode\": \"bursting\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Example 8 with JsonUtil

use of com.sequenceiq.cloudbreak.common.json.JsonUtil in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestWithMultipleLoadBalancers.

@Test
public void buildTestWithMultipleLoadBalancers() {
    // GIVEN
    List<AwsLoadBalancer> awsLoadBalancers = List.of(setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, true), setupLoadBalancer(AwsLoadBalancerScheme.INTERNET_FACING, 888, true));
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withLoadBalancers(awsLoadBalancers);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"LoadBalancerInternal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::LoadBalancer\"").contains("\"Scheme\" : \"internal\"").contains("\"TargetGroupPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::TargetGroup\"").contains("\"ListenerPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::Listener\"").contains("\"LoadBalancerExternal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::LoadBalancer\"").contains("\"Scheme\" : \"internet-facing\"").contains("\"TargetGroupPort888External\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::TargetGroup\"").contains("\"ListenerPort888External\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::Listener\"");
    assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-443\" },{ \"Id\" : \"instance2-443\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-443\" },{ \"Id\" : \"instance1-443\" }]}}");
    assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-888\" },{ \"Id\" : \"instance2-888\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-888\" },{ \"Id\" : \"instance1-888\" }]}}");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Example 9 with JsonUtil

use of com.sequenceiq.cloudbreak.common.json.JsonUtil in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestEfsSetFields.

@Test
public void buildTestEfsSetFields() {
    // GIVEN
    AwsEfsFileSystem awsEfsFileSystem = setupEfsFileSystemValidSet();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate).withEnableEfs(true).withEfsFileSystem(awsEfsFileSystem);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("AWS::EFS::FileSystem").contains("\"Encrypted\" : \"false\"").contains("\"PerformanceMode\": \"maxIO\"").contains("\"ThroughputMode\": \"provisioned\"");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Test(org.junit.jupiter.api.Test)

Aggregations

ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)9 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Test (org.junit.jupiter.api.Test)8 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)4 AwsEfsFileSystem (com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem)2