use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsResourceConnector method getTlsInfo.
@Override
public TlsInfo getTlsInfo(AuthenticatedContext authenticatedContext, CloudStack cloudStack) {
Network network = cloudStack.getNetwork();
AwsNetworkView networkView = new AwsNetworkView(network);
boolean sameVPC = deployingToSameVPC(networkView, networkView.isExistingVPC());
return new TlsInfo(sameVPC);
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
resumeAutoScaling(ac, stack);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
List<Group> scaledGroups = getScaledGroups(stack);
for (Group group : scaledGroups) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, cloudFormationClient, group.getName());
amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(asGroupName).withMaxSize(group.getInstancesSize()).withDesiredCapacity(group.getInstancesSize()));
LOGGER.info("Updated Auto Scaling group's desiredCapacity: [stack: '{}', to: '{}']", ac.getCloudContext().getId(), resources.size());
}
scheduleStatusChecks(stack, ac, cloudFormationClient);
suspendAutoScaling(ac, stack);
boolean mapPublicIpOnLaunch = isMapPublicOnLaunch(new AwsNetworkView(stack.getNetwork()), amazonEC2Client);
List<Group> gateways = getGatewayGroups(scaledGroups);
if (mapPublicIpOnLaunch && !gateways.isEmpty()) {
String cFStackName = getCloudFormationStackResource(resources).getName();
Map<String, String> eipAllocationIds = getElasticIpAllocationIds(cFStackName, cloudFormationClient);
for (Group gateway : gateways) {
List<String> eips = getEipsForGatewayGroup(eipAllocationIds, gateway);
List<String> freeEips = getFreeIps(eips, amazonEC2Client);
List<String> instanceIds = getInstancesForGroup(ac, amazonASClient, cloudFormationClient, gateway);
List<String> newInstances = instanceIds.stream().filter(iid -> gateway.getInstances().stream().noneMatch(inst -> iid.equals(inst.getInstanceId()))).collect(Collectors.toList());
associateElasticIpsToInstances(amazonEC2Client, freeEips, newInstances);
}
}
return singletonList(new CloudResourceStatus(getCloudFormationStackResource(resources), ResourceStatus.UPDATED));
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsResourceConnector method getExistingSubnetCidr.
private List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest().withSubnetIds(awsNetworkView.getSubnetList());
List<Subnet> subnets = ec2Client.describeSubnets(subnetsRequest).getSubnets();
if (subnets.isEmpty()) {
throw new CloudConnectorException("The specified subnet does not exist (maybe it's in a different region).");
}
List<String> cidrs = Lists.newArrayList();
for (Subnet subnet : subnets) {
cidrs.add(subnet.getCidrBlock());
}
return cidrs;
}
use of com.sequenceiq.cloudbreak.cloud.aws.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);
AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential());
AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
if (awsClient.roleBasedCredential(awsCredentialView) && awsInstanceProfileView.isCreateInstanceProfile()) {
validateInstanceProfileCreation(awsCredentialView);
}
if (awsNetworkView.isExistingVPC()) {
try {
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, region);
validateExistingIGW(awsNetworkView, amazonEC2Client);
validateExistingSubnet(awsNetworkView, amazonEC2Client);
} catch (AmazonServiceException e) {
throw new CloudConnectorException(e.getErrorMessage());
} catch (AmazonClientException e) {
throw new CloudConnectorException(e.getMessage());
}
}
validateExistingKeyPair(stack.getInstanceAuthentication(), credentialView, region);
LOGGER.debug("setup has been executed");
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView in project cloudbreak by hortonworks.
the class AwsResourceConnector 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<>(asList(new Parameter().withParameterKey("CBUserData").withParameterValue(stack.getImage().getUserDataByType(InstanceGroupType.CORE)), new Parameter().withParameterKey("CBGateWayUserData").withParameterValue(stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY)), new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("StackOwner").withParameterValue(ac.getCloudContext().getOwner()), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack))));
if (awsInstanceProfileView.isUseExistingInstanceProfile() && awsInstanceProfileView.isEnableInstanceProfileStrategy()) {
parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile()));
}
if (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