Search in sources :

Example 1 with AwsInstanceView

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);
    }
}
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)

Example 2 with AwsInstanceView

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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

AwsInstanceView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceView)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 AwsGroupView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsGroupView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)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