Search in sources :

Example 6 with CloudLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.

the class CloudFormationStackUtil method addLoadBalancerTargets.

public void addLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToAdd) {
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
    for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
        // Get a list of the new instances in the target groups
        Set<String> updatedInstanceIds = getInstanceIdsForGroups(resourcesToAdd, entry.getValue());
        // Find target group ARN
        AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
        String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
        // Use ARN to fetch a list of current targets
        DescribeTargetHealthResult targetHealthResult = amazonElbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(targetGroupArn));
        List<TargetDescription> targetDescriptions = targetHealthResult.getTargetHealthDescriptions().stream().map(TargetHealthDescription::getTarget).collect(Collectors.toList());
        Set<String> alreadyRegisteredInstanceIds = targetDescriptions.stream().map(TargetDescription::getId).collect(Collectors.toSet());
        // Remove any targets that have already been registered from the list being processed
        updatedInstanceIds.removeAll(alreadyRegisteredInstanceIds);
        // Register any new instances
        if (!updatedInstanceIds.isEmpty()) {
            List<TargetDescription> targetsToAdd = updatedInstanceIds.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
            RegisterTargetsResult registerTargetsResult = amazonElbClient.registerTargets(new RegisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToAdd));
        }
    }
}
Also used : RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TargetHealthDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetHealthDescription) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Splitter(com.google.common.base.Splitter) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) Collection(java.util.Collection) Output(com.amazonaws.services.cloudformation.model.Output) Set(java.util.Set) Retry(com.sequenceiq.cloudbreak.service.Retry) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Objects(java.util.Objects) List(java.util.List) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) Group(com.sequenceiq.cloudbreak.cloud.model.Group) PRIVATE_ID(com.sequenceiq.cloudbreak.cloud.model.CloudResource.PRIVATE_ID) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) INSTANCE_TYPE(com.sequenceiq.cloudbreak.cloud.model.CloudResource.INSTANCE_TYPE) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) Supplier(java.util.function.Supplier) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Service(org.springframework.stereotype.Service) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme) Retryable(org.springframework.retry.annotation.Retryable) DescribeStackResourceRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourceRequest) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DescribeFileSystemsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest) RegisterTargetsResult(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) SdkClientException(com.amazonaws.SdkClientException) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult) Collections(java.util.Collections) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Set(java.util.Set) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) RegisterTargetsResult(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsResult) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) Map(java.util.Map) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 7 with CloudLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method createCloudLoadBalancer.

private CloudLoadBalancer createCloudLoadBalancer(LoadBalancerType type, List<String> instanceGroupNetworkSubnetIds) {
    Group group = new Group(INSTANCE_NAME, GATEWAY, List.of(), null, null, null, null, null, null, 100, null, createGroupNetwork(instanceGroupNetworkSubnetIds), emptyMap());
    CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(type);
    cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(PORT, PORT), Set.of(group));
    return cloudLoadBalancer;
}
Also used : AwsTargetGroup(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 8 with CloudLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsOnlyEndpointGatewaySet.

@Test
public void testSelectLoadBalancerSubnetIdsOnlyEndpointGatewaySet() {
    AwsNetworkView awsNetworkView = createNetworkView(null, PUBLIC_ID_1);
    LoadBalancerType loadBalancerType = LoadBalancerType.PUBLIC;
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(loadBalancerType);
    Set<String> subnetIds = underTest.selectLoadBalancerSubnetIds(loadBalancerType, awsNetworkView, cloudLoadBalancer);
    assertEquals(Set.of(PUBLIC_ID_1), subnetIds);
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Test(org.junit.jupiter.api.Test)

Example 9 with CloudLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsPublicEndpointGatway.

@Test
public void testSelectLoadBalancerSubnetIdsPublicEndpointGatway() {
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, PUBLIC_ID_1);
    LoadBalancerType loadBalancerType = LoadBalancerType.PUBLIC;
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(loadBalancerType);
    Set<String> subnetIds = underTest.selectLoadBalancerSubnetIds(loadBalancerType, awsNetworkView, cloudLoadBalancer);
    assertEquals(Set.of(PUBLIC_ID_1), subnetIds);
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Test(org.junit.jupiter.api.Test)

Example 10 with CloudLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsMissingPublicSubnet.

@Test
public void testSelectLoadBalancerSubnetIdsMissingPublicSubnet() {
    AwsNetworkView awsNetworkView = createNetworkView(null, null);
    String expectedError = "Unable to configure load balancer: Could not identify subnets.";
    CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> underTest.selectLoadBalancerSubnetIds(LoadBalancerType.PUBLIC, awsNetworkView, new CloudLoadBalancer(LoadBalancerType.PUBLIC)));
    assertEquals(expectedError, exception.getMessage());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.jupiter.api.Test)

Aggregations

CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)47 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)27 Group (com.sequenceiq.cloudbreak.cloud.model.Group)24 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)21 ArrayList (java.util.ArrayList)21 Test (org.junit.jupiter.api.Test)20 List (java.util.List)15 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)13 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)13 HashMap (java.util.HashMap)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)12 Set (java.util.Set)12 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)10 Map (java.util.Map)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9