use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24VpcEmptySubnet.
@Test
public void testFindNonOverLappingCIDRWit24VpcEmptySubnet() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/24");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Collections.emptyList());
thrown.expect(CloudConnectorException.class);
thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilder method build.
public String build(ModelContext context) {
Map<String, Object> model = new HashMap<>();
Collection<AwsGroupView> awsGroupViews = new ArrayList<>();
Collection<AwsGroupView> awsGatewayGroupViews = new ArrayList<>();
int i = 0;
boolean multigw = context.stack.getGroups().stream().filter(g -> g.getType() == InstanceGroupType.GATEWAY).count() > 1;
for (Group group : context.stack.getGroups()) {
AwsInstanceView awsInstanceView = new AwsInstanceView(group.getReferenceInstanceConfiguration().getTemplate());
String snapshotId = context.snapshotId.get(group.getName());
AwsGroupView groupView = new AwsGroupView(group.getInstancesSize(), group.getType().name(), awsInstanceView.getFlavor(), group.getName(), awsInstanceView.getVolumes().size(), awsInstanceView.isEncryptedVolumes(), awsInstanceView.getVolumeSize(), awsInstanceView.getVolumeType(), awsInstanceView.getSpotPrice(), group.getSecurity().getRules(), group.getSecurity().getCloudSecurityId(), getSubnetIds(context.existingSubnetIds, i, group, multigw), awsInstanceView.isKmsEnabled(), awsInstanceView.getKmsKey(), snapshotId);
awsGroupViews.add(groupView);
if (group.getType() == InstanceGroupType.GATEWAY) {
awsGatewayGroupViews.add(groupView);
}
i++;
}
model.put("instanceGroups", awsGroupViews);
model.put("gatewayGroups", awsGatewayGroupViews);
model.put("existingVPC", context.existingVPC);
model.put("existingIGW", context.existingIGW);
model.put("existingSubnet", !isNullOrEmptyList(context.existingSubnetCidr));
model.put("enableInstanceProfile", context.enableInstanceProfile || context.instanceProfileAvailable);
model.put("existingRole", context.instanceProfileAvailable);
model.put("cbSubnet", (isNullOrEmptyList(context.existingSubnetCidr)) ? Lists.newArrayList(context.defaultSubnet) : context.existingSubnetCidr);
model.put("dedicatedInstances", areDedicatedInstancesRequested(context.stack));
model.put("availabilitySetNeeded", context.ac.getCloudContext().getLocation().getAvailabilityZone().value() != null);
model.put("mapPublicIpOnLaunch", context.mapPublicIpOnLaunch);
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
try {
String template = processTemplateIntoString(new Template("aws-template", context.template, freemarkerConfiguration), model);
return template.replaceAll("\\t|\\n| [\\s]+", "");
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process CloudFormation freemarker template", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildWithInstanceGroupTypeGatewayShouldNotContainsCoreCustomData.
@Test
public void buildWithInstanceGroupTypeGatewayShouldNotContainsCoreCustomData() throws Exception {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, not(containsString("\"customData\": \"" + base64EncodedUserData(CORE_CUSTOM_DATA) + '"')));
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildNoPublicIpButFirewall.
@Test
public void buildNoPublicIpButFirewall() {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
when(azureUtils.isPrivateIp(any())).then(invocation -> true);
when(azureUtils.isNoSecurityGroups(any())).then(invocation -> false);
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, not(containsString("publicIPAddress")));
assertThat(templateString, containsString("networkSecurityGroups"));
}
use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.
the class AzureTemplateBuilderTest method buildWithInstanceGroupTypeCore.
@Test
public void buildWithInstanceGroupTypeCore() throws Exception {
// GIVEN
Network network = new Network(new Subnet("testSubnet"));
Map<String, String> parameters = new HashMap<>();
parameters.put("persistentStorage", "persistentStorageTest");
parameters.put("attachedStorageOption", "attachedStorageOptionTest");
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
// WHEN
when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
// THEN
gson.fromJson(templateString, Map.class);
assertThat(templateString, containsString("\"customData\": \"" + base64EncodedUserData(CORE_CUSTOM_DATA) + '"'));
}
Aggregations