use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestPlacementGroupWithPartitionPlacementGroup.
@Test
public void buildTestPlacementGroupWithPartitionPlacementGroup() {
// GIVEN
instance.getTemplate().putParameter(PLACEMENT_GROUP_STRATEGY, AwsPlacementGroupStrategy.PARTITION.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(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
Assertions.assertThat(templateString).contains("\"PlacementGroupmaster\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"partition\"}}").contains("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupmaster\" } }").contains("\"PlacementGroupgateway\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"partition\"}}").contains("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupgateway\" } }");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestInstanceGroupsWithSpotInstances.
@Test
public void buildTestInstanceGroupsWithSpotInstances() {
// GIVEN
List<Group> groups = new ArrayList<>();
Security security = getDefaultCloudStackSecurity();
groups.add(createDefaultGroup("master", InstanceGroupType.CORE, ROOT_VOLUME_SIZE, security, Optional.empty()));
InstanceTemplate spotInstanceTemplate = createDefaultInstanceTemplate();
spotInstanceTemplate.putParameter(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, 60);
CloudInstance spotInstance = new CloudInstance("SOME_ID", spotInstanceTemplate, instanceAuthentication, "subnet-1", "az1");
groups.add(new Group("compute", InstanceGroupType.CORE, singletonList(spotInstance), security, spotInstance, instanceAuthentication, instanceAuthentication.getLoginUserName(), "publickey", ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap()));
groups.add(createDefaultGroup("gateway", InstanceGroupType.GATEWAY, ROOT_VOLUME_SIZE, security, Optional.empty()));
CloudStack cloudStack = createDefaultCloudStack(groups, getDefaultCloudStackParameters(), getDefaultCloudStackTags());
// 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(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
assertThat(templateString, stringContainsInOrder("OnDemandPercentageAboveBaseCapacity", "40"));
assertThat(templateString, containsString("SecurityGroupIngress"));
assertThat(templateString, not(containsString("SpotMaxPrice")));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestPlacementGroupWithMixedPlacementGroup.
@Test
public void buildTestPlacementGroupWithMixedPlacementGroup() {
// GIVEN
InstanceTemplate instanceTemplateMaster = createDefaultInstanceTemplate();
InstanceTemplate instanceTemplateWorker = createDefaultInstanceTemplate();
InstanceTemplate instanceTemplateGateway = createDefaultInstanceTemplate();
InstanceTemplate instanceTemplateCustom = createDefaultInstanceTemplate();
instanceTemplateMaster.putParameter(PLACEMENT_GROUP_STRATEGY, AwsPlacementGroupStrategy.SPREAD.name());
instanceTemplateWorker.putParameter(PLACEMENT_GROUP_STRATEGY, AwsPlacementGroupStrategy.PARTITION.name());
instanceTemplateGateway.putParameter(PLACEMENT_GROUP_STRATEGY, AwsPlacementGroupStrategy.CLUSTER.name());
instanceTemplateCustom.putParameter(PLACEMENT_GROUP_STRATEGY, AwsPlacementGroupStrategy.NONE.name());
List<Group> groups = List.of(createDefaultGroupWithInstanceTemplate("master", instanceTemplateMaster, InstanceGroupType.CORE), createDefaultGroupWithInstanceTemplate("worker", instanceTemplateWorker, InstanceGroupType.CORE), createDefaultGroupWithInstanceTemplate("gateway", instanceTemplateGateway, InstanceGroupType.GATEWAY), createDefaultGroupWithInstanceTemplate("custom", instanceTemplateCustom, InstanceGroupType.CORE));
CloudStack cloudStack = createDefaultCloudStack(groups, getDefaultCloudStackParameters(), getDefaultCloudStackTags());
// 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(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
Assertions.assertThat(templateString).contains("\"PlacementGroupmaster\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"spread\"}}").contains("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupmaster\" } }").contains("\"PlacementGroupworker\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"partition\"}}").contains("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupworker\" } }").contains("\"PlacementGroupgateway\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"cluster\"}}").contains("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupgateway\" } }").doesNotContain("\"PlacementGroupcustom\" : {\"Type\" : \"AWS::EC2::PlacementGroup\",\"Properties\" : {\"Strategy\" : \"cluster\"}}").doesNotContain("\"Placement\" : { \"GroupName\" : { \"Ref\" : \"PlacementGroupcustom\" } }");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext 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));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestWithVPCAndIGWAndInstanceProfileWithoutPublicIpOnLaunchAndRole.
@Test
public void buildTestWithVPCAndIGWAndInstanceProfileWithoutPublicIpOnLaunchAndRole() {
CloudStack cloudStack = initCloudStackWithInstanceProfile();
// WHEN
modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(false).withEnableInstanceProfile(true).withInstanceProfileAvailable(false).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
String templateString = cloudFormationTemplateBuilder.build(modelContext);
// THEN
Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
assertThat(templateString, containsString("InstanceProfile"));
assertThat(templateString, containsString("VPCId"));
assertThat(templateString, not(containsString("SubnetCIDR")));
assertThat(templateString, containsString("SubnetId"));
assertThat(templateString, not(containsString("SubnetConfig")));
assertThat(templateString, not(containsString("\"AttachGateway\"")));
assertThat(templateString, not(containsString("\"InternetGateway\"")));
assertThat(templateString, containsString("SecurityGroupIngress"));
assertThat(templateString, containsString("AvailabilitySet"));
assertThat(templateString, not(containsString("EIP")));
}
Aggregations