Search in sources :

Example 76 with ClusterSpec

use of org.apache.whirr.ClusterSpec 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 77 with ClusterSpec

use of org.apache.whirr.ClusterSpec 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)

Example 78 with ClusterSpec

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

the class BootstrapTemplateTest method testOverrideSpotPrice.

@Test
public void testOverrideSpotPrice() throws Exception {
    ClusterSpec clusterSpec = buildClusterSpecWith(ImmutableMap.of("whirr.instance-templates", "1 role1", "whirr.aws-ec2-spot-price", "0.1", "whirr.templates.role1.aws-ec2-spot-price", "0.3"));
    assertSpotPriceIs(clusterSpec, "role1", 0.3f);
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 79 with ClusterSpec

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

the class BootstrapTemplateTest method testSetGlobalSpotPrice.

@Test
public void testSetGlobalSpotPrice() throws Exception {
    ClusterSpec clusterSpec = buildClusterSpecWith(ImmutableMap.of("whirr.instance-templates", "1 role1", "whirr.aws-ec2-spot-price", "0.3"));
    assertSpotPriceIs(clusterSpec, "role1", 0.3f);
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 80 with ClusterSpec

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

the class RunScript method doExecute.

@Override
protected Object doExecute() throws Exception {
    RunScriptCommand command = new RunScriptCommand(clusterControllerFactory);
    ClusterSpec clusterSpec = getClusterSpec();
    if (clusterSpec != null) {
        command.run(System.in, System.out, System.err, clusterSpec, instances.toArray(new String[instances.size()]), roles.toArray(new String[roles.size()]), script);
    }
    return null;
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) RunScriptCommand(org.apache.whirr.cli.command.RunScriptCommand)

Aggregations

ClusterSpec (org.apache.whirr.ClusterSpec)98 Configuration (org.apache.commons.configuration.Configuration)39 Cluster (org.apache.whirr.Cluster)35 Test (org.junit.Test)34 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)16 Instance (org.apache.whirr.Cluster.Instance)14 ClusterController (org.apache.whirr.ClusterController)10 InetAddress (java.net.InetAddress)9 DryRun (org.apache.whirr.service.DryRunModule.DryRun)9 OptionSet (joptsimple.OptionSet)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 ZooKeeperCluster (org.apache.whirr.service.zookeeper.ZooKeeperCluster)8 IOException (java.io.IOException)7 ComputeService (org.jclouds.compute.ComputeService)7 File (java.io.File)6 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)6 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)6 Set (java.util.Set)5 Stack (java.util.Stack)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5