Search in sources :

Example 41 with Cluster

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

the class BlobClusterStateStoreTest method testStoreAndLoadState.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testStoreAndLoadState() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    try {
        spec.setStateStore("blob");
        spec.setStateStoreContainer(container);
        Cluster expected = createTestCluster(new String[] { "region/id1", "region/id2" }, new String[] { "role1", "role2" });
        BlobClusterStateStore store = new BlobClusterStateStore(spec);
        store.save(expected);
        /* load and check the stored state */
        Cluster stored = store.load();
        Cluster.Instance first = Iterables.getFirst(stored.getInstances(), null);
        assertNotNull(first);
        assertThat(first.getId(), is("region/id1"));
        assertThat(first.getRoles().contains("role1"), is(true));
        assertThat(stored.getInstances().size(), is(2));
        /* destroy stored state and check it no longer exists */
        store.destroy();
        expected = store.load();
        assertNull(expected);
    } finally {
        LOG.info("Removing temporary container '{}'", container);
        context.getBlobStore().deleteContainer(container);
    }
}
Also used : BlobClusterStateStore(org.apache.whirr.state.BlobClusterStateStore) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Test(org.junit.Test)

Example 42 with Cluster

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

the class BlobClusterStateStoreTest 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.newLinkedHashSet();
    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) Credentials(org.jclouds.domain.Credentials)

Example 43 with Cluster

use of org.apache.whirr.Cluster 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 44 with Cluster

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

the class UtilsTest method testPrintAccess.

@Test
public void testPrintAccess() {
    final Instance instance = mock(Instance.class);
    when(instance.getPublicIp()).thenReturn("test-public-ip");
    when(instance.getRoles()).thenReturn(ImmutableSet.of("test-role"));
    Cluster cluster = mock(Cluster.class);
    when(cluster.getInstances()).thenReturn(ImmutableSet.<Cluster.Instance>of(instance));
    ClusterSpec spec = mock(ClusterSpec.class);
    when(spec.getClusterUser()).thenReturn("test-identity");
    when(spec.getPrivateKeyFile()).thenReturn(new File("/test/key/path"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    Utils.printSSHConnectionDetails(ps, spec, cluster, 20);
    assertEquals("The ssh command did not match", EXPECTED_SSH_COMMAND, new String(baos.toByteArray()));
}
Also used : PrintStream(java.io.PrintStream) Instance(org.apache.whirr.Cluster.Instance) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 45 with Cluster

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

the class ElasticSearchHandler method beforeConfigure.

@Override
protected void beforeConfigure(ClusterActionEvent event) throws IOException {
    ClusterSpec spec = event.getClusterSpec();
    Cluster cluster = event.getCluster();
    event.getFirewallManager().addRule(Rule.create().destination(cluster.getInstancesMatching(role(ROLE))).port(HTTP_CLIENT_PORT));
    handleFirewallRules(event);
    Configuration config = ElasticSearchConfigurationBuilder.buildConfig(spec, cluster);
    addStatement(event, call("retry_helpers"));
    addStatement(event, ElasticSearchConfigurationBuilder.build("/tmp/elasticsearch.yml", config));
    addStatement(event, call("configure_elasticsearch", config.getStringArray("es.plugins")));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) 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