Search in sources :

Example 1 with AwsInstanceProfileView

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

the class AwsModelService method buildDefaultModelContext.

public ModelContext buildDefaultModelContext(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier) {
    Network network = stack.getNetwork();
    AwsNetworkView awsNetworkView = new AwsNetworkView(network);
    AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
    String regionName = ac.getCloudContext().getLocation().getRegion().value();
    AmazonEc2Client amazonEC2Client = awsClient.createEc2Client(credentialView, regionName);
    boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(awsNetworkView, amazonEC2Client);
    boolean existingVPC = awsNetworkView.isExistingVPC();
    boolean existingSubnet = awsNetworkView.isExistingSubnet();
    String cidr = network.getSubnet().getCidr();
    String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? awsNetworkService.findNonOverLappingCIDR(ac, stack) : cidr;
    AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
    ModelContext modelContext = new ModelContext().withAuthenticatedContext(ac).withStack(stack).withExistingVpc(existingVPC).withExistingIGW(awsNetworkView.isExistingIGW()).withExistingSubnetCidr(existingSubnet ? awsNetworkService.getExistingSubnetCidr(ac, stack) : null).withExistinVpcCidr(awsNetworkService.getVpcCidrs(ac, awsNetworkView)).withExistingSubnetIds(existingSubnet ? awsNetworkView.getSubnetList() : null).mapPublicIpOnLaunch(mapPublicIpOnLaunch).withEnableInstanceProfile(awsInstanceProfileView.isInstanceProfileAvailable()).withInstanceProfileAvailable(awsInstanceProfileView.isInstanceProfileAvailable()).withTemplate(stack.getTemplate()).withDefaultSubnet(subnet).withOutboundInternetTraffic(network.getOutboundInternetTraffic()).withVpcCidrs(network.getNetworkCidrs()).withPrefixListIds(awsNetworkService.getPrefixListIds(amazonEC2Client, regionName, network.getOutboundInternetTraffic()));
    AwsEfsFileSystem efsFileSystem = getAwsEfsFileSystem(stack);
    if (efsFileSystem != null) {
        modelContext.withEnableEfs(true);
        modelContext.withEfsFileSystem(efsFileSystem);
    } else {
        modelContext.withEnableEfs(false);
    }
    return modelContext;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AwsEfsFileSystem(com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceProfileView)

Example 2 with AwsInstanceProfileView

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

the class AwsStackRequestHelper method getStackParameters.

private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) {
    AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
    AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
    String keyPairName = awsClient.getKeyPairName(ac);
    if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) {
        keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication());
    }
    Collection<Parameter> parameters = new ArrayList<>();
    if (stack.getImage().getUserDataByType(InstanceGroupType.CORE) != null) {
        addParameterChunks(parameters, "CBUserData", stack.getImage().getUserDataByType(InstanceGroupType.CORE), CHUNK_COUNT);
    }
    addParameterChunks(parameters, "CBGateWayUserData", stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY), CHUNK_COUNT);
    parameters.addAll(asList(new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack))));
    if (awsInstanceProfileView.isInstanceProfileAvailable()) {
        parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile()));
    }
    if (ac.getCloudContext().getLocation().getAvailabilityZone() != null && ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) {
        parameters.add(new Parameter().withParameterKey("AvailabilitySet").withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value()));
    }
    if (awsNetworkView.isExistingVPC()) {
        parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVpc()));
        if (awsNetworkView.isExistingIGW()) {
            parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIgw()));
        }
        if (awsNetworkView.isExistingSubnet()) {
            parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet()));
        } else {
            parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr));
        }
    }
    return parameters;
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceProfileView)

Aggregations

AwsInstanceProfileView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceProfileView)2 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)2 Parameter (com.amazonaws.services.cloudformation.model.Parameter)1 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)1 AwsEfsFileSystem (com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem)1 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 ArrayList (java.util.ArrayList)1