Search in sources :

Example 36 with Cluster

use of org.apache.whirr.Cluster in project whirr by apache.

the class RunScriptCommandTest method createTestCluster.

private Cluster createTestCluster(String[] ids, String[] roles) {
    checkArgument(ids.length == roles.length, "each ID should have a role");
    Credentials credentials = new Credentials("dummy", "dummy");
    Set<Cluster.Instance> instances = Sets.newHashSet();
    for (int i = 0; i < ids.length; i++) {
        String ip = "127.0.0." + (i + 1);
        instances.add(new Cluster.Instance(credentials, Sets.newHashSet(roles[i]), ip, ip, ids[i], null));
    }
    return new Cluster(instances);
}
Also used : Cluster(org.apache.whirr.Cluster) Matchers.containsString(org.hamcrest.Matchers.containsString) Credentials(org.jclouds.domain.Credentials)

Example 37 with Cluster

use of org.apache.whirr.Cluster in project whirr by apache.

the class ScriptBasedClusterAction method runScripts.

protected void runScripts(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws InterruptedException, IOException {
    final String phaseName = getAction();
    final Collection<Future<ExecResponse>> futures = Sets.newHashSet();
    final ClusterSpec clusterSpec = eventMap.values().iterator().next().getClusterSpec();
    final RunScriptOptions options = overrideLoginCredentials(LoginCredentials.builder().user(clusterSpec.getClusterUser()).privateKey(clusterSpec.getPrivateKey()).build());
    for (Map.Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
        if (shouldIgnoreInstanceTemplate(entry.getKey())) {
            // skip if not in the target
            continue;
        }
        Cluster cluster = entry.getValue().getCluster();
        StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
        if (statementBuilder.isEmpty()) {
            // skip execution if we have an empty list
            continue;
        }
        Set<Instance> instances = cluster.getInstancesMatching(Predicates.<Instance>and(onlyRolesIn(entry.getKey().getRoles()), not(instanceIsNotInTarget())));
        LOG.info("Starting to run scripts on cluster for phase {} " + "on instances: {}", phaseName, asString(instances));
        for (Instance instance : instances) {
            futures.add(runStatementOnInstanceInCluster(statementBuilder, instance, clusterSpec, options));
        }
    }
    for (Future<ExecResponse> future : futures) {
        try {
            future.get();
        } catch (ExecutionException e) {
            throw new IOException(e.getCause());
        }
    }
    LOG.info("Finished running {} phase scripts on all cluster instances", phaseName);
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) Instance(org.apache.whirr.Cluster.Instance) ExecResponse(org.jclouds.compute.domain.ExecResponse) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterActionEvent(org.apache.whirr.service.ClusterActionEvent) IOException(java.io.IOException) StatementBuilder(org.apache.whirr.service.jclouds.StatementBuilder) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Future(java.util.concurrent.Future) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) InstanceTemplate(org.apache.whirr.InstanceTemplate)

Example 38 with Cluster

use of org.apache.whirr.Cluster in project whirr by apache.

the class ClusterStateStore method unserialize.

/**
 * Rebuild the {@link Cluster} instance by using the string representation
 *
 * @param spec
 * @param content
 * @return
 * @throws UnknownHostException
 */
protected Cluster unserialize(ClusterSpec spec, String content) throws UnknownHostException {
    Credentials credentials = new Credentials(spec.getClusterUser(), spec.getPrivateKey());
    Set<Cluster.Instance> instances = Sets.newLinkedHashSet();
    for (String line : Splitter.on("\n").split(content)) {
        if (line.trim().equals(""))
            continue;
        /* ignore empty lines */
        Iterator<String> fields = Splitter.on("\t").split(line).iterator();
        String id = fields.next();
        Set<String> roles = Sets.newLinkedHashSet(Splitter.on(",").split(fields.next()));
        String publicIPAddress = fields.next();
        String privateIPAddress = fields.next();
        instances.add(new Cluster.Instance(credentials, roles, publicIPAddress, privateIPAddress, id, null));
    }
    return new Cluster(instances);
}
Also used : Cluster(org.apache.whirr.Cluster) Credentials(org.jclouds.domain.Credentials)

Example 39 with Cluster

use of org.apache.whirr.Cluster in project whirr by apache.

the class LaunchClusterCommand method run.

public int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec) throws Exception {
    ClusterController controller = createClusterController(clusterSpec.getServiceName());
    Cluster cluster = controller.launchCluster(clusterSpec);
    out.printf("Started cluster of %s instances\n", cluster.getInstances().size());
    out.println(cluster);
    Utils.printSSHConnectionDetails(out, clusterSpec, cluster, 20);
    out.println("To destroy cluster, run 'whirr destroy-cluster' with the same options used to launch it.");
    return 0;
}
Also used : ClusterController(org.apache.whirr.ClusterController) Cluster(org.apache.whirr.Cluster)

Example 40 with Cluster

use of org.apache.whirr.Cluster in project whirr by apache.

the class ZooKeeperClusterActionHandler method afterConfigure.

@Override
protected void afterConfigure(ClusterActionEvent event) {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Cluster cluster = event.getCluster();
    LOG.info("Completed configuration of {}", clusterSpec.getClusterName());
    String hosts = Joiner.on(',').join(getHosts(cluster.getInstancesMatching(role(ZOOKEEPER_ROLE))));
    LOG.info("Hosts: {}", hosts);
}
Also used : Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec)

Aggregations

Cluster (org.apache.whirr.Cluster)52 ClusterSpec (org.apache.whirr.ClusterSpec)35 Instance (org.apache.whirr.Cluster.Instance)19 Configuration (org.apache.commons.configuration.Configuration)16 IOException (java.io.IOException)9 InetAddress (java.net.InetAddress)9 ZooKeeperCluster (org.apache.whirr.service.zookeeper.ZooKeeperCluster)9 Test (org.junit.Test)8 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)7 Credentials (org.jclouds.domain.Credentials)7 ClusterController (org.apache.whirr.ClusterController)5 Properties (java.util.Properties)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 InstanceTemplate (org.apache.whirr.InstanceTemplate)4 ClusterActionEvent (org.apache.whirr.service.ClusterActionEvent)4 StatementBuilder (org.apache.whirr.service.jclouds.StatementBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 File (java.io.File)3 ExecutionException (java.util.concurrent.ExecutionException)3 Future (java.util.concurrent.Future)3