use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonService method convertLoadBalancer.
@VisibleForTesting
AwsLoadBalancer convertLoadBalancer(CloudLoadBalancer cloudLoadBalancer, Map<String, List<String>> instanceIdsByGroupName, AwsNetworkView awsNetworkView, List<AwsLoadBalancer> awsLoadBalancers) {
// Check and see if we already have a load balancer whose scheme matches this one.
AwsLoadBalancer currentLoadBalancer = null;
LoadBalancerType cloudLbType = cloudLoadBalancer.getType();
Set<String> subnetIds = selectLoadBalancerSubnetIds(cloudLbType, awsNetworkView, cloudLoadBalancer);
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(cloudLbType);
currentLoadBalancer = awsLoadBalancers.stream().filter(lb -> lb.getScheme() == scheme).findFirst().orElse(new AwsLoadBalancer(scheme));
currentLoadBalancer.addSubnets(subnetIds);
setupLoadBalancer(cloudLoadBalancer, instanceIdsByGroupName, currentLoadBalancer);
return currentLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsNetworkService method findNonOverLappingCIDR.
public String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc());
Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0);
String vpcCidr = vpc.getCidrBlock();
LOGGER.debug("Subnet cidr is empty, find a non-overlapping subnet for VPC cidr: {}", vpcCidr);
DescribeSubnetsRequest request = new DescribeSubnetsRequest().withFilters(new Filter("vpc-id", singletonList(awsNetworkView.getExistingVpc())));
List<Subnet> awsSubnets = ec2Client.describeSubnets(request).getSubnets();
List<String> subnetCidrs = awsSubnets.stream().map(Subnet::getCidrBlock).collect(Collectors.toList());
LOGGER.debug("The selected VPCs: {}, has the following subnets: {}", vpc.getVpcId(), String.join(",", subnetCidrs));
return calculateSubnet(ac.getCloudContext().getName(), vpc, subnetCidrs);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsSetup method prerequisites.
@Override
public void prerequisites(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier persistenceNotifier) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String region = ac.getCloudContext().getLocation().getRegion().value();
verifySpotInstances(stack);
if (awsNetworkView.isExistingVPC()) {
try {
AmazonEc2Client amazonEC2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
validateExistingIGW(awsNetworkView, amazonEC2Client);
validateExistingSubnet(awsNetworkView, amazonEC2Client);
} catch (AmazonServiceException e) {
throw new CloudConnectorException(e.getErrorMessage());
} catch (AmazonClientException e) {
throw new CloudConnectorException(e.getMessage());
}
}
validateRegionAndZone(ac.getCloudCredential(), ac.getCloudContext().getLocation());
validateExistingKeyPair(stack.getInstanceAuthentication(), credentialView, region, ac);
LOGGER.debug("setup has been executed");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsStackRequestHelper method getStackParameters.
@VisibleForTesting
Collection<Parameter> getStackParameters(AuthenticatedContext ac, DatabaseStack stack, boolean deleteProtection) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
DatabaseServer databaseServer = stack.getDatabaseServer();
AwsRdsInstanceView awsRdsInstanceView = new AwsRdsInstanceView(databaseServer);
AwsRdsDbSubnetGroupView awsRdsDbSubnetGroupView = new AwsRdsDbSubnetGroupView(databaseServer);
AwsRdsVpcSecurityGroupView awsRdsVpcSecurityGroupView = new AwsRdsVpcSecurityGroupView(databaseServer);
AwsRdsDbParameterGroupView awsRdsDbParameterGroupView = new AwsRdsDbParameterGroupView(databaseServer);
List<Parameter> parameters = new ArrayList<>(asList(new Parameter().withParameterKey("DBInstanceClassParameter").withParameterValue(awsRdsInstanceView.getDBInstanceClass()), new Parameter().withParameterKey("DBInstanceIdentifierParameter").withParameterValue(awsRdsInstanceView.getDBInstanceIdentifier()), new Parameter().withParameterKey("DBSubnetGroupNameParameter").withParameterValue(awsRdsDbSubnetGroupView.getDBSubnetGroupName()), new Parameter().withParameterKey("DBSubnetGroupSubnetIdsParameter").withParameterValue(String.join(",", awsNetworkView.getSubnetList())), new Parameter().withParameterKey("EngineParameter").withParameterValue(awsRdsInstanceView.getEngine()), new Parameter().withParameterKey("MasterUsernameParameter").withParameterValue(awsRdsInstanceView.getMasterUsername()), new Parameter().withParameterKey("MasterUserPasswordParameter").withParameterValue(awsRdsInstanceView.getMasterUserPassword()), new Parameter().withParameterKey("DeletionProtectionParameter").withParameterValue(deleteProtection ? "true" : "false")));
addParameterIfNotNull(parameters, "AllocatedStorageParameter", awsRdsInstanceView.getAllocatedStorage());
addParameterIfNotNull(parameters, "BackupRetentionPeriodParameter", awsRdsInstanceView.getBackupRetentionPeriod());
addParameterIfNotNull(parameters, "EngineVersionParameter", awsRdsInstanceView.getEngineVersion());
addParameterIfNotNull(parameters, "MultiAZParameter", awsRdsInstanceView.getMultiAZ());
addParameterIfNotNull(parameters, "StorageTypeParameter", awsRdsInstanceView.getStorageType());
addParameterIfNotNull(parameters, "PortParameter", databaseServer.getPort());
boolean useSslEnforcement = databaseServer.isUseSslEnforcement();
addParameterIfNotNull(parameters, "DBParameterGroupNameParameter", useSslEnforcement ? awsRdsDbParameterGroupView.getDBParameterGroupName() : null);
addParameterIfNotNull(parameters, "DBParameterGroupFamilyParameter", useSslEnforcement ? awsRdsDbParameterGroupView.getDBParameterGroupFamily() : null);
addParameterIfNotNull(parameters, "SslCertificateIdentifierParameter", useSslEnforcement && awsRdsInstanceView.isSslCertificateIdentifierDefined() ? awsRdsInstanceView.getSslCertificateIdentifier() : null);
if (awsRdsInstanceView.getVPCSecurityGroups().isEmpty()) {
// VPC-id and VPC cidr should be filled in
parameters.addAll(asList(new Parameter().withParameterKey("VPCIdParameter").withParameterValue(String.valueOf(awsNetworkView.getExistingVpc())), new Parameter().withParameterKey("DBSecurityGroupNameParameter").withParameterValue(awsRdsVpcSecurityGroupView.getDBSecurityGroupName())));
} else {
parameters.add(new Parameter().withParameterKey("VPCSecurityGroupsParameter").withParameterValue(String.join(",", awsRdsInstanceView.getVPCSecurityGroups())));
}
return parameters;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsLaunchService method launch.
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier, AdjustmentTypeWithThreshold adjustmentTypeWithThreshold) throws Exception {
LOGGER.info("Launch AWS cluster with adjustment and threshold: {}", adjustmentTypeWithThreshold);
createKeyPair(ac, stack);
String cFStackName = cfStackUtil.getCfStackName(ac);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonEc2Client amazonEC2Client = awsClient.createEc2Client(credentialView, regionName);
Network network = stack.getNetwork();
AwsNetworkView awsNetworkView = new AwsNetworkView(network);
boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(awsNetworkView, amazonEC2Client);
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
ModelContext modelContext = null;
try {
cfClient.describeStacks(describeStacksRequest);
LOGGER.debug("Stack already exists: {}", cFStackName);
} catch (AmazonServiceException ignored) {
boolean existingVPC = awsNetworkView.isExistingVPC();
boolean existingSubnet = awsNetworkView.isExistingSubnet();
CloudResource cloudFormationStack = new Builder().type(ResourceType.CLOUDFORMATION_STACK).availabilityZone(ac.getCloudContext().getLocation().getAvailabilityZone().value()).name(cFStackName).build();
resourceNotifier.notifyAllocation(cloudFormationStack, ac.getCloudContext());
String cidr = network.getSubnet().getCidr();
String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? awsNetworkService.findNonOverLappingCIDR(ac, stack) : cidr;
modelContext = awsModelService.buildDefaultModelContext(ac, stack, resourceNotifier);
String cfTemplate = cloudFormationTemplateBuilder.build(modelContext);
LOGGER.debug("CloudFormationTemplate: {}", cfTemplate);
cfClient.createStack(awsStackRequestHelper.createCreateStackRequest(ac, stack, cFStackName, subnet, cfTemplate));
}
LOGGER.debug("CloudFormation stack creation request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId());
Waiter<DescribeStacksRequest> creationWaiter = cfClient.waiters().stackCreateComplete();
StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
run(creationWaiter, describeStacksRequest, stackCancellationCheck, String.format("CloudFormation stack %s creation failed.", cFStackName), () -> awsCloudFormationErrorMessageProvider.getErrorReason(ac, cFStackName, ResourceStatus.CREATE_FAILED));
List<CloudResource> networkResources = saveGeneratedSubnet(ac, stack, cFStackName, cfClient, resourceNotifier);
suspendAutoscalingGoupsWhenNewInstancesAreReady(ac, stack);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(credentialView, regionName);
List<CloudResource> instances = cfStackUtil.getInstanceCloudResources(ac, cfClient, amazonASClient, stack.getGroups());
if (mapPublicIpOnLaunch) {
associatePublicIpsToGatewayInstances(stack, cFStackName, cfClient, amazonEC2Client, instances);
}
awsComputeResourceService.buildComputeResourcesForLaunch(ac, stack, adjustmentTypeWithThreshold, instances, networkResources);
awsTaggingService.tagRootVolumes(ac, amazonEC2Client, instances, stack.getTags());
awsCloudWatchService.addCloudWatchAlarmsForSystemFailures(instances, regionName, credentialView);
return awsResourceConnector.check(ac, instances);
}
Aggregations