use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerMetadataCollectorTest method testCollectInternalLoadBalancer.
@Test
public void testCollectInternalLoadBalancer() {
int numPorts = 1;
AuthenticatedContext ac = authenticatedContext();
LoadBalancer loadBalancer = createLoadBalancer();
List<StackResourceSummary> summaries = createSummaries(numPorts, true);
ListStackResourcesResult result = new ListStackResourcesResult();
result.setStackResourceSummaries(summaries);
Map<String, Object> expectedParameters = Map.of(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN, AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, TARGET_GROUP_ARN + "0Internal");
when(awsClient.createCloudFormationClient(any(), any())).thenReturn(cfRetryClient);
when(cloudFormationStackUtil.getCfStackName(ac)).thenReturn("stackName");
when(awsStackRequestHelper.createListStackResourcesRequest(eq("stackName"))).thenReturn(new ListStackResourcesRequest());
when(cfRetryClient.listStackResources(any())).thenReturn(result);
Map<String, Object> parameters = underTest.getParameters(ac, loadBalancer, AwsLoadBalancerScheme.INTERNAL);
assertEquals(expectedParameters, parameters);
}
use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchServiceTest method testLaunchLoadBalancerResourcesWhenListenerAlreadyExistsAndLoadBalancerTargetsCouldNotBeRegistered.
@Test
void testLaunchLoadBalancerResourcesWhenListenerAlreadyExistsAndLoadBalancerTargetsCouldNotBeRegistered() {
CloudStack stack = getCloudStack();
when(loadBalancerCommonService.getAwsLoadBalancers(any(), any(), any())).thenReturn(List.of(getAwsLoadBalancer()));
when(resourceNameService.resourceName(eq(ResourceType.ELASTIC_LOAD_BALANCER), any(), any())).thenReturn("aLoadBalancerName");
when(persistenceRetriever.retrieveFirstByTypeAndStatusForStack(eq(ResourceType.ELASTIC_LOAD_BALANCER), eq(CommonStatus.CREATED), any())).thenReturn(Optional.empty());
LoadBalancer loadBalancer = new LoadBalancer().withLoadBalancerArn("anARN");
CreateLoadBalancerResult loadBalancerResult = new CreateLoadBalancerResult().withLoadBalancers(loadBalancer);
when(loadBalancingClient.registerLoadBalancer(any())).thenReturn(loadBalancerResult);
when(resourceNameService.resourceName(eq(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP), any(), any(), any())).thenReturn("aLoadBalancerTGName");
when(persistenceRetriever.retrieveFirstByTypeAndStatusForStack(eq(ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP), eq(CommonStatus.CREATED), any())).thenReturn(Optional.empty());
TargetGroup targetGroup = new TargetGroup().withTargetGroupArn("aTargetGroupArn");
CreateTargetGroupResult createTargetGroupResult = new CreateTargetGroupResult().withTargetGroups(List.of(targetGroup));
when(loadBalancingClient.createTargetGroup(any())).thenReturn(createTargetGroupResult);
when(persistenceRetriever.retrieveFirstByTypeAndStatusForStack(eq(ResourceType.ELASTIC_LOAD_BALANCER_LISTENER), eq(CommonStatus.CREATED), any())).thenReturn(Optional.empty());
AmazonServiceException amazonServiceException = new AmazonServiceException(DUPLICATE_LISTENER_ERROR_CODE);
amazonServiceException.setErrorCode(DUPLICATE_LISTENER_ERROR_CODE);
when(loadBalancingClient.registerListener(any())).thenThrow(amazonServiceException);
Listener listener = new Listener().withListenerArn("aListenerArn");
DescribeListenersResult describeListenersResult = new DescribeListenersResult().withListeners(listener);
when(loadBalancingClient.describeListeners(any())).thenReturn(describeListenersResult);
when(loadBalancingClient.registerTargets(any())).thenThrow(new AmazonElasticLoadBalancingException("something went wrong"));
Assertions.assertThrows(CloudConnectorException.class, () -> undertTest.launchLoadBalancerResources(authenticatedContext, stack, persistenceNotifier, loadBalancingClient, true));
ArgumentCaptor<CloudResource> cloudResourceArgumentCaptor = ArgumentCaptor.forClass(CloudResource.class);
verify(loadBalancingClient, times(1)).registerTargets(any());
verify(persistenceNotifier, times(3)).notifyAllocation(cloudResourceArgumentCaptor.capture(), any());
assertTrue(cloudResourceArgumentCaptor.getAllValues().stream().anyMatch(cloudResource -> ResourceType.ELASTIC_LOAD_BALANCER.equals(cloudResource.getType())));
assertTrue(cloudResourceArgumentCaptor.getAllValues().stream().anyMatch(cloudResource -> ResourceType.ELASTIC_LOAD_BALANCER_TARGET_GROUP.equals(cloudResource.getType())));
assertTrue(cloudResourceArgumentCaptor.getAllValues().stream().anyMatch(cloudResource -> ResourceType.ELASTIC_LOAD_BALANCER_LISTENER.equals(cloudResource.getType())));
}
use of com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer 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.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer 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.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer in project aws-cloudwatch-exporter by asserts.
the class TargetGroupLBMapProviderTest method mapLB.
@Test
public void mapLB() {
Resource lbResource = Resource.builder().arn("lb-arn").build();
LoadBalancer loadBalancer = LoadBalancer.builder().loadBalancerArn("lb-arn").build();
Listener listener = Listener.builder().listenerArn("listener-arn").build();
DescribeListenersRequest request = DescribeListenersRequest.builder().loadBalancerArn("lb-arn").build();
DescribeListenersResponse response = DescribeListenersResponse.builder().listeners(listener).build();
expect(resourceMapper.map(loadBalancer.loadBalancerArn())).andReturn(Optional.of(lbResource));
expect(lbClient.describeListeners(request)).andReturn(response);
metricCollector.recordLatency(eq(SCRAPE_LATENCY_METRIC), anyObject(SortedMap.class), anyLong());
AtomicInteger sideEffect = new AtomicInteger();
TargetGroupLBMapProvider testClass = new TargetGroupLBMapProvider(scrapeConfigProvider, awsClientProvider, resourceMapper, new RateLimiter(metricCollector)) {
@Override
void mapListener(ElasticLoadBalancingV2Client theClient, SortedMap<String, String> labels, Resource theResource, Listener theListener) {
assertEquals(lbClient, theClient);
assertEquals(lbResource, theResource);
assertEquals(listener, theListener);
sideEffect.incrementAndGet();
}
};
replayAll();
testClass.mapLB(lbClient, labels, loadBalancer);
assertEquals(1, sideEffect.get());
verifyAll();
}
Aggregations