Set<Instance> allInstances = Sets.newLinkedHashSet();
for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
final ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
final ComputeService computeService = computeServiceContext.getComputeService();
Credentials credentials = new Credentials(clusterSpec.getIdentity(), clusterSpec.getCredential());
if (numberAllocated == 0) {
for (ComputeMetadata compute : computeService.listNodes()) {
if (!(compute instanceof NodeMetadata)) {
throw new IllegalArgumentException("Not an instance of NodeMetadata: " + compute);
}
nodes.add((NodeMetadata) compute);
}
}
int num = entry.getKey().getNumberOfInstances();
final List<NodeMetadata> templateNodes =
nodes.subList(numberAllocated, numberAllocated + num);
numberAllocated += num;
final Set<Instance> templateInstances = getInstances(
credentials, entry.getKey().getRoles(), templateNodes
);
allInstances.addAll(templateInstances);
for (final Instance instance : templateInstances) {
final Statement statement = statementBuilder.build(clusterSpec, instance);
futures.add(executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
LOG.info("Running script on: {}", instance.getId());