Search in sources :

Example 1 with AwsGroupView

use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsGroupView 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);
    }
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) IOException(java.io.IOException) Template(freemarker.template.Template) AwsGroupView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsGroupView)

Aggregations

AwsGroupView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsGroupView)1 AwsInstanceView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 FreeMarkerTemplateUtils.processTemplateIntoString (com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1