MDCBuilder.buildMdcContext(stack);
LOGGER.info("Accepted {} event.", ReactorConfig.DELETE_REQUEST_EVENT);
try {
if (!data.getCloudPlatform().isWithTemplate()) {
ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(data.getCloudPlatform());
final DeleteContextObject dCO = resourceBuilderInit.deleteInit(stack);
for (int i = instanceResourceBuilders.get(data.getCloudPlatform()).size() - 1; i >= 0; i--) {
List<Future<Boolean>> futures = new ArrayList<>();
final int index = i;
List<Resource> resourceByType = stack.getResourcesByType(instanceResourceBuilders.get(data.getCloudPlatform()).get(i).resourceType());
for (final Resource resource : resourceByType) {
Future<Boolean> submit = resourceBuilderExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return instanceResourceBuilders.get(data.getCloudPlatform()).get(index).delete(resource, dCO);
}
});
futures.add(submit);
}
for (Future<Boolean> future : futures) {
future.get();
}
}
for (int i = instanceResourceBuilders.get(data.getCloudPlatform()).size() - 1; i >= 0; i--) {
for (Resource resource : stack.getResourcesByType(networkResourceBuilders.get(data.getCloudPlatform()).get(i).resourceType())) {
networkResourceBuilders.get(data.getCloudPlatform()).get(i).delete(resource, dCO);
}
}
reactor.notify(ReactorConfig.DELETE_COMPLETE_EVENT, Event.wrap(new StackDeleteComplete(dCO.getStackId())));
} else {
cloudPlatformConnectors.get(data.getCloudPlatform()).deleteStack(stack, stack.getCredential());
}
} catch (Exception ex) {
LOGGER.error(String.format("Stack delete failed on {} stack: ", stack.getId()), ex);