Search in sources :

Example 16 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationSuccess.

@Test
public void testUpdateCloudformationSuccess() {
    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, 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.CREATED, statuses.get(0).getStatus());
    assertEquals(CREATED, 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 17 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithEndpointGatewayAndPrivateSubnet.

@Test
public void testUpdateCloudformationWithEndpointGatewayAndPrivateSubnet() {
    List<CloudResource> instances = createInstances();
    AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, PUBLIC_ID_1);
    Network network = createNetwork(PRIVATE_ID_1, PUBLIC_ID_1);
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PUBLIC, LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    List<StackResourceSummary> secondUpdateSummaries = createFullSummaries(types);
    setupMocksForUpdate(awsNetworkView, network, instances, Set.of(LoadBalancerType.PUBLIC, 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(5)).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 18 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithLoadBalancerMissingTargetGroupArn.

@Test
public void testUpdateCloudformationWithLoadBalancerMissingTargetGroupArn() {
    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: target group %s arn not found.", AwsTargetGroup.getTargetGroupName(PORT, AwsLoadBalancerScheme.INTERNAL));
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    StackResourceSummary tgSummary = firstUpdateSummaries.get(TG_INDEX);
    tgSummary.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 19 with StackResourceSummary

use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project pipeline-aws-plugin by jenkinsci.

the class LambdaVersionCleanupStepTest method deleteCloudFormationStack.

@Test
public void deleteCloudFormationStack() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.awsLambda.listAliases(Mockito.eq(new ListAliasesRequest().withFunctionName("foo2")))).thenReturn(new ListAliasesResult());
    Mockito.when(this.awsLambda.listVersionsByFunction(Mockito.eq(new ListVersionsByFunctionRequest().withFunctionName("foo2")))).thenReturn(new ListVersionsByFunctionResult().withVersions(Arrays.asList(new FunctionConfiguration().withVersion("v1").withLastModified(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)), new FunctionConfiguration().withVersion("v2").withLastModified("2018-02-05T11:15:12Z"))));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")).withNextToken("foo"));
    Mockito.when(this.cloudformation.listStackResources(new ListStackResourcesRequest().withStackName("baz").withNextToken("foo"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withResourceType("AWS::Lambda::Function").withPhysicalResourceId("foo2"), new StackResourceSummary().withResourceType("AWS::Baz::Function").withPhysicalResourceId("bar")));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  lambdaVersionCleanup(stackName: 'baz', daysAgo: 5)\n" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo"));
    Mockito.verify(this.awsLambda).deleteFunction(new DeleteFunctionRequest().withQualifier("v2").withFunctionName("foo2"));
    Mockito.verify(this.awsLambda, Mockito.times(2)).listVersionsByFunction(Mockito.any());
    Mockito.verify(this.awsLambda, Mockito.times(2)).listAliases(Mockito.any());
    Mockito.verifyNoMoreInteractions(this.awsLambda);
}
Also used : ListAliasesResult(com.amazonaws.services.lambda.model.ListAliasesResult) ListVersionsByFunctionResult(com.amazonaws.services.lambda.model.ListVersionsByFunctionResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ListStackResourcesResult(com.amazonaws.services.cloudformation.model.ListStackResourcesResult) FunctionConfiguration(com.amazonaws.services.lambda.model.FunctionConfiguration) ListAliasesRequest(com.amazonaws.services.lambda.model.ListAliasesRequest) ListVersionsByFunctionRequest(com.amazonaws.services.lambda.model.ListVersionsByFunctionRequest) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DeleteFunctionRequest(com.amazonaws.services.lambda.model.DeleteFunctionRequest) ListStackResourcesRequest(com.amazonaws.services.cloudformation.model.ListStackResourcesRequest) StackResourceSummary(com.amazonaws.services.cloudformation.model.StackResourceSummary) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with StackResourceSummary

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

the class AwsLaunchServiceLoadBalancerTest method testUpdateCloudformationWithLoadBalancerMissingTargetGroup.

@Test
public void testUpdateCloudformationWithLoadBalancerMissingTargetGroup() {
    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: target group %s not found.", AwsTargetGroup.getTargetGroupName(PORT, AwsLoadBalancerScheme.INTERNAL));
    Set<LoadBalancerType> types = Set.of(LoadBalancerType.PRIVATE);
    List<StackResourceSummary> firstUpdateSummaries = createFirstUpdateSummaries(types);
    firstUpdateSummaries.remove(TG_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)

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