Search in sources :

Example 6 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class AwsMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    LOGGER.debug("Collect AWS load balancer metadata, for cluster {}", ac.getCloudContext().getName());
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = new ArrayList<>();
    for (LoadBalancerType type : loadBalancerTypes) {
        AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(type);
        String loadBalancerName = AwsLoadBalancer.getLoadBalancerName(scheme);
        LOGGER.debug("Attempting to collect metadata for load balancer {}, type {}", loadBalancerName, type);
        try {
            LoadBalancer loadBalancer = cloudFormationStackUtil.getLoadBalancerByLogicalId(ac, loadBalancerName);
            LOGGER.debug("Parsing all listener and target group information for load balancer {}", loadBalancerName);
            Map<String, Object> parameters = awsLoadBalancerMetadataCollector.getParameters(ac, loadBalancer, scheme);
            CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withCloudDns(loadBalancer.getDNSName()).withHostedZoneId(loadBalancer.getCanonicalHostedZoneId()).withName(loadBalancerName).withParameters(parameters).build();
            cloudLoadBalancerMetadata.add(loadBalancerMetadata);
            LOGGER.debug("Saved metadata for load balancer {}: DNS {}, zone id {}", loadBalancerName, loadBalancer.getDNSName(), loadBalancer.getCanonicalHostedZoneId());
        } catch (RuntimeException e) {
            LOGGER.debug("Unable to find metadata for load balancer " + loadBalancerName, e);
        }
    }
    return cloudLoadBalancerMetadata;
}
Also used : ArrayList(java.util.ArrayList) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 7 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType 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 8 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType 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 9 with LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsPrivate.

@Test
public void testSelectLoadBalancerSubnetIdsPrivate() {
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
    LoadBalancerType loadBalancerType = LoadBalancerType.PRIVATE;
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(loadBalancerType);
    Set<String> subnetIds = underTest.selectLoadBalancerSubnetIds(loadBalancerType, awsNetworkView, cloudLoadBalancer);
    assertEquals(Set.of(PRIVATE_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 LoadBalancerType

use of com.sequenceiq.common.api.type.LoadBalancerType in project cloudbreak by hortonworks.

the class AwsNativeMetadataCollectorTest method collectLoadBalancerMetadataWhenWhenRuntimeExceptionOccurs.

@Test
void collectLoadBalancerMetadataWhenWhenRuntimeExceptionOccurs() {
    List<LoadBalancerType> loadBalancerTypes = List.of();
    CloudResource cloudResource = getCloudResource("secondCrn", "secondInstanceName", null, ELASTIC_LOAD_BALANCER);
    List<CloudResource> cloudResources = List.of(cloudResource);
    when(awsClient.createElasticLoadBalancingClient(any(), any())).thenReturn(loadBalancingClient);
    RuntimeException runtimeException = new RuntimeException("Something really bad happened...");
    when(loadBalancingClient.describeLoadBalancers(any())).thenThrow(runtimeException);
    CloudConnectorException cloudConnectorException = assertThrows(CloudConnectorException.class, () -> underTest.collectLoadBalancer(authenticatedContext, loadBalancerTypes, cloudResources));
    assertThat(cloudConnectorException).hasMessage("Metadata collection of load balancers failed");
    assertThat(cloudConnectorException).hasCauseReference(runtimeException);
    verify(loadBalancingClient, times(1)).describeLoadBalancers(any());
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Test(org.junit.jupiter.api.Test)

Aggregations

LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)36 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)21 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)18 StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)12 Test (org.junit.jupiter.api.Test)12 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)11 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)11 Network (com.sequenceiq.cloudbreak.cloud.model.Network)11 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)9 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 Logger (org.slf4j.Logger)5 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4