ComputeServiceContext computeServiceContext =
ComputeServiceContextBuilder.build(clusterSpec);
ComputeService computeService = computeServiceContext.getComputeService();
Payload bootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
"sun/java/install",
"apache/cassandra/install"));
TemplateBuilder templateBuilder = computeService.templateBuilder()
.options(
runScript(bootScript).installPrivateKey(
clusterSpec.getPrivateKey()).authorizePublicKey(
clusterSpec.getPublicKey()));
new TemplateBuilderStrategy().configureTemplateBuilder(clusterSpec,
templateBuilder);
LOG.info("Configuring template");
Template template = templateBuilder.build();
InstanceTemplate instanceTemplate = clusterSpec
.getInstanceTemplate(CASSANDRA_ROLE);
checkNotNull(instanceTemplate);
int clusterSize = instanceTemplate.getNumberOfInstances();
Set<? extends NodeMetadata> nodeMap;
try {
LOG.info("Starting {} node(s)", clusterSize);
nodeMap = computeService.runNodesWithTag(clusterSpec.getClusterName(),
clusterSize, template);
LOG.info("Nodes started: {}", nodeMap);
} catch (RunNodesException e) {
// TODO: can we do better here
throw new IOException(e);
}
LOG.info("Authorizing firewall");
FirewallSettings.authorizeIngress(computeServiceContext, nodeMap, clusterSpec, CLIENT_PORT);
List<NodeMetadata> nodes = Lists.newArrayList(nodeMap);
List<NodeMetadata> seeds = getSeeds(nodes);
// Pass list of all servers in cluster to configure script.
String servers = Joiner.on(' ').join(getPrivateIps(seeds));
Payload configureScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
String.format("apache/cassandra/post-configure -c %s %s",
clusterSpec.getProvider(),
servers)));
// Use private key to run script
Credentials credentials = new Credentials(