use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName.
// @checkstyle:off
@Test
void stackResourceRegistry_stackConfigurationWithStaticName_stackResourceRegistryBeanExposedUnderStaticStackName() throws Exception {
// @checkstyle:on
// Arrange
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("IntegrationTestStack"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary()));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-staticStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
// Act
StackResourceRegistry staticStackNameProviderBasedStackResourceRegistry = applicationContext.getBean("IntegrationTestStack", StackResourceRegistry.class);
// Assert
assertThat(staticStackNameProviderBasedStackResourceRegistry).isNotNull();
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBean method getStackResourceSummaries.
private List<StackResourceSummary> getStackResourceSummaries(String stackName) {
ListStackResourcesResult listStackResourcesResult = this.amazonCloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(stackName));
if (!StringUtils.hasText(listStackResourcesResult.getNextToken())) {
return listStackResourcesResult.getStackResourceSummaries();
} else {
List<StackResourceSummary> result = new ArrayList<>(listStackResourcesResult.getStackResourceSummaries());
while (StringUtils.hasText(listStackResourcesResult.getNextToken())) {
listStackResourcesResult = this.amazonCloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(stackName).withNextToken(listStackResourcesResult.getNextToken()));
result.addAll(listStackResourcesResult.getStackResourceSummaries());
}
return result;
}
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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);
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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);
}
use of com.amazonaws.services.cloudformation.model.ListStackResourcesRequest 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);
}
Aggregations