Search in sources :

Example 11 with ClusterControllerFactory

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

the class ZooKeeperServiceTest method setUp.

@Before
public void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    config.addConfiguration(new PropertiesConfiguration("whirr-zookeeper-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterControllerFactory().create(clusterSpec.getServiceName());
    cluster = controller.launchCluster(clusterSpec);
    hosts = ZooKeeperCluster.getHosts(cluster);
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) Before(org.junit.Before)

Example 12 with ClusterControllerFactory

use of org.apache.whirr.ClusterControllerFactory 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 13 with ClusterControllerFactory

use of org.apache.whirr.ClusterControllerFactory 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 14 with ClusterControllerFactory

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

the class AbstractClusterCommandTest method testCreateServerWithInvalidClusterControllerName.

/**
 * Ensure that an invalid service name uses the default (after logging a
 * warning).
 */
@Test
public void testCreateServerWithInvalidClusterControllerName() throws Exception {
    AbstractClusterCommand clusterCommand = new AbstractClusterCommand("name", "description", new ClusterControllerFactory()) {

        @Override
        public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
            return 0;
        }
    };
    // following should not fail
    clusterCommand.createClusterController("bar");
}
Also used : PrintStream(java.io.PrintStream) InputStream(java.io.InputStream) List(java.util.List) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) Test(org.junit.Test)

Aggregations

ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)14 Test (org.junit.Test)11 File (java.io.File)9 ClusterController (org.apache.whirr.ClusterController)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)6 ClusterSpec (org.apache.whirr.ClusterSpec)6 Configuration (org.apache.commons.configuration.Configuration)3 Cluster (org.apache.whirr.Cluster)3 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)3 Predicate (com.google.common.base.Predicate)2 InputStream (java.io.InputStream)2 PrintStream (java.io.PrintStream)2 List (java.util.List)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 ClusterStateStore (org.apache.whirr.state.ClusterStateStore)2 ClusterStateStoreFactory (org.apache.whirr.state.ClusterStateStoreFactory)2 MemoryClusterStateStore (org.apache.whirr.state.MemoryClusterStateStore)2 Before (org.junit.Before)2 OptionSet (joptsimple.OptionSet)1