Search in sources :

Example 6 with AmazonElasticLoadBalancingClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.

the class AwsNativeResourceConnector method upscale.

@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, AdjustmentTypeWithThreshold adjustmentTypeWithThreshold) throws QuotaExceededException {
    List<CloudResourceStatus> upscale = super.upscale(auth, stack, resources, adjustmentTypeWithThreshold);
    LOGGER.info("Launching elastic load balancers");
    CloudCredential cloudCredential = auth.getCloudCredential();
    String region = auth.getCloudContext().getLocation().getRegion().value();
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
    loadBalancerLaunchService.launchLoadBalancerResources(auth, stack, persistenceNotifier, elasticLoadBalancingClient, true);
    return upscale;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Example 7 with AmazonElasticLoadBalancingClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.

the class AwsNativeResourceConnector method launchLoadBalancers.

@Override
public List<CloudResourceStatus> launchLoadBalancers(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier) throws Exception {
    LOGGER.info("Launching elastic load balancers");
    CloudCredential cloudCredential = authenticatedContext.getCloudCredential();
    String region = authenticatedContext.getCloudContext().getLocation().getRegion().value();
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
    return loadBalancerLaunchService.launchLoadBalancerResources(authenticatedContext, stack, persistenceNotifier, elasticLoadBalancingClient, true);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential)

Example 8 with AmazonElasticLoadBalancingClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.

the class AwsClient method createAuthenticatedContext.

public AuthenticatedContext createAuthenticatedContext(CloudContext cloudContext, CloudCredential cloudCredential) {
    AuthenticatedContext authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
    try {
        AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(authenticatedContext);
        String region = authenticatedContextView.getRegion();
        AwsCredentialView awsCredentialView = authenticatedContextView.getAwsCredentialView();
        AmazonEc2Client amazonEC2Client = null;
        if (region != null) {
            amazonEC2Client = createEc2Client(awsCredentialView, region);
            AmazonElasticLoadBalancingClient loadBalancingClient = createElasticLoadBalancingClient(awsCredentialView, region);
            authenticatedContext.putParameter(AmazonElasticLoadBalancingClient.class, loadBalancingClient);
        } else {
            amazonEC2Client = createEc2Client(awsCredentialView);
        }
        authenticatedContext.putParameter(AmazonEc2Client.class, amazonEC2Client);
    } catch (AmazonServiceException e) {
        throw new CredentialVerificationException(e.getErrorMessage(), e);
    }
    return authenticatedContext;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonServiceException(com.amazonaws.AmazonServiceException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) CredentialVerificationException(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)

Example 9 with AmazonElasticLoadBalancingClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.

the class AwsContextBuilder method contextInit.

@Override
public AwsContext contextInit(CloudContext context, AuthenticatedContext auth, Network network, List<CloudResource> resources, boolean build) {
    Location location = context.getLocation();
    AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(auth);
    AmazonEc2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client();
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = authenticatedContextView.getElasticLoadBalancingClient();
    return new AwsContext(context.getName(), amazonEC2Client, location, PARALLEL_RESOURCE_REQUEST, build, elasticLoadBalancingClient);
}
Also used : AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AuthenticatedContextView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 10 with AmazonElasticLoadBalancingClient

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient in project cloudbreak by hortonworks.

the class LoadBalancerService method removeLoadBalancerTargets.

public void removeLoadBalancerTargets(AuthenticatedContext ac, List<String> targetGroupArns, List<CloudResource> resourcesToRemove) {
    if (targetGroupArns.isEmpty()) {
        LOGGER.info("Cannot find target group for the stack, skip the removing of the targets");
        return;
    }
    for (String targetGroupArn : targetGroupArns) {
        String region = ac.getCloudContext().getLocation().getRegion().value();
        AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
        LOGGER.debug("Get a list of the instance ids to remove");
        Set<String> instancesToRemove = getInstanceIdsForGroups(resourcesToRemove);
        LOGGER.debug("Deregister any instances that no longer exist");
        if (!instancesToRemove.isEmpty()) {
            try {
                List<TargetDescription> targetsToRemove = instancesToRemove.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
                amazonElbClient.deregisterTargets(new DeregisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToRemove));
                LOGGER.debug("Targets deregistered: {}", targetsToRemove);
            } catch (InvalidTargetException ignored) {
                LOGGER.debug("no-op - we tried to remove a target that wasn't in the target group, which is fine");
            }
        }
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) Logger(org.slf4j.Logger) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DeregisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) InvalidTargetException(com.amazonaws.services.elasticloadbalancingv2.model.InvalidTargetException) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) InvalidTargetException(com.amazonaws.services.elasticloadbalancingv2.model.InvalidTargetException) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DeregisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest)

Aggregations

AmazonElasticLoadBalancingClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient)16 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest)7 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)7 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)7 List (java.util.List)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 Inject (javax.inject.Inject)7 Logger (org.slf4j.Logger)7 TargetDescription (com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)6 ResourceType (com.sequenceiq.common.api.type.ResourceType)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Service (org.springframework.stereotype.Service)6 RegisterTargetsRequest (com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest)5 AwsLoadBalancerScheme (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)5