Search in sources :

Example 6 with ClusterControllerFactory

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

the class DestroyInstanceCommandTest method testDestroyInstanceById.

@Test
public void testDestroyInstanceById() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    DestroyInstanceCommand command = new DestroyInstanceCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--instance-templates", "1 noop", "--instance-id", "region/instanceid", "--service-name", "test-service", "--cluster-name", "test-cluster", "--provider", "rackspace", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string"));
    assertThat(rc, is(0));
    verify(controller).destroyInstance((ClusterSpec) any(), eq("region/instanceid"));
}
Also used : ClusterController(org.apache.whirr.ClusterController) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 7 with ClusterControllerFactory

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

the class LaunchClusterCommandTest method testAllOptions.

@Test
public void testAllOptions() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    Cluster cluster = mock(Cluster.class);
    when(factory.create((String) any())).thenReturn(controller);
    when(controller.launchCluster((ClusterSpec) any())).thenReturn(cluster);
    LaunchClusterCommand command = new LaunchClusterCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--service-name", "test-service", "--cluster-name", "test-cluster", "--instance-templates", "1 role1+role2,2 role3", "--provider", "rackspace", "--endpoint", "http://endpoint", "--blobstore-endpoint", "http://blobstore-endpoint", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string"));
    assertThat(rc, is(0));
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.version", "version-string");
    ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf);
    expectedClusterSpec.setInstanceTemplates(Lists.newArrayList(InstanceTemplate.builder().numberOfInstance(1).roles("role1", "role2").build(), InstanceTemplate.builder().numberOfInstance(2).roles("role3").build()));
    expectedClusterSpec.setServiceName("test-service");
    expectedClusterSpec.setProvider("rackspace");
    expectedClusterSpec.setEndpoint("http://endpoint");
    expectedClusterSpec.setIdentity("myusername");
    expectedClusterSpec.setCredential("mypassword");
    expectedClusterSpec.setBlobStoreEndpoint("http://blobstore-endpoint");
    expectedClusterSpec.setClusterName("test-cluster");
    expectedClusterSpec.setPrivateKey(keys.get("private"));
    expectedClusterSpec.setPublicKey(keys.get("public"));
    verify(factory).create("test-service");
    verify(controller).launchCluster(expectedClusterSpec);
    assertThat(outBytes.toString(), containsString("Started cluster of 0 instances"));
}
Also used : ClusterController(org.apache.whirr.ClusterController) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Cluster(org.apache.whirr.Cluster) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 8 with ClusterControllerFactory

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

the class LaunchClusterCommandTest method testLaunchClusterUsingDryRun.

@Test
public void testLaunchClusterUsingDryRun() throws Exception {
    ClusterControllerFactory factory = new ClusterControllerFactory();
    TestLaunchClusterCommand launchCluster = new TestLaunchClusterCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = launchCluster.run(null, out, err, Lists.<String>newArrayList("--cluster-name", "test-cluster-launch", "--state-store", "none", "--instance-templates", "1 zookeeper+cassandra, 1 zookeeper+elasticsearch", "--provider", "stub", "--identity", "dummy", "--private-key-file", keys.get("private").getAbsolutePath()));
    MatcherAssert.assertThat(rc, is(0));
    assertExecutedPhases(launchCluster.dryRun, "bootstrap", "configure", "start");
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 9 with ClusterControllerFactory

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

the class LaunchClusterCommandTest method testMaxPercentFailure.

@Test
public void testMaxPercentFailure() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    Cluster cluster = mock(Cluster.class);
    when(factory.create((String) any())).thenReturn(controller);
    when(controller.launchCluster((ClusterSpec) any())).thenReturn(cluster);
    LaunchClusterCommand command = new LaunchClusterCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--service-name", "hadoop", "--cluster-name", "test-cluster", "--instance-templates", "1 hadoop-namenode+hadoop-jobtracker,3 hadoop-datanode+hadoop-tasktracker", "--instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker", "--provider", "aws-ec2", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string"));
    assertThat(rc, is(0));
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.provider", "aws-ec2");
    conf.addProperty("whirr.version", "version-string");
    conf.addProperty("whirr.instance-templates-max-percent-failure", "60 hadoop-datanode+hadoop-tasktracker");
    ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf);
    expectedClusterSpec.setInstanceTemplates(Lists.newArrayList(InstanceTemplate.builder().numberOfInstance(1).minNumberOfInstances(1).roles("hadoop-namenode", "hadoop-jobtracker").build(), InstanceTemplate.builder().numberOfInstance(3).minNumberOfInstances(2).roles("hadoop-datanode", "hadoop-tasktracker").build()));
    expectedClusterSpec.setServiceName("hadoop");
    expectedClusterSpec.setIdentity("myusername");
    expectedClusterSpec.setCredential("mypassword");
    expectedClusterSpec.setClusterName("test-cluster");
    expectedClusterSpec.setPrivateKey(keys.get("private"));
    expectedClusterSpec.setPublicKey(keys.get("public"));
    verify(factory).create("hadoop");
    verify(controller).launchCluster(expectedClusterSpec);
    assertThat(outBytes.toString(), containsString("Started cluster of 0 instances"));
}
Also used : ClusterController(org.apache.whirr.ClusterController) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Cluster(org.apache.whirr.Cluster) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 10 with ClusterControllerFactory

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

the class RunScriptCommandTest method testRunScriptByInstanceId.

@Test
public void testRunScriptByInstanceId() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    RunScriptCommand command = new RunScriptCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, System.err, Lists.newArrayList("--script", "/dev/null", "--instance-templates", "1 noop", "--instances", "A,B", "--cluster-name", "test-cluster", "--provider", "provider", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath()));
    assertThat(rc, is(0));
    ArgumentCaptor<Predicate> predicate = ArgumentCaptor.forClass(Predicate.class);
    verify(controller).runScriptOnNodesMatching((ClusterSpec) any(), predicate.capture(), (Statement) any());
    // check predicate equality by using the object string representation
    Predicate<NodeMetadata> expected = Predicates.and(Predicates.<NodeMetadata>alwaysTrue(), withIds("A", "B"));
    assertThat(predicate.getValue().toString(), is(expected.toString()));
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Predicate(com.google.common.base.Predicate) 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