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