Search in sources :

Example 26 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithPrivateLoadBalancer.

@Test
public void testUpdateCloudformationWithPrivateLoadBalancer() {
    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, 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"));
    underTest.updateCloudformationWithLoadBalancers(ac, cloudStack, null, null);
    verify(cfClient, times(2)).updateStack(any());
    verify(result, times(4)).getStackResourceSummaries();
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) 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 27 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method createSummaries.

private List<StackResourceSummary> createSummaries(Set<LoadBalancerType> types, boolean createLbAndTg, boolean creatListeners) {
    List<StackResourceSummary> summaries = new ArrayList<>();
    for (LoadBalancerType type : types) {
        AwsLoadBalancerScheme scheme = LoadBalancerType.PRIVATE.equals(type) ? AwsLoadBalancerScheme.INTERNAL : AwsLoadBalancerScheme.INTERNET_FACING;
        if (createLbAndTg) {
            StackResourceSummary tgSummary = new StackResourceSummary();
            tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(PORT, scheme));
            tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN);
            tgSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(tgSummary);
            StackResourceSummary lbSummary = new StackResourceSummary();
            lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
            lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN);
            lbSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(lbSummary);
        }
        if (creatListeners) {
            StackResourceSummary lSummary = new StackResourceSummary();
            lSummary.setLogicalResourceId(AwsListener.getListenerName(PORT, scheme));
            lSummary.setResourceStatus(ResourceStatus.CREATE_COMPLETE);
            summaries.add(lSummary);
        }
    }
    return summaries;
}
Also used : ArrayList(java.util.ArrayList) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 28 with StackResourceSummary

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

the class AwsLoadBalancerLaunchService method checkForListenerResources.

@VisibleForTesting
boolean checkForListenerResources(AmazonCloudFormationClient cfClient, String cFStackName, List<AwsLoadBalancer> awsLoadBalancers) {
    ListStackResourcesResult result = cfClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
    boolean resourcesFound = true;
    List<StackResourceSummary> summaries = result.getStackResourceSummaries();
    for (AwsLoadBalancer loadBalancer : awsLoadBalancers) {
        for (AwsListener listener : loadBalancer.getListeners()) {
            LOGGER.debug("Checking to see if listener resource {} already exists", listener.getName());
            resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> listener.getName().equals(stackResourceSummary.getLogicalResourceId()));
        }
    }
    return resourcesFound;
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 29 with StackResourceSummary

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

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMissingTargetGroup.

@Test
public void testCollectLoadBalancerMissingTargetGroup() {
    int numPorts = 1;
    AuthenticatedContext ac = authenticatedContext();
    LoadBalancer loadBalancer = createLoadBalancer();
    List<StackResourceSummary> summaries = createSummaries(numPorts, false);
    ListStackResourcesResult result = new ListStackResourcesResult();
    result.setStackResourceSummaries(summaries);
    Map<String, Object> expectedParameters = new HashMap<>();
    expectedParameters.put(AwsLoadBalancerMetadataView.LOADBALANCER_ARN, LOAD_BALANCER_ARN);
    expectedParameters.put(AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 0, LISTENER_ARN + "0Internal");
    expectedParameters.put(AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 0, null);
    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);
}
Also used : HashMap(java.util.HashMap) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.Test)

Example 30 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary 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);
}
Also used : ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) LoadBalancer(com.amazonaws.services.elasticloadbalancingv2.model.LoadBalancer) AwsLoadBalancer(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) Test(org.junit.jupiter.api.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