Search in sources :

Example 1 with Cluster

use of org.apache.whirr.service.Cluster 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));
}
Also used : ExecResponse(org.jclouds.ssh.ExecResponse) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) Cluster(org.apache.whirr.service.Cluster) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) IOException(java.io.IOException) ComputeService(org.jclouds.compute.ComputeService) Template(org.jclouds.compute.domain.Template) InstanceTemplate(org.apache.whirr.service.ClusterSpec.InstanceTemplate) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) RunNodesException(org.jclouds.compute.RunNodesException) RunScriptOnNodesException(org.jclouds.compute.RunScriptOnNodesException) InstanceTemplate(org.apache.whirr.service.ClusterSpec.InstanceTemplate)

Aggregations

IOException (java.io.IOException)1 Cluster (org.apache.whirr.service.Cluster)1 InstanceTemplate (org.apache.whirr.service.ClusterSpec.InstanceTemplate)1 ComputeService (org.jclouds.compute.ComputeService)1 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)1 RunNodesException (org.jclouds.compute.RunNodesException)1 RunScriptOnNodesException (org.jclouds.compute.RunScriptOnNodesException)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 Template (org.jclouds.compute.domain.Template)1 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)1 ExecResponse (org.jclouds.ssh.ExecResponse)1