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