use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView 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.aws.view.AwsInstanceView in project cloudbreak by hortonworks.
the class EncryptedSnapshotPreparator method createSnapshotIfNeeded.
public Optional<String> createSnapshotIfNeeded(AuthenticatedContext ac, Group group) {
InstanceTemplate instanceTemplate = group.getReferenceInstanceConfiguration().getTemplate();
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AwsInstanceView awsInstanceView = new AwsInstanceView(instanceTemplate);
AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential());
AmazonEC2Client client = awsClient.createAccess(awsCredentialView, regionName);
Optional<String> snapshotId = checkThatSnapshotIsAvailable(awsInstanceView, client);
return snapshotId.isPresent() ? snapshotId : prepareSnapshotForEncryptionBecauseThatDoesNotExist(ac, awsInstanceView, client);
}
Aggregations