Search in sources :

Example 1 with JsonUtil

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

the class CloudFormationTemplateBuilderTest method buildTestHealthCheckPortDifferentFromTrafficPort.

public void buildTestHealthCheckPortDifferentFromTrafficPort() {
    // GIVEN
    AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, 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(List.of(awsLoadBalancer));
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).contains("\"Port\" : 443").contains("\"HealthCheckPort\" : \"8443\"");
}
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)

Example 2 with JsonUtil

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

the class CloudFormationTemplateBuilderTest method buildTestWithSingleLoadBalancerAfterUpdate.

@Test
public void buildTestWithSingleLoadBalancerAfterUpdate() {
    // GIVEN
    AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, 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(List.of(awsLoadBalancer));
    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\"");
    assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-443\" },{ \"Id\" : \"instance2-443\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-443\" },{ \"Id\" : \"instance1-443\" }]}}");
}
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 3 with JsonUtil

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

the class CloudFormationTemplateBuilderTest method buildTestEbsEncryptionWithCustomKey.

@Test
public void buildTestEbsEncryptionWithCustomKey() {
    // GIVEN
    instance.getTemplate().putParameter(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true);
    instance.getTemplate().putParameter(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name());
    instance.getTemplate().putParameter(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, "customEncryptionKeyArn");
    // 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").contains("\"KmsKeyId\" : \"customEncryptionKeyArn\"");
}
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 4 with JsonUtil

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

the class CloudFormationTemplateBuilderTest method buildTestWithSingleLoadBalancerBeforeUpdate.

@Test
public void buildTestWithSingleLoadBalancerBeforeUpdate() {
    // GIVEN
    AwsLoadBalancer awsLoadBalancer = setupLoadBalancer(AwsLoadBalancerScheme.INTERNAL, 443, false);
    // 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(List.of(awsLoadBalancer));
    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\"").doesNotContain("\"ListenerPort443Internal\" : {\"Type\" : \"AWS::ElasticLoadBalancingV2::Listener\"");
    assert templateString.contains("\"Targets\" : [{ \"Id\" : \"instance1-443\" },{ \"Id\" : \"instance2-443\" }]}}") || templateString.contains("\"Targets\" : [{ \"Id\" : \"instance2-443\" },{ \"Id\" : \"instance1-443\" }]}}");
}
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 5 with JsonUtil

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

the class CloudFormationTemplateBuilderTest method buildTestInstanceGroupsAndRootVolumeSize.

@Test
public void buildTestInstanceGroupsAndRootVolumeSize() {
    // 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("AmbariNodesmaster").matches(template -> template.contains("AmbariNodeLaunchConfigmaster") || template.contains("ClusterManagerNodeLaunchTemplatemaster")).contains("ClusterNodeSecurityGroupmaster").contains("SecurityGroupIngress").contains("AmbariNodesgateway").matches(template -> template.contains("AmbariNodeLaunchConfiggateway") || template.contains("ClusterManagerNodeLaunchTemplategateway")).contains("ClusterNodeSecurityGroupgateway").doesNotContain("testtagkey").doesNotContain("testtagkey").contains(Integer.toString(ROOT_VOLUME_SIZE));
}
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)

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