Search in sources :

Example 31 with LoadBalancerType

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

the class AwsLaunchServiceLoadBalancerTest method createSummaries.

private List<StackResourceSummary> createSummaries(Set<LoadBalancerType> types, boolean createLbAndTg, boolean creatListeners) {
    List<StackResourceSummary> summaries = new ArrayList<>();
    for (LoadBalancerType type : types) {
        AwsLoadBalancerScheme scheme = LoadBalancerType.PRIVATE.equals(type) ? AwsLoadBalancerScheme.INTERNAL : AwsLoadBalancerScheme.INTERNET_FACING;
        if (createLbAndTg) {
            StackResourceSummary tgSummary = new StackResourceSummary();
            tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(PORT, scheme));
            tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN);
            tgSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(tgSummary);
            StackResourceSummary lbSummary = new StackResourceSummary();
            lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
            lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN);
            lbSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(lbSummary);
        }
        if (creatListeners) {
            StackResourceSummary lSummary = new StackResourceSummary();
            lSummary.setLogicalResourceId(AwsListener.getListenerName(PORT, scheme));
            lSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(lSummary);
        }
    }
    return summaries;
}
Also used : ArrayList(java.util.ArrayList) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 32 with LoadBalancerType

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

the class AwsNativeMetadataCollectorApiIntegrationTest method collectLoadBalancerMetadataWhenTheSpecifiedArnsDoNotExist.

@Test
void collectLoadBalancerMetadataWhenTheSpecifiedArnsDoNotExist() {
    List<LoadBalancerType> loadbalancerTypes = List.of();
    CloudResource aLoadBalancer = new CloudResource.Builder().name("aLoadBalancer").reference("arn:aws:elasticloadbalancing:eu-central-1:152813717728:loadbalancer/net/notexisting-LoadB-1MYWS0111IT2K/2e65a6e6b1a801df").type(ResourceType.ELASTIC_LOAD_BALANCER).build();
    CloudResource secondLoadBalancer = new CloudResource.Builder().name("secondLoadBalancer").reference("arn:aws:elasticloadbalancing:eu-central-1:152813717728:loadbalancer/net/notexisting2-LoadB-1MYWS0111IT2K/2e65a6e6b1a801bf").type(ResourceType.ELASTIC_LOAD_BALANCER).build();
    List<CloudResource> resources = List.of(aLoadBalancer, secondLoadBalancer);
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = underTest.collectLoadBalancer(authenticatedContext, loadbalancerTypes, resources);
    assertTrue(cloudLoadBalancerMetadata.isEmpty());
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 33 with LoadBalancerType

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

the class AwsNativeMetadataCollectorTest method collectLoadBalancerMetadataWhenOneOfSpecifiedArnsDoNotExist.

@Test
void collectLoadBalancerMetadataWhenOneOfSpecifiedArnsDoNotExist() {
    List<LoadBalancerType> loadBalancerTypes = List.of();
    CloudResource cloudResource = getCloudResource("aCrn", "lbname", null, ELASTIC_LOAD_BALANCER);
    CloudResource secondCloudResource = getCloudResource("secondCrn", "lbnamesecond", null, ELASTIC_LOAD_BALANCER);
    List<CloudResource> cloudResources = List.of(cloudResource, secondCloudResource);
    when(awsClient.createElasticLoadBalancingClient(any(), any())).thenReturn(loadBalancingClient);
    LoadBalancerNotFoundException loadBalancerNotFoundException = new LoadBalancerNotFoundException("One or more elastic lb not found");
    loadBalancerNotFoundException.setErrorCode(LOAD_BALANCER_NOT_FOUND_ERROR_CODE);
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setScheme(LoadBalancerSchemeEnum.Internal);
    when(loadBalancingClient.describeLoadBalancers(any())).thenReturn(new DescribeLoadBalancersResult().withLoadBalancers(loadBalancer)).thenThrow(loadBalancerNotFoundException);
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = underTest.collectLoadBalancer(authenticatedContext, loadBalancerTypes, cloudResources);
    verify(loadBalancingClient, times(2)).describeLoadBalancers(any());
    assertFalse(cloudLoadBalancerMetadata.isEmpty());
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) LoadBalancerNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerNotFoundException) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 34 with LoadBalancerType

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

the class AwsNativeMetadataCollectorTest method collectLoadBalancerMetadataWhenTheSpecifiedArnsDoNotExist.

@Test
void collectLoadBalancerMetadataWhenTheSpecifiedArnsDoNotExist() {
    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);
    LoadBalancerNotFoundException loadBalancerNotFoundException = new LoadBalancerNotFoundException("One or more elastic lb not found");
    loadBalancerNotFoundException.setErrorCode(LOAD_BALANCER_NOT_FOUND_ERROR_CODE);
    when(loadBalancingClient.describeLoadBalancers(any())).thenThrow(loadBalancerNotFoundException);
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = underTest.collectLoadBalancer(authenticatedContext, loadBalancerTypes, cloudResources);
    verify(loadBalancingClient, times(1)).describeLoadBalancers(any());
    Assertions.assertTrue(cloudLoadBalancerMetadata.isEmpty());
}
Also used : LoadBalancerNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerNotFoundException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 35 with LoadBalancerType

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

the class AwsNativeMetadataCollectorTest method collectLoadBalancerMetadataWhenTheSpecifiedArnsExists.

@Test
void collectLoadBalancerMetadataWhenTheSpecifiedArnsExists() {
    List<LoadBalancerType> loadBalancerTypes = List.of();
    CloudResource cloudResource = getCloudResource("aCrn", "lbname", null, ELASTIC_LOAD_BALANCER);
    CloudResource secondCloudResource = getCloudResource("secondCrn", "lbnamesecond", null, ELASTIC_LOAD_BALANCER);
    List<CloudResource> cloudResources = List.of(cloudResource, secondCloudResource);
    when(awsClient.createElasticLoadBalancingClient(any(), any())).thenReturn(loadBalancingClient);
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setScheme(LoadBalancerSchemeEnum.Internal);
    when(loadBalancingClient.describeLoadBalancers(any())).thenReturn(new DescribeLoadBalancersResult().withLoadBalancers(loadBalancer));
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = underTest.collectLoadBalancer(authenticatedContext, loadBalancerTypes, cloudResources);
    verify(loadBalancingClient, times(2)).describeLoadBalancers(any());
    assertFalse(cloudLoadBalancerMetadata.isEmpty());
    assertEquals(cloudResources.size(), cloudLoadBalancerMetadata.size());
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) 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