CloudPlatformConnector connector = cloudPlatformConnectors.get(cloudPlatform);
stopped = connector.stopAll(stack);
} else {
try {
ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
final StartStopContextObject sSCO = resourceBuilderInit.startStopInit(stack);
for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
resourceBuilder.stop(sSCO, resource);
}
}
List<Future<Boolean>> futures = new ArrayList<>();
for (final ResourceBuilder resourceBuilder : instanceResourceBuilders.get(cloudPlatform)) {
List<Resource> resourceByType = stack.getResourcesByType(resourceBuilder.resourceType());
for (final Resource resource : resourceByType) {
Future<Boolean> submit = resourceBuilderExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return resourceBuilder.stop(sSCO, resource);
}
});
futures.add(submit);
}
}
for (Future<Boolean> future : futures) {
if (!future.get()) {
stopped = false;
}
}
} catch (Exception ex) {
stopped = false;
}
}
if (stopped) {
LOGGER.info("Update stack state to: {}", Status.STOPPED);
stackUpdater.updateStackStatus(stackId, Status.STOPPED);
cloudbreakEventService.fireCloudbreakEvent(stackId, BillingStatus.BILLING_STOPPED.name(), "Stack stopped.");
} else {
LOGGER.info("Update stack state to: {}", Status.STOP_FAILED);
stackUpdater.updateStackStatus(stackId, Status.STOP_FAILED);
}
} else {
boolean started = true;
if (cloudPlatform.isWithTemplate()) {
CloudPlatformConnector connector = cloudPlatformConnectors.get(cloudPlatform);
started = connector.startAll(stack);
} else {
try {
ResourceBuilderInit resourceBuilderInit = resourceBuilderInits.get(cloudPlatform);
final StartStopContextObject sSCO = resourceBuilderInit.startStopInit(stack);
for (ResourceBuilder resourceBuilder : networkResourceBuilders.get(cloudPlatform)) {
for (Resource resource : stack.getResourcesByType(resourceBuilder.resourceType())) {
resourceBuilder.start(sSCO, resource);
}