Search in sources :

Example 41 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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 42 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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 43 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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 44 with CloudLoadBalancerMetadata

use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata 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)

Example 45 with CloudLoadBalancerMetadata

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

the class AwsNativeMetadataCollector method collectLoadBalancer.

@Override
public List<CloudLoadBalancerMetadata> collectLoadBalancer(AuthenticatedContext ac, List<LoadBalancerType> lbTypes, List<CloudResource> resources) {
    List<CloudLoadBalancerMetadata> result = new ArrayList<>();
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AwsCredentialView awsCredential = new AwsCredentialView(ac.getCloudCredential());
    LOGGER.debug("Collect AWS load balancer metadata, for cluster {}", ac.getCloudContext().getName());
    Set<CloudResource> loadBalancers = resources.stream().filter(resource -> ResourceType.ELASTIC_LOAD_BALANCER.equals(resource.getType())).collect(Collectors.toSet());
    Set<String> loadBalancerArns = loadBalancers.stream().map(CloudResource::getReference).collect(Collectors.toSet());
    AmazonElasticLoadBalancingClient loadBalancingClient = awsClient.createElasticLoadBalancingClient(awsCredential, region);
    LOGGER.info("Collect AWS load balancer metadata, in region '{}' with ARNs: '{}'", region, String.join(", ", loadBalancerArns));
    for (String loadBalancerArn : loadBalancerArns) {
        Optional<CloudLoadBalancerMetadata> collectedLoadBalancer = collectLoadBalancerMetadata(loadBalancingClient, loadBalancerArn, resources);
        collectedLoadBalancer.ifPresent(result::add);
    }
    return result;
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) LoggerFactory(org.slf4j.LoggerFactory) AwsLifeCycleMapper(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsLifeCycleMapper) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) INSTANCE_NOT_FOUND_ERROR_CODE(com.sequenceiq.cloudbreak.cloud.aws.common.AwsInstanceConnector.INSTANCE_NOT_FOUND_ERROR_CODE) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) Instance(com.amazonaws.services.ec2.model.Instance) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) LinkedHashSet(java.util.LinkedHashSet) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Set(java.util.Set) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) MetadataCollector(com.sequenceiq.cloudbreak.cloud.MetadataCollector) Collectors(java.util.stream.Collectors) List(java.util.List) AwsPlatformResources(com.sequenceiq.cloudbreak.cloud.aws.common.AwsPlatformResources) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Optional(java.util.Optional) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) LoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.LoadBalancerTypeConverter) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)

Aggregations

CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)45 ArrayList (java.util.ArrayList)22 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)18 Test (org.junit.jupiter.api.Test)17 Test (org.junit.Test)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 List (java.util.List)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)8 Optional (java.util.Optional)8 LoadBalancer (com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer)7 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)7 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)7 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)7 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ForwardingRule (com.google.api.services.compute.model.ForwardingRule)6