Search in sources :

Example 1 with ClusterControllerFactory

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

the class AbstractClusterCommandTest method testOverrides.

@Test
public void testOverrides() 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;
        }
    };
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    OptionSet optionSet = clusterCommand.parser.parse("--quiet", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath());
    ClusterSpec clusterSpec = clusterCommand.getClusterSpec(optionSet);
    assertThat(optionSet.has("quiet"), is(true));
    assertThat(clusterSpec.isQuiet(), is(true));
    assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
    assertThat(clusterSpec.getClusterName(), is("test-cluster"));
    optionSet = clusterCommand.parser.parse("--quiet", "true", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath());
    clusterSpec = clusterCommand.getClusterSpec(optionSet);
    assertThat(optionSet.has("quiet"), is(true));
    assertThat(clusterSpec.isQuiet(), is(true));
    assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
    assertThat(clusterSpec.getClusterName(), is("test-cluster"));
    optionSet = clusterCommand.parser.parse("--quiet", "false", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath());
    clusterSpec = clusterCommand.getClusterSpec(optionSet);
    assertThat(optionSet.has("quiet"), is(true));
    assertThat(clusterSpec.isQuiet(), is(false));
    assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
    assertThat(clusterSpec.getClusterName(), is("test-cluster"));
    optionSet = clusterCommand.parser.parse("--quiet", "some-value", "--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath());
    clusterSpec = clusterCommand.getClusterSpec(optionSet);
    assertThat(optionSet.has("quiet"), is(true));
    assertThat(clusterSpec.isQuiet(), is(false));
    assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
    assertThat(clusterSpec.getClusterName(), is("test-cluster"));
    optionSet = clusterCommand.parser.parse("--service-name", "overridden-test-service", "--config", "whirr-override-test.properties", "--private-key-file", keys.get("private").getAbsolutePath());
    clusterSpec = clusterCommand.getClusterSpec(optionSet);
    assertThat(optionSet.has("quiet"), is(false));
    assertThat(clusterSpec.isQuiet(), is(false));
    assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
    assertThat(clusterSpec.getClusterName(), is("test-cluster"));
}
Also used : PrintStream(java.io.PrintStream) InputStream(java.io.InputStream) List(java.util.List) ClusterSpec(org.apache.whirr.ClusterSpec) OptionSet(joptsimple.OptionSet) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 2 with ClusterControllerFactory

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

the class GangliaServiceTest 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-ganglia-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterControllerFactory().create(clusterSpec.getServiceName());
    cluster = controller.launchCluster(clusterSpec);
}
Also used : CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) Before(org.junit.Before)

Example 3 with ClusterControllerFactory

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

the class DestroyClusterCommandTest method testAllOptions.

@Test
public void testAllOptions() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    DestroyClusterCommand command = new DestroyClusterCommand(factory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--instance-templates", "1 noop", "--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));
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.version", "version-string");
    conf.addProperty("whirr.instance-templates", "1 noop");
    ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf);
    expectedClusterSpec.setServiceName("test-service");
    expectedClusterSpec.setProvider("rackspace");
    expectedClusterSpec.setIdentity("myusername");
    expectedClusterSpec.setCredential("mypassword");
    expectedClusterSpec.setClusterName("test-cluster");
    expectedClusterSpec.setPrivateKey(keys.get("private"));
    expectedClusterSpec.setPublicKey(keys.get("public"));
    verify(factory).create("test-service");
    verify(controller).destroyCluster(expectedClusterSpec);
}
Also used : ClusterController(org.apache.whirr.ClusterController) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) 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 4 with ClusterControllerFactory

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

the class ListClusterCommandTest method testAllOptions.

@Test
public void testAllOptions() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    NodeMetadata node1 = new NodeMetadataBuilder().name("name1").ids("id1").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id1").description("location-desc1").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.1")).privateAddresses(Lists.newArrayList("127.0.0.1")).build();
    NodeMetadata node2 = new NodeMetadataBuilder().name("name2").ids("id2").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id2").description("location-desc2").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.2")).privateAddresses(Lists.newArrayList("127.0.0.2")).build();
    when(controller.getNodes((ClusterSpec) any())).thenReturn((Set) Sets.newLinkedHashSet(Lists.newArrayList(node1, node2)));
    when(controller.getInstances((ClusterSpec) any(), (ClusterStateStore) any())).thenCallRealMethod();
    ClusterStateStore memStore = new MemoryClusterStateStore();
    memStore.save(createTestCluster(new String[] { "id1", "id2" }, new String[] { "role1", "role2" }));
    ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class);
    when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore);
    ListClusterCommand command = new ListClusterCommand(factory, stateStoreFactory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--instance-templates", "1 noop", "--service-name", "test-service", "--cluster-name", "test-cluster", "--identity", "myusername", "--quiet", "--private-key-file", keys.get("private").getAbsolutePath()));
    assertThat(rc, is(0));
    assertThat(outBytes.toString(), is("id1\timage-id\t127.0.0.1\t127.0.0.1\tRUNNING\tlocation-id1\trole1\n" + "id2\timage-id\t127.0.0.2\t127.0.0.2\tRUNNING\tlocation-id2\trole2\n"));
    verify(factory).create("test-service");
}
Also used : MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Matchers.containsString(org.hamcrest.Matchers.containsString) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) NodeMetadataBuilder(org.jclouds.compute.domain.NodeMetadataBuilder) ClusterController(org.apache.whirr.ClusterController) MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStoreFactory(org.apache.whirr.state.ClusterStateStoreFactory) LocationBuilder(org.jclouds.domain.LocationBuilder) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Example 5 with ClusterControllerFactory

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

the class RunScriptCommandTest method testRunScriptByRole.

@Test
public void testRunScriptByRole() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    ClusterStateStore memStore = new MemoryClusterStateStore();
    memStore.save(createTestCluster(new String[] { "reg/A", "reg/B" }, new String[] { "A", "B" }));
    ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class);
    when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore);
    RunScriptCommand command = new RunScriptCommand(factory, stateStoreFactory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, System.err, Lists.newArrayList("--instance-templates", "1 noop", "--script", "/dev/null", "--roles", "A", "--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("reg/A"));
    assertThat(predicate.getValue().toString(), is(expected.toString()));
}
Also used : MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Matchers.containsString(org.hamcrest.Matchers.containsString) Predicate(com.google.common.base.Predicate) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStoreFactory(org.apache.whirr.state.ClusterStateStoreFactory) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) 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