Search in sources :

Example 1 with AwsNetworkView

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);
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) Network(com.sequenceiq.cloudbreak.cloud.model.Network) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo)

Example 2 with AwsNetworkView

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));
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) ROLLBACK_IN_PROGRESS(com.amazonaws.services.cloudformation.model.StackStatus.ROLLBACK_IN_PROGRESS) SuspendProcessesRequest(com.amazonaws.services.autoscaling.model.SuspendProcessesRequest) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ROLLBACK_FAILED(com.amazonaws.services.cloudformation.model.StackStatus.ROLLBACK_FAILED) AdjustmentType(com.sequenceiq.cloudbreak.api.model.AdjustmentType) SubnetInfo(org.apache.commons.net.util.SubnetUtils.SubnetInfo) AmazonServiceException(com.amazonaws.AmazonServiceException) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Retry(com.sequenceiq.cloudbreak.service.Retry) SyncPollingScheduler(com.sequenceiq.cloudbreak.cloud.scheduler.SyncPollingScheduler) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DELETE_FAILED(com.amazonaws.services.cloudformation.model.StackStatus.DELETE_FAILED) AwsPollTaskFactory(com.sequenceiq.cloudbreak.cloud.aws.task.AwsPollTaskFactory) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) StackStatus(com.amazonaws.services.cloudformation.model.StackStatus) DescribeKeyPairsRequest(com.amazonaws.services.ec2.model.DescribeKeyPairsRequest) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Lists(com.google.common.collect.Lists) UpdateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Service(org.springframework.stereotype.Service) Image(com.amazonaws.services.ec2.model.Image) Filter(com.amazonaws.services.ec2.model.Filter) Network(com.sequenceiq.cloudbreak.cloud.model.Network) DeleteStackRequest(com.amazonaws.services.cloudformation.model.DeleteStackRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DELETE_COMPLETE(com.amazonaws.services.cloudformation.model.StackStatus.DELETE_COMPLETE) CREATE_FAILED(com.amazonaws.services.cloudformation.model.StackStatus.CREATE_FAILED) DetachInstancesRequest(com.amazonaws.services.autoscaling.model.DetachInstancesRequest) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ROLLBACK_COMPLETE(com.amazonaws.services.cloudformation.model.StackStatus.ROLLBACK_COMPLETE) IOException(java.io.IOException) DescribeAddressesRequest(com.amazonaws.services.ec2.model.DescribeAddressesRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) ImportKeyPairRequest(com.amazonaws.services.ec2.model.ImportKeyPairRequest) Configuration(freemarker.template.Configuration) InetAddresses(com.google.common.net.InetAddresses) SubnetUtils(org.apache.commons.net.util.SubnetUtils) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) OnFailure(com.amazonaws.services.cloudformation.model.OnFailure) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CREATE_COMPLETE(com.amazonaws.services.cloudformation.model.StackStatus.CREATE_COMPLETE) Collection(java.util.Collection) Output(com.amazonaws.services.cloudformation.model.Output) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) Collectors(java.util.stream.Collectors) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) ModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.ModelContext) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Entry(java.util.Map.Entry) Optional(java.util.Optional) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) HashMap(java.util.HashMap) Inject(javax.inject.Inject) DeleteKeyPairRequest(com.amazonaws.services.ec2.model.DeleteKeyPairRequest) DisassociateAddressRequest(com.amazonaws.services.ec2.model.DisassociateAddressRequest) Charset(java.nio.charset.Charset) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ResumeProcessesRequest(com.amazonaws.services.autoscaling.model.ResumeProcessesRequest) PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) Subnet(com.amazonaws.services.ec2.model.Subnet) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) Logger(org.slf4j.Logger) ResourceType(com.sequenceiq.cloudbreak.common.type.ResourceType) Address(com.amazonaws.services.ec2.model.Address) Vpc(com.amazonaws.services.ec2.model.Vpc) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AssociateAddressRequest(com.amazonaws.services.ec2.model.AssociateAddressRequest) DescribeAddressesResult(com.amazonaws.services.ec2.model.DescribeAddressesResult) Collections(java.util.Collections) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) UpdateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest) AmazonCloudFormationClient(com.amazonaws.services.cloudformation.AmazonCloudFormationClient)

Example 3 with AwsNetworkView

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;
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 4 with AwsNetworkView

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");
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)

Example 5 with AwsNetworkView

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;
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)

Aggregations

AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)5 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)5 AwsInstanceProfileView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)4 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)3 Subnet (com.amazonaws.services.ec2.model.Subnet)3 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)2 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)2 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)2 Parameter (com.amazonaws.services.cloudformation.model.Parameter)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)2 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 TlsInfo (com.sequenceiq.cloudbreak.cloud.model.TlsInfo)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)1 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1