ExecutorService executorService = Executors.newCachedThreadPool();
Map<InstanceTemplate, Future<Set<? extends NodeMetadata>>> futures = Maps.newHashMap();
// initialize startup processes per InstanceTemplates
for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
final InstanceTemplate instanceTemplate = entry.getKey();
final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
final int maxNumberOfRetries = clusterSpec.getMaxStartupRetries();
StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
final ComputeService computeService =
computeServiceContext.getComputeService();
final Template template = BootstrapTemplate.build(clusterSpec, computeService,
statementBuilder, entry.getValue().getTemplateBuilderStrategy());
if (template.getOptions() != null) {
template.getOptions()
.nameTask("bootstrap-" + Joiner.on('_').join(entry.getKey().getRoles()));
}
Future<Set<? extends NodeMetadata>> nodesFuture = executorService.submit(
new StartupProcess(
clusterSpec.getClusterName(),
instanceTemplate.getNumberOfInstances(),
instanceTemplate.getMinNumberOfInstances(),
maxNumberOfRetries,
instanceTemplate.getRoles(),
computeService, template, executorService, nodeStarterFactory));
futures.put(instanceTemplate, nodesFuture);
}
Set<Instance> instances = Sets.newLinkedHashSet();