for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
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;
instances.addAll(getInstances(credentials,
entry.getKey().getRoles(), templateNodes));
futures.add(executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
LOG.info("Running script");
if (LOG.isDebugEnabled())
LOG.debug("Running script:\n{}", statementBuilder.render(OsFamily.UNIX));
computeService.runScriptOnNodesMatching(
Predicates.in(templateNodes),
statementBuilder);
LOG.info("Script run completed");
return null;
}