Search in sources :

Example 11 with StackResourceSummary

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

the class AwsLoadBalancerLaunchService method createLoadBalancerStatus.

private CloudResourceStatus createLoadBalancerStatus(AuthenticatedContext ac, AwsLoadBalancer loadBalancer, ListStackResourcesResult result) {
    LOGGER.debug(String.format("Checking final status of AWS load balancer %s", loadBalancer.getName()));
    List<StackResourceSummary> summaries = result.getStackResourceSummaries();
    boolean createSuccess = isResourceStatusGood(summaries, loadBalancer.getName());
    for (AwsListener listener : loadBalancer.getListeners()) {
        LOGGER.debug(String.format("Checking final status of AWS listener %s", listener.getName()));
        createSuccess = createSuccess && isResourceStatusGood(summaries, listener.getName());
        LOGGER.debug(String.format("Checking final status of AWS target group %s", listener.getTargetGroup().getName()));
        createSuccess = createSuccess && isResourceStatusGood(summaries, listener.getTargetGroup().getName());
    }
    CloudResource.Builder cloudResource = new CloudResource.Builder().status(createSuccess ? CommonStatus.CREATED : CommonStatus.FAILED).type(ELASTIC_LOAD_BALANCER).availabilityZone(ac.getCloudContext().getLocation().getAvailabilityZone().value()).name(loadBalancer.getName());
    return new CloudResourceStatus(cloudResource.build(), createSuccess ? com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED : com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.FAILED);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudFormationTemplateBuilder(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder) AwsListener(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsListener) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary)

Example 12 with StackResourceSummary

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

the class AwsLoadBalancerLaunchService method checkForLoadBalancerAndTargetGroupResources.

@VisibleForTesting
boolean checkForLoadBalancerAndTargetGroupResources(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) {
        LOGGER.debug("Checking to see if load balancer resource {} already exists", loadBalancer.getName());
        resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> loadBalancer.getName().equals(stackResourceSummary.getLogicalResourceId()));
        for (AwsListener listener : loadBalancer.getListeners()) {
            LOGGER.debug("Checking to see if target group resource {} already exists", listener.getTargetGroup().getName());
            resourcesFound = resourcesFound && summaries.stream().anyMatch(stackResourceSummary -> listener.getTargetGroup().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 13 with StackResourceSummary

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

the class AwsLoadBalancerMetadataCollectorTest method testCollectLoadBalancerMultiplePorts.

@Test
public void testCollectLoadBalancerMultiplePorts() {
    int numPorts = 3;
    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", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 1, LISTENER_ARN + "1Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 1, TARGET_GROUP_ARN + "1Internal", AwsLoadBalancerMetadataView.LISTENER_ARN_PREFIX + 2, LISTENER_ARN + "2Internal", AwsLoadBalancerMetadataView.TARGET_GROUP_ARN_PREFIX + 2, TARGET_GROUP_ARN + "2Internal");
    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)

Example 14 with StackResourceSummary

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

the class AwsLoadBalancerMetadataCollectorTest method createSummaries.

private List<StackResourceSummary> createSummaries(int numPorts, boolean includeTargetGroup) {
    List<StackResourceSummary> summaries = new ArrayList<>();
    for (AwsLoadBalancerScheme scheme : AwsLoadBalancerScheme.class.getEnumConstants()) {
        StackResourceSummary lbSummary = new StackResourceSummary();
        lbSummary.setLogicalResourceId(AwsLoadBalancer.getLoadBalancerName(scheme));
        lbSummary.setPhysicalResourceId(LOAD_BALANCER_ARN + scheme.resourceName());
        summaries.add(lbSummary);
        for (int i = 0; i < numPorts; i++) {
            if (includeTargetGroup) {
                StackResourceSummary tgSummary = new StackResourceSummary();
                tgSummary.setLogicalResourceId(AwsTargetGroup.getTargetGroupName(i, scheme));
                tgSummary.setPhysicalResourceId(TARGET_GROUP_ARN + i + scheme.resourceName());
                summaries.add(tgSummary);
            }
            StackResourceSummary lSummary = new StackResourceSummary();
            lSummary.setLogicalResourceId(AwsListener.getListenerName(i, scheme));
            lSummary.setPhysicalResourceId(LISTENER_ARN + i + scheme.resourceName());
            summaries.add(lSummary);
        }
    }
    return summaries;
}
Also used : ArrayList(java.util.ArrayList) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Example 15 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary 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();
}
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)

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