use of com.amazonaws.services.cloudformation.model.StackResourceSummary 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.StackResourceSummary 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.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBeanTest method makeAmazonCloudFormationClient.
private static AmazonCloudFormation makeAmazonCloudFormationClient(Map<String, String> resourceIdMappings) {
Map<String, List<StackResourceSummary>> stackResourceSummaries = new HashMap<>();
// allow stack with no
stackResourceSummaries.put(STACK_NAME, new ArrayList<>());
for (Map.Entry<String, String> entry : resourceIdMappings.entrySet()) {
String logicalResourceId = entry.getKey();
String physicalResourceId = entry.getValue();
String physicalStackName;
if (logicalResourceId.contains(".")) {
physicalStackName = resourceIdMappings.get(logicalResourceId.substring(0, logicalResourceId.lastIndexOf(".")));
logicalResourceId = logicalResourceId.substring(logicalResourceId.lastIndexOf(".") + 1);
} else {
physicalStackName = STACK_NAME;
}
List<StackResourceSummary> list = stackResourceSummaries.computeIfAbsent(physicalStackName, k -> new ArrayList<>());
list.add(makeStackResourceSummary(logicalResourceId, physicalResourceId));
}
AmazonCloudFormation amazonCloudFormationClient = mock(AmazonCloudFormation.class);
for (Map.Entry<String, List<StackResourceSummary>> entry : stackResourceSummaries.entrySet()) {
String stackName = entry.getKey();
ListStackResourcesResult listStackResourcesResult = mock(ListStackResourcesResult.class);
when(listStackResourcesResult.getStackResourceSummaries()).thenReturn(entry.getValue());
when(amazonCloudFormationClient.listStackResources(argThat(item -> item != null && stackName.equals((item).getStackName())))).thenReturn(listStackResourcesResult);
}
return amazonCloudFormationClient;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project spring-cloud-aws by awspring.
the class StackResourceRegistryFactoryBeanTest method makeStackResourceSummary.
private static StackResourceSummary makeStackResourceSummary(String logicalResourceId, String physicalResourceId) {
StackResourceSummary stackResourceSummary = mock(StackResourceSummary.class);
when(stackResourceSummary.getLogicalResourceId()).thenReturn(logicalResourceId);
when(stackResourceSummary.getPhysicalResourceId()).thenReturn(physicalResourceId);
when(stackResourceSummary.getResourceType()).thenReturn(logicalResourceId.endsWith("Stack") ? "AWS::CloudFormation::Stack" : "Amazon::SES::Test");
return stackResourceSummary;
}
use of com.amazonaws.services.cloudformation.model.StackResourceSummary in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method setLoadBalancerMetadata.
@VisibleForTesting
void setLoadBalancerMetadata(List<AwsLoadBalancer> awsLoadBalancers, ListStackResourcesResult result) {
List<StackResourceSummary> summaries = result.getStackResourceSummaries();
for (AwsLoadBalancer loadBalancer : awsLoadBalancers) {
LOGGER.debug("Processing load balancer {}", loadBalancer.getName());
for (AwsListener listener : loadBalancer.getListeners()) {
LOGGER.debug("Processing listener {} and target group {}", listener.getName(), listener.getTargetGroup().getName());
Optional<StackResourceSummary> targetGroupSummary = summaries.stream().filter(stackResourceSummary -> listener.getTargetGroup().getName().equals(stackResourceSummary.getLogicalResourceId())).findFirst();
if (targetGroupSummary.isEmpty()) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: target group %s not found.", listener.getTargetGroup().getName()));
}
if (StringUtils.isEmpty(targetGroupSummary.get().getPhysicalResourceId())) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: target group %s arn not found.", listener.getTargetGroup().getName()));
}
listener.getTargetGroup().setArn(targetGroupSummary.get().getPhysicalResourceId());
LOGGER.debug("Found arn {} for target group {}", listener.getTargetGroup().getArn(), listener.getTargetGroup().getName());
}
Optional<StackResourceSummary> loadBalancerSummary = summaries.stream().filter(stackResourceSummary -> loadBalancer.getName().equals(stackResourceSummary.getLogicalResourceId())).findFirst();
if (loadBalancerSummary.isEmpty()) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: load balancer %s not found.", loadBalancer.getName()));
}
if (StringUtils.isEmpty(loadBalancerSummary.get().getPhysicalResourceId())) {
throw new CloudConnectorException(String.format("Could not create load balancer listeners: load balancer %s arn not found.", loadBalancer.getName()));
}
loadBalancer.setArn(loadBalancerSummary.get().getPhysicalResourceId());
loadBalancer.validateListenerConfigIsSet();
LOGGER.debug("Found arn {} for load balancer {}", loadBalancer.getArn(), loadBalancer.getName());
}
}
Aggregations