Search in sources :

Example 1 with OpenStackGroupView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.OpenStackGroupView in project cloudbreak by hortonworks.

the class HeatTemplateBuilder method build.

public String build(ModelContext modelContext) {
    try {
        List<NovaInstanceView> novaInstances = new OpenStackGroupView(modelContext.stackName, modelContext.groups, modelContext.tags).getFlatNovaView();
        Map<String, Object> model = new HashMap<>();
        model.put("cb_stack_name", openStackUtil.adjustStackNameLength(modelContext.stackName));
        model.put("agents", novaInstances);
        model.put("core_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.CORE)));
        model.put("gateway_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.GATEWAY)));
        model.put("groups", modelContext.groups);
        model.put("existingNetwork", modelContext.existingNetwork);
        model.put("existingSubnet", modelContext.existingSubnet);
        model.put("network", modelContext.neutronNetworkView);
        model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
        AvailabilityZone az = modelContext.location.getAvailabilityZone();
        if (az != null && az.value() != null) {
            model.put("availability_zone", az.value());
        }
        Template template = new Template(openStackHeatTemplatePath, modelContext.templateString, freemarkerConfiguration);
        String generatedTemplate = processTemplateIntoString(template, model);
        LOGGER.debug("Generated Heat template: {}", generatedTemplate);
        return generatedTemplate;
    } catch (IOException | TemplateException e) {
        throw new CloudConnectorException("Failed to process the OpenStack HeatTemplateBuilder", e);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) IOException(java.io.IOException) NovaInstanceView(com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView) Template(freemarker.template.Template) OpenStackGroupView(com.sequenceiq.cloudbreak.cloud.openstack.view.OpenStackGroupView)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 NovaInstanceView (com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView)1 OpenStackGroupView (com.sequenceiq.cloudbreak.cloud.openstack.view.OpenStackGroupView)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 HashMap (java.util.HashMap)1