use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackConfigurationBeanDefinitionParserTest method resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId.
// @checkstyle:off
@Test
void resourceIdResolverResolveToPhysicalResourceId_stackConfigurationWithoutStaticNameAndLogicalResourceIdOfExistingResourceProvided_returnsPhysicalResourceId() throws Exception {
// @checkstyle:on
// Arrange
HttpServer server = MetaDataServer.setupHttpServer();
HttpContext httpContext = server.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("foo"));
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
AmazonCloudFormation amazonCloudFormation = Mockito.mock(AmazonCloudFormation.class);
when(amazonCloudFormation.describeStackResources(new DescribeStackResourcesRequest().withPhysicalResourceId("foo"))).thenReturn(new DescribeStackResourcesResult().withStackResources(new StackResource().withStackName("test")));
when(amazonCloudFormation.listStackResources(new ListStackResourcesRequest().withStackName("test"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("EmptyBucket").withPhysicalResourceId("integrationteststack-emptybucket-foo")));
applicationContext.load(new ClassPathResource(getClass().getSimpleName() + "-autoDetectStackName.xml", getClass()));
applicationContext.getBeanFactory().registerSingleton(getBeanName(AmazonCloudFormation.class.getName()), amazonCloudFormation);
applicationContext.refresh();
ResourceIdResolver resourceIdResolver = applicationContext.getBean(ResourceIdResolver.class);
// Act
String physicalResourceId = resourceIdResolver.resolveToPhysicalResourceId("EmptyBucket");
// Assert
assertThat(physicalResourceId).startsWith("integrationteststack-emptybucket-");
server.removeContext(httpContext);
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBeanTest method createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages.
@Test
void createInstance_stackWithNextTag_returnsStackResourceRegistryBuildWithTwoPages() throws Exception {
// Arrange
AmazonCloudFormation cloudFormationClient = mock(AmazonCloudFormation.class);
StackResourceRegistryFactoryBean stackResourceRegistryFactoryBean = new StackResourceRegistryFactoryBean(cloudFormationClient, new StaticStackNameProvider(STACK_NAME));
when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME))).thenReturn(new ListStackResourcesResult().withNextToken("2").withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log1")));
when(cloudFormationClient.listStackResources(new ListStackResourcesRequest().withStackName(STACK_NAME).withNextToken("2"))).thenReturn(new ListStackResourcesResult().withStackResourceSummaries(new StackResourceSummary().withLogicalResourceId("log2")));
// Act
ListableStackResourceFactory stackResourceFactory = stackResourceRegistryFactoryBean.createInstance();
// Assert
verify(cloudFormationClient, times(2)).listStackResources(isA(ListStackResourcesRequest.class));
assertThat(stackResourceFactory.getAllResources().size()).isEqualTo(2);
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBean method convertToStackResourceMappings.
private Map<String, StackResource> convertToStackResourceMappings(String prefix, List<StackResourceSummary> stackResourceSummaries) {
Map<String, StackResource> stackResourceMappings = new HashMap<>();
for (StackResourceSummary stackResourceSummary : stackResourceSummaries) {
String logicalResourceId = toNestedResourceId(prefix, stackResourceSummary.getLogicalResourceId());
stackResourceMappings.put(logicalResourceId, new StackResource(logicalResourceId, stackResourceSummary.getPhysicalResourceId(), stackResourceSummary.getResourceType()));
}
return stackResourceMappings;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBean method getResourceMappings.
private Map<String, StackResource> getResourceMappings(String prefix, String stackName) {
List<StackResourceSummary> stackResourceSummaries = getStackResourceSummaries(stackName);
Map<String, StackResource> current = convertToStackResourceMappings(prefix, stackResourceSummaries);
Map<String, StackResource> stackResourceMappings = new HashMap<>(current);
for (Map.Entry<String, StackResource> e : current.entrySet()) {
StackResource resource = e.getValue();
if ("AWS::CloudFormation::Stack".equals(resource.getType())) {
stackResourceMappings.putAll(getResourceMappings(e.getKey(), resource.getPhysicalId()));
}
}
return stackResourceMappings;
}
Aggregations