Search in sources :

Example 6 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView 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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) Filter(com.amazonaws.services.ec2.model.Filter) Vpc(com.amazonaws.services.ec2.model.Vpc) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Subnet(com.amazonaws.services.ec2.model.Subnet) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest)

Example 7 with AwsCredentialView

use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView 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");
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonClientException(com.amazonaws.AmazonClientException) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)

Example 8 with AwsCredentialView

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

the class AwsLaunchConfigurationImageUpdateService method updateImage.

public void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource) {
    AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
    String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
    AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
    AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);
    Map<AutoScalingGroup, String> scalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource);
    List<LaunchConfiguration> oldLaunchConfigurations = launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroups.keySet());
    for (LaunchConfiguration oldLaunchConfiguration : oldLaunchConfigurations) {
        changeImageInAutoscalingGroup(authenticatedContext, stack, autoScalingClient, scalingGroups, oldLaunchConfiguration);
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) LaunchConfiguration(com.amazonaws.services.autoscaling.model.LaunchConfiguration) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)

Example 9 with AwsCredentialView

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

the class AwsLaunchTemplateUpdateService method updateFields.

public void updateFields(AuthenticatedContext authenticatedContext, String stackName, Map<LaunchTemplateField, String> updatableFields, boolean dryRun) {
    AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
    String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
    AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
    AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);
    AmazonEc2Client ec2Client = awsClient.createEc2Client(credentialView, regionName);
    Map<AutoScalingGroup, String> autoScalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, stackName);
    autoScalingGroups = filterGroupsForDryRun(autoScalingGroups, dryRun);
    LOGGER.debug("Modifying the {} fields for the [{}] autoscaling groups' launchtemplates [dryrun: {}]", updatableFields, autoScalingGroups.values(), dryRun);
    for (Map.Entry<AutoScalingGroup, String> asgEntry : autoScalingGroups.entrySet()) {
        AutoScalingGroup autoScalingGroup = asgEntry.getKey();
        LOGGER.debug("Creating new launchtemplate version for [{}] autoscale group...", autoScalingGroup.getAutoScalingGroupName());
        LaunchTemplateSpecification launchTemplateSpecification = getLaunchTemplateSpecification(autoScalingGroup);
        CreateLaunchTemplateVersionResult createLaunchTemplateVersionResult = getCreateLaunchTemplateVersionRequest(ec2Client, updatableFields, launchTemplateSpecification);
        modifyLaunchTemplate(ec2Client, launchTemplateSpecification, createLaunchTemplateVersionResult, !dryRun);
        if (dryRun) {
            LOGGER.debug("Autoscale group update will be skipped because of dryrun, which just test the permissions for modifiying the launch template.");
        } else {
            updateAutoScalingGroup(updatableFields, autoScalingClient, autoScalingGroup, launchTemplateSpecification, createLaunchTemplateVersionResult);
        }
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) LaunchTemplateSpecification(com.amazonaws.services.autoscaling.model.LaunchTemplateSpecification) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) CreateLaunchTemplateVersionResult(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Map(java.util.Map)

Example 10 with AwsCredentialView

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

the class AwsLoadBalancerMetadataCollector method getParameters.

public Map<String, Object> getParameters(AuthenticatedContext ac, LoadBalancer loadBalancer, AwsLoadBalancerScheme scheme) {
    String region = ac.getCloudContext().getLocation().getRegion().value();
    String cFStackName = cloudFormationStackUtil.getCfStackName(ac);
    AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
    AmazonCloudFormationClient cfRetryClient = awsClient.createCloudFormationClient(credentialView, region);
    ListStackResourcesResult result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
    Map<String, Object> parameters = parseTargetGroupCloudParams(scheme, result.getStackResourceSummaries());
    parameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, loadBalancer.getLoadBalancerArn());
    return parameters;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)

Aggregations

AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)94 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)32 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)32 List (java.util.List)25 AmazonServiceException (com.amazonaws.AmazonServiceException)22 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)21 Logger (org.slf4j.Logger)21 Inject (javax.inject.Inject)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)19 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)18 Group (com.sequenceiq.cloudbreak.cloud.model.Group)18 Set (java.util.Set)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)17 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Map (java.util.Map)16 LoggerFactory (org.slf4j.LoggerFactory)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 Service (org.springframework.stereotype.Service)15 AmazonAutoScalingClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient)14