use of com.amazonaws.services.elasticloadbalancingv2.model.AmazonElasticLoadBalancingException in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchServiceTest method testLaunchLoadBalancerResourcesWhenLoadBalancerCouldNotBeCreated.
@Test
void testLaunchLoadBalancerResourcesWhenLoadBalancerCouldNotBeCreated() {
CloudStack stack = getCloudStack();
when(loadBalancerCommonService.getAwsLoadBalancers(any(), any(), any())).thenReturn(List.of(getAwsLoadBalancer()));
when(persistenceRetriever.retrieveFirstByTypeAndStatusForStack(eq(ResourceType.ELASTIC_LOAD_BALANCER), eq(CommonStatus.CREATED), any())).thenReturn(Optional.empty());
when(loadBalancingClient.registerLoadBalancer(any())).thenThrow(new AmazonElasticLoadBalancingException("something went wrong"));
Assertions.assertThrows(CloudConnectorException.class, () -> undertTest.launchLoadBalancerResources(authenticatedContext, stack, persistenceNotifier, loadBalancingClient, true));
}
use of com.amazonaws.services.elasticloadbalancingv2.model.AmazonElasticLoadBalancingException 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())));
}
Aggregations