use of org.jclouds.ssh.ExecResponse in project whirr by apache.
the class CassandraService method launchCluster.
@Override
public Cluster launchCluster(ClusterSpec clusterSpec) throws IOException {
ComputeServiceContext computeServiceContext = ComputeServiceContextBuilder.build(clusterSpec);
ComputeService computeService = computeServiceContext.getComputeService();
byte[] bootScript = RunUrlBuilder.runUrls("sun/java/install", "apache/cassandra/install");
TemplateBuilder templateBuilder = computeService.templateBuilder().osFamily(UBUNTU).options(runScript(bootScript).installPrivateKey(clusterSpec.readPrivateKey()).authorizePublicKey(clusterSpec.readPublicKey()));
// TODO extract this logic elsewhere
if (clusterSpec.getProvider().equals("ec2"))
templateBuilder.imageNameMatches(".*10\\.?04.*").osDescriptionMatches("^ubuntu-images.*").architecture(Architecture.X86_32);
Template template = templateBuilder.build();
InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(CASSANDRA_ROLE);
checkNotNull(instanceTemplate);
int clusterSize = instanceTemplate.getNumberOfInstances();
Set<? extends NodeMetadata> nodeMap;
try {
nodeMap = computeService.runNodesWithTag(clusterSpec.getClusterName(), clusterSize, template);
} catch (RunNodesException e) {
// TODO: can we do better here
throw new IOException(e);
}
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));
byte[] configureScript = RunUrlBuilder.runUrls("apache/cassandra/post-configure " + servers);
try {
Map<? extends NodeMetadata, ExecResponse> responses = computeService.runScriptOnNodesMatching(runningWithTag(clusterSpec.getClusterName()), configureScript);
assert responses.size() > 0 : "no nodes matched " + clusterSpec.getClusterName();
} catch (RunScriptOnNodesException e) {
// TODO: retry
throw new IOException(e);
}
return new Cluster(getInstances(nodes));
}
Aggregations