Search in sources :

Example 31 with ClusterController

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

the class ListClusterCommand method run.

public int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec) throws Exception {
    ClusterStateStore stateStore = createClusterStateStore(clusterSpec);
    ClusterController controller = createClusterController(clusterSpec.getServiceName());
    for (Cluster.Instance instance : controller.getInstances(clusterSpec, stateStore)) {
        out.println(Joiner.on('\t').useForNull("-").join(instance.getId(), instance.getNodeMetadata().getImageId(), instance.getPublicIp(), instance.getPrivateIp(), instance.getNodeMetadata().getStatus(), instance.getNodeMetadata().getLocation().getId(), Joiner.on(",").join(instance.getRoles())));
    }
    return 0;
}
Also used : ClusterController(org.apache.whirr.ClusterController) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Cluster(org.apache.whirr.Cluster)

Example 32 with ClusterController

use of org.apache.whirr.ClusterController 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 33 with ClusterController

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

the class DryRunModuleTest method testExecuteOnlyBootstrapForNoop.

@Test
public void testExecuteOnlyBootstrapForNoop() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    config.setProperty("whirr.provider", "stub");
    config.setProperty("whirr.cluster-name", "stub-test");
    config.setProperty("whirr.instance-templates", "1 noop");
    config.setProperty("whirr.state-store", "memory");
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config);
    ClusterController controller = new ClusterController();
    DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec);
    dryRun.reset();
    controller.launchCluster(clusterSpec);
    controller.destroyCluster(clusterSpec);
    ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions();
    for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions.asMap().entrySet()) {
        assertSame("An incorrect number of scripts was executed in the node " + entry, entry.getValue().size(), 1);
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) Statement(org.jclouds.scriptbuilder.domain.Statement) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) DryRun(org.apache.whirr.service.DryRunModule.DryRun) Collection(java.util.Collection) ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 34 with ClusterController

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

the class HadoopClusterExample method main.

@Override
public int main(String[] args) throws Exception {
    if (!System.getenv().containsKey("AWS_ACCESS_KEY_ID")) {
        LOG.error("AWS_ACCESS_KEY_ID is undefined in the current environment");
        return -1;
    }
    if (!System.getenv().containsKey("AWS_SECRET_ACCESS_KEY")) {
        LOG.error("AWS_SECRET_ACCESS_KEY is undefined in the current environment");
        return -2;
    }
    /**
     * Start by loading cluster configuration file and creating a ClusterSpec object
     *
     * You can find the file in the resources folder.
     */
    ClusterSpec spec = new ClusterSpec(new PropertiesConfiguration("whirr-hadoop-example.properties"));
    /**
     * Create an instance of the generic cluster controller
     */
    ClusterControllerFactory factory = new ClusterControllerFactory();
    ClusterController controller = factory.create(spec.getServiceName());
    /**
     * Start the cluster as defined in the configuration file
     */
    HadoopProxy proxy = null;
    try {
        LOG.info("Starting cluster {}", spec.getClusterName());
        Cluster cluster = controller.launchCluster(spec);
        LOG.info("Starting local SOCKS proxy");
        proxy = new HadoopProxy(spec, cluster);
        proxy.start();
        /**
         * Obtain a Hadoop configuration object and wait for services to start
         */
        Configuration config = getHadoopConfiguration(cluster);
        JobConf job = new JobConf(config, HadoopClusterExample.class);
        JobClient client = new JobClient(job);
        waitToExitSafeMode(client);
        waitForTaskTrackers(client);
        /**
         * Run a simple job to show that the cluster is available for work.
         */
        runWordCountingJob(config);
    } finally {
        /**
         * Stop the proxy and terminate all the cluster instances.
         */
        if (proxy != null) {
            proxy.stop();
        }
        controller.destroyCluster(spec);
        return 0;
    }
}
Also used : ClusterController(org.apache.whirr.ClusterController) Configuration(org.apache.hadoop.conf.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Cluster(org.apache.whirr.Cluster) HadoopProxy(org.apache.whirr.service.hadoop.HadoopProxy) ClusterSpec(org.apache.whirr.ClusterSpec) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) JobConf(org.apache.hadoop.mapred.JobConf) JobClient(org.apache.hadoop.mapred.JobClient)

Example 35 with ClusterController

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

the class PhaseExecutionBarrierTest method testNoRemoteExecutionOverlap.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testNoRemoteExecutionOverlap() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    ClusterController controller = (new ClusterControllerFactory()).create(spec.getServiceName());
    try {
        controller.launchCluster(spec);
        Map<? extends NodeMetadata, ExecResponse> responseMap = controller.runScriptOnNodesMatching(spec, Predicates.<NodeMetadata>alwaysTrue(), exec("cat /tmp/bootstrap-start /tmp/bootstrap-end /tmp/configure-start"));
        ExecResponse response = Iterables.get(responseMap.values(), 0);
        LOG.info("Got response: {}", response);
        String[] parts = Strings.split(response.getOutput(), '\n');
        int bootstrapStart = parseInt(deleteWhitespace(parts[0]));
        int bootstrapEnd = parseInt(deleteWhitespace(parts[1]));
        int configureStart = parseInt(deleteWhitespace(parts[2]));
        assertTrue(bootstrapStart < bootstrapEnd);
        assertTrue(bootstrapEnd < configureStart);
    } finally {
        controller.destroyCluster(spec);
    }
    assertNoOverlapOnLocalMachine();
}
Also used : ClusterController(org.apache.whirr.ClusterController) ExecResponse(org.jclouds.compute.domain.ExecResponse) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) Test(org.junit.Test)

Aggregations

ClusterController (org.apache.whirr.ClusterController)42 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)23 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)22 Test (org.junit.Test)12 ClusterSpec (org.apache.whirr.ClusterSpec)10 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 Before (org.junit.Before)8 File (java.io.File)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)7 BeforeClass (org.junit.BeforeClass)7 Cluster (org.apache.whirr.Cluster)6 DryRun (org.apache.whirr.service.DryRunModule.DryRun)5 Collection (java.util.Collection)3 Configuration (org.apache.commons.configuration.Configuration)3 Configuration (org.apache.hadoop.conf.Configuration)3 JobClient (org.apache.hadoop.mapred.JobClient)3 JobConf (org.apache.hadoop.mapred.JobConf)3 ClusterStateStore (org.apache.whirr.state.ClusterStateStore)3