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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations