@Autowired
private StackRepository stackRepository;
public StackDescription describeStackWithResources(Stack actualStack) {
Stack stack = stackRepository.findById(actualStack.getId());
Credential credential = stack.getCredential();
final CloudPlatform cloudPlatform = credential.cloudPlatform();
if (cloudPlatform.isWithTemplate()) {
return cloudPlatformConnectors.get(cloudPlatform).describeStackWithResources(stack, stack.getCredential());
} else {
try {
DetailedStackDescription dSD = new DetailedStackDescription();
ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
final DescribeContextObject describeContextObject = resourceBuilderInit.describeInit(stack);
for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
Optional<String> describe = resourceBuilder.describe(resource, describeContextObject);
if (describe.isPresent()) {
dSD.getResources().add(describe.get());
}
}
}
for (final ResourceBuilder resourceBuilder : instanceResourceBuilders.get(cloudPlatform)) {
List<Future<Optional<String>>> futures = new ArrayList<>();
for (final Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
Future<Optional<String>> submit = resourceBuilderExecutor.submit(new Callable<Optional<String>>() {
@Override
public Optional<String> call() throws Exception {
return resourceBuilder.describe(resource, describeContextObject);
}
});
futures.add(submit);
}
for (Future<Optional<String>> future : futures) {
if (future.get().isPresent()) {
dSD.getResources().add(future.get().get());
}
}
}
return dSD;
} catch (Exception ex) {
throw new InternalServerException(String.format("Stack describe problem on {} stack", stack.getId()), ex);
}
}
}