Search in sources :

Example 21 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithLoadBalancerMissingLoadBalancerArn.

@Test
public void testUpdateCloudformationWithLoadBalancerMissingLoadBalancerArn() {
    List<CloudResource> instances = createInstances();
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
    Network network = createNetwork(PRIVATE_ID_1, null);
    String expectedError = String.format("Could not create load balancer listeners: load balancer %s arn not found.", AwsLoadBalancer.getLoadBalancerName(AwsLoadBalancerScheme.INTERNAL));
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    StackResourceSummary lbSummary = firstUpdateSummaries.get(LB_INDEX);
    lbSummary.setPhysicalResourceId(null);
    List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
    setupMocksForUpdate(awsNetworkView, network, instances, types);
    when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
    CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null));
    verify(cfClient, times(1)).updateStack(any());
    verify(result, times(2)).getStackResourceSummaries();
    assertEquals(expectedError, exception.getMessage());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationLoadBalancerCreateFailure.

@Test
public void testUpdateCloudformationLoadBalancerCreateFailure() {
    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);
    secondUpdateSummaries.get(LB_INDEX).setResourceStatus(ResourceStatus.CREATE_FAILED);
    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.FAILED, statuses.get(0).getStatus());
    assertEquals(FAILED, statuses.get(0).getCloudResource().getStatus());
    assertEquals(ELASTIC_LOAD_BALANCER, statuses.get(0).getCloudResource().getType());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithLoadBalancerMissingLoadBalancer.

@Test
public void testUpdateCloudformationWithLoadBalancerMissingLoadBalancer() {
    List<CloudResource> instances = createInstances();
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
    Network network = createNetwork(PRIVATE_ID_1, null);
    String expectedError = String.format("Could not create load balancer listeners: load balancer %s not found.", AwsLoadBalancer.getLoadBalancerName(AwsLoadBalancerScheme.INTERNAL));
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    firstUpdateSummaries.remove(LB_INDEX);
    List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
    setupMocksForUpdate(awsNetworkView, network, instances, types);
    when(result.getStackResourceSummaries()).thenReturn(List.of()).thenReturn(firstUpdateSummaries).thenReturn(firstUpdateSummaries).thenReturn(secondUpdateSummaries);
    CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null));
    verify(cfClient, times(1)).updateStack(any());
    verify(result, times(2)).getStackResourceSummaries();
    assertEquals(expectedError, exception.getMessage());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationTargetGroupCreateFailure.

@Test
public void testUpdateCloudformationTargetGroupCreateFailure() {
    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);
    secondUpdateSummaries.get(TG_INDEX).setResourceStatus(ResourceStatus.CREATE_FAILED);
    setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PRIVATE));
    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.FAILED, statuses.get(0).getStatus());
    assertEquals(FAILED, statuses.get(0).getCloudResource().getStatus());
    assertEquals(ELASTIC_LOAD_BALANCER, statuses.get(0).getCloudResource().getType());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationListenerCreateFailure.

@Test
public void testUpdateCloudformationListenerCreateFailure() {
    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);
    secondUpdateSummaries.get(LIS_INDEX).setResourceStatus(ResourceStatus.CREATE_FAILED);
    setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PRIVATE));
    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.FAILED, statuses.get(0).getStatus());
    assertEquals(FAILED, statuses.get(0).getCloudResource().getStatus());
    assertEquals(ELASTIC_LOAD_BALANCER, statuses.get(0).getCloudResource().getType());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StackResourceSummary (com.amazonaws.services.cloudformation.model.StackResourceSummary)34 ListStackResourcesResult (com.amazonaws.services.cloudformation.model.ListStackResourcesResult)17 ListStackResourcesRequest (com.amazonaws.services.cloudformation.model.ListStackResourcesRequest)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)13 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)13 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)12 Network (com.sequenceiq.cloudbreak.cloud.model.Network)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)11 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)9 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)5 ArrayList (java.util.ArrayList)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 AwsListener (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)4