Search in sources :

Example 11 with LoadBalancerType

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

the class AwsNativeMetadataCollectorTest method collectLoadBalancerMetadataWhenWhenNotExpectedAmazonServiceExceptionOccurs.

@Test
void collectLoadBalancerMetadataWhenWhenNotExpectedAmazonServiceExceptionOccurs() {
    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");
    when(loadBalancingClient.describeLoadBalancers(any())).thenThrow(loadBalancerNotFoundException);
    CloudConnectorException cloudConnectorException = assertThrows(CloudConnectorException.class, () -> underTest.collectLoadBalancer(authenticatedContext, loadBalancerTypes, cloudResources));
    assertThat(cloudConnectorException).hasMessage("Metadata collection of load balancers failed");
    assertThat(cloudConnectorException).hasCauseReference(loadBalancerNotFoundException);
    verify(loadBalancingClient, times(1)).describeLoadBalancers(any());
}
Also used : LoadBalancerNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancerNotFoundException) 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)

Example 12 with LoadBalancerType

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

the class AwsNativeMetadataCollector method describeLoadBalancer.

private Optional<CloudLoadBalancerMetadata> describeLoadBalancer(String loadBalancerArn, AmazonElasticLoadBalancingClient loadBalancingClient, List<CloudResource> resources) {
    DescribeLoadBalancersRequest describeLoadBalancersRequest = new DescribeLoadBalancersRequest().withLoadBalancerArns(loadBalancerArn);
    DescribeLoadBalancersResult describeLoadBalancersResult = loadBalancingClient.describeLoadBalancers(describeLoadBalancersRequest);
    return describeLoadBalancersResult.getLoadBalancers().stream().findFirst().map(loadBalancer -> {
        LoadBalancerType type = loadBalancerTypeConverter.convert(loadBalancer.getScheme());
        Map<String, Object> parameters = awsNativeLbMetadataCollector.getParameters(loadBalancerArn, resources);
        CloudLoadBalancerMetadata loadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withType(type).withCloudDns(loadBalancer.getDNSName()).withHostedZoneId(loadBalancer.getCanonicalHostedZoneId()).withName(loadBalancer.getLoadBalancerName()).withParameters(parameters).build();
        LOGGER.info("Saved metadata for load balancer {}: DNS {}, zone ID {}", loadBalancer.getLoadBalancerName(), loadBalancer.getDNSName(), loadBalancer.getCanonicalHostedZoneId());
        return loadBalancerMetadata;
    });
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Example 13 with LoadBalancerType

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

the class YarnMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> loadBalancerTypes, List<CloudResource> resources) {
    List<CloudLoadBalancerMetadata> loadBalancerMetadata = Lists.newArrayList();
    if (loadBalancerTypes.size() == 0) {
        return loadBalancerMetadata;
    }
    YarnClient yarnClient = yarnClientUtil.createYarnClient(ac);
    String loadBalancerApplicationName = applicationNameUtil.createLoadBalancerName(ac);
    Iterable<Container> loadBalancerContainers = yarnLoadBalancerLaunchService.getContainers(loadBalancerApplicationName, yarnClient);
    Iterator<Container> containerIterator = loadBalancerContainers.iterator();
    for (LoadBalancerType loadBalancerType : loadBalancerTypes) {
        Container container = containerIterator.next();
        CloudLoadBalancerMetadata metadata = new CloudLoadBalancerMetadata.Builder().withType(loadBalancerType).withName(applicationNameUtil.createLoadBalancerComponentName(loadBalancerApplicationName, loadBalancerType)).withIp(container.getIp()).build();
        loadBalancerMetadata.add(metadata);
    }
    return loadBalancerMetadata;
}
Also used : Container(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Container) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType)

Example 14 with LoadBalancerType

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithPublicLoadBalancerNoEndpointGateway.

@Test
public void testUpdateCloudformationWithPublicLoadBalancerNoEndpointGateway() {
    List<CloudResource> instances = createInstances();
    AwsNetworkView awsNetworkView = createNetworkView(PUBLIC_ID_1, null);
    Network network = createNetwork(PUBLIC_ID_1, null);
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PUBLIC);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
    setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PUBLIC));
    when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
    when(ac.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location);
    when(location.getAvailabilityZone()).thenReturn(availabilityZone("az1"));
    underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null);
    verify(cfClient, times(2)).updateStack(any());
    verify(result, times(4)).getStackResourceSummaries();
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with LoadBalancerType

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationSuccess.

@Test
public void testUpdateCloudformationSuccess() {
    List<CloudResource> instances = createInstances();
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
    Network network = createNetwork(PRIVATE_ID_1, null);
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
    setupMocksForUpdate(awsNetworkView, network, instances, types);
    when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
    when(ac.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location);
    when(location.getAvailabilityZone()).thenReturn(availabilityZone("az1"));
    List<CloudResourceStatus> statuses = underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null);
    assertEquals(1, statuses.size());
    assertEquals(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED, statuses.get(0).getStatus());
    assertEquals(CREATED, statuses.get(0).getCloudResource().getStatus());
    assertEquals(ELASTIC_LOAD_BALANCER, statuses.get(0).getCloudResource().getType());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.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