Search in sources :

Example 1 with AwsInstanceView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView in project cloudbreak by hortonworks.

the class AwsNativeModelBuilder method build.

public AwsNativeModel build(ModelContext context) {
    Collection<AwsGroupView> awsGroupViews = new ArrayList<>();
    Collection<AwsGroupView> awsGatewayGroupViews = new ArrayList<>();
    int subnetCounter = 0;
    boolean multigw = context.getStack().getGroups().stream().filter(g -> g.getType() == InstanceGroupType.GATEWAY).count() > 1;
    for (Group group : context.getStack().getGroups()) {
        AwsInstanceView awsInstanceView = new AwsInstanceView(group.getReferenceInstanceTemplate());
        String encryptedAMI = context.getEncryptedAMIByGroupName().get(group.getName());
        Map<String, Long> volumeCounts = awsInstanceView.getVolumes().stream().collect(Collectors.groupingBy(Volume::getType, Collectors.counting()));
        volumeCounts.putIfAbsent(AwsDiskType.Ephemeral.value(), group.getReferenceInstanceTemplate().getTemporaryStorageCount());
        AwsGroupView groupView = new AwsGroupView(group.getInstancesSize(), group.getType().name(), awsInstanceView.getFlavor(), group.getName(), awsInstanceView.isEncryptedVolumes(), group.getRootVolumeSize(), volumeCounts, group.getSecurity().getRules(), group.getSecurity().getCloudSecurityIds(), getSubnetIds(context.getExistingSubnetIds(), subnetCounter, group, multigw), awsInstanceView.isKmsCustom(), awsInstanceView.getKmsKey(), encryptedAMI, group.getSecurity().isUseNetworkCidrAsSourceForDefaultRules(), getInstanceProfile(group), awsInstanceView.getOnDemandPercentage(), awsInstanceView.getSpotMaxPrice(), awsInstanceView.getPlacementGroupStrategy().name());
        awsGroupViews.add(groupView);
        if (group.getType() == InstanceGroupType.GATEWAY) {
            awsGatewayGroupViews.add(groupView);
        }
        subnetCounter++;
    }
    AwsNativeModel awsNativeModel = new AwsNativeModel();
    awsNativeModel.setInstanceGroups(awsGroupViews);
    awsNativeModel.setGatewayGroups(awsGatewayGroupViews);
    awsNativeModel.setExistingVPC(context.isExistingVPC());
    awsNativeModel.setExistingIGW(context.isExistingIGW());
    awsNativeModel.setExistingSubnet(!isNullOrEmptyList(context.getExistingSubnetCidr()));
    awsNativeModel.setEnableInstanceProfile(context.isEnableInstanceProfile() || context.isInstanceProfileAvailable());
    awsNativeModel.setExistingRole(context.isInstanceProfileAvailable());
    awsNativeModel.setCbSubnet(isNullOrEmptyList(context.getExistingSubnetCidr()) ? Lists.newArrayList(context.getDefaultSubnet()) : context.getExistingSubnetCidr());
    awsNativeModel.setVpcSubnet(context.getExistingVpcCidr() == null ? Collections.emptyList() : context.getExistingVpcCidr());
    awsNativeModel.setDedicatedInstances(areDedicatedInstancesRequested(context.getStack()));
    awsNativeModel.setAvailabilitySetNeeded(context.getAc().getCloudContext().getLocation().getAvailabilityZone() != null && context.getAc().getCloudContext().getLocation().getAvailabilityZone().value() != null);
    awsNativeModel.setMapPublicIpOnLaunch(context.isMapPublicIpOnLaunch());
    awsNativeModel.setOutboundInternetTraffic(context.getOutboundInternetTraffic());
    awsNativeModel.setVpcCidrs(context.getVpcCidrs());
    awsNativeModel.setPrefixListIds(context.getPrefixListIds());
    awsNativeModel.setLoadBalancers(Optional.ofNullable(context.getLoadBalancers()).orElse(Collections.emptyList()));
    awsNativeModel.setEnableEfs(context.isEnableEfs());
    awsNativeModel.setEfsFileSystem(context.getEfsFileSystem());
    return awsNativeModel;
}
Also used : AwsGroupView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsGroupView) Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView)

Example 2 with AwsInstanceView

use of com.sequenceiq.cloudbreak.cloud.aws.common.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 subnetCounter = 0;
    boolean multigw = context.getStack().getGroups().stream().filter(g -> g.getType() == InstanceGroupType.GATEWAY).count() > 1;
    for (Group group : context.getStack().getGroups()) {
        AwsInstanceView awsInstanceView = new AwsInstanceView(group.getReferenceInstanceTemplate());
        String encryptedAMI = context.getEncryptedAMIByGroupName().get(group.getName());
        Map<String, Long> volumeCounts = awsInstanceView.getVolumes().stream().collect(Collectors.groupingBy(Volume::getType, Collectors.counting()));
        volumeCounts.putIfAbsent(AwsDiskType.Ephemeral.value(), group.getReferenceInstanceTemplate().getTemporaryStorageCount());
        AwsGroupView groupView = new AwsGroupView(group.getInstancesSize(), group.getType().name(), awsInstanceView.getFlavor(), group.getName(), awsInstanceView.isEncryptedVolumes(), group.getRootVolumeSize(), volumeCounts, group.getSecurity().getRules(), group.getSecurity().getCloudSecurityIds(), getSubnetIds(context.getExistingSubnetIds(), subnetCounter, group, multigw), awsInstanceView.isKmsCustom(), awsInstanceView.getKmsKey(), encryptedAMI, group.getSecurity().isUseNetworkCidrAsSourceForDefaultRules(), getInstanceProfile(group), awsInstanceView.getOnDemandPercentage(), awsInstanceView.getSpotMaxPrice(), awsInstanceView.getPlacementGroupStrategy().name());
        awsGroupViews.add(groupView);
        if (group.getType() == InstanceGroupType.GATEWAY) {
            awsGatewayGroupViews.add(groupView);
        }
        subnetCounter++;
    }
    model.put("instanceGroups", awsGroupViews);
    model.put("gatewayGroups", awsGatewayGroupViews);
    model.put("existingVPC", context.isExistingVPC());
    model.put("existingIGW", context.isExistingIGW());
    model.put("existingSubnet", !isNullOrEmptyList(context.getExistingSubnetCidr()));
    model.put("enableInstanceProfile", context.isEnableInstanceProfile() || context.isInstanceProfileAvailable());
    model.put("existingRole", context.isInstanceProfileAvailable());
    model.put("cbSubnet", (isNullOrEmptyList(context.getExistingSubnetCidr())) ? Lists.newArrayList(context.getDefaultSubnet()) : context.getExistingSubnetCidr());
    model.put("vpcSubnet", context.getExistingVpcCidr() == null ? Collections.emptyList() : context.getExistingVpcCidr());
    model.put("dedicatedInstances", areDedicatedInstancesRequested(context.getStack()));
    model.put("availabilitySetNeeded", context.getAc().getCloudContext().getLocation().getAvailabilityZone() != null && context.getAc().getCloudContext().getLocation().getAvailabilityZone().value() != null);
    model.put("mapPublicIpOnLaunch", context.isMapPublicIpOnLaunch());
    model.put("outboundInternetTraffic", context.getOutboundInternetTraffic());
    model.put("vpcCidrs", context.getVpcCidrs());
    model.put("prefixListIds", context.getPrefixListIds());
    model.put("loadBalancers", Optional.ofNullable(context.getLoadBalancers()).orElse(Collections.emptyList()));
    model.put("enableEfs", context.isEnableEfs());
    model.put("efsFileSystem", context.getEfsFileSystem());
    try {
        String template = freeMarkerTemplateUtils.processTemplateIntoString(new Template("aws-template", context.getTemplate(), 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.common.view.AwsInstanceView) IOException(java.io.IOException) Template(freemarker.template.Template) AwsGroupView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsGroupView)

Example 3 with AwsInstanceView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView in project cloudbreak by hortonworks.

the class AwsNativeInstanceResourceBuilder method blocks.

Collection<BlockDeviceMapping> blocks(Group group, CloudStack cloudStack, AuthenticatedContext ac) {
    AwsInstanceView awsInstanceView = new AwsInstanceView(group.getReferenceInstanceTemplate());
    List<BlockDeviceMapping> blocks = new ArrayList<>();
    blocks.add(volumeBuilderUtil.getRootVolume(awsInstanceView, group, cloudStack, ac));
    List<BlockDeviceMapping> ephemeralBockDeviceMappings = volumeBuilderUtil.getEphemeral(awsInstanceView);
    if (CollectionUtils.isNotEmpty(ephemeralBockDeviceMappings)) {
        blocks.addAll(ephemeralBockDeviceMappings);
    }
    return blocks;
}
Also used : ArrayList(java.util.ArrayList) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping)

Aggregations

AwsInstanceView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView)3 ArrayList (java.util.ArrayList)3 AwsGroupView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsGroupView)2 Group (com.sequenceiq.cloudbreak.cloud.model.Group)2 BlockDeviceMapping (com.amazonaws.services.ec2.model.BlockDeviceMapping)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1