Search in sources :

Example 56 with ClusterSpec

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

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

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

the class RoleLifecycleCommand method run.

@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
    OptionSet optionSet = parser.parse(args.toArray(new String[args.size()]));
    if (!optionSet.nonOptionArguments().isEmpty()) {
        printUsage(err);
        return -1;
    }
    try {
        ClusterSpec clusterSpec = getClusterSpec(optionSet);
        printProviderInfo(out, err, clusterSpec, optionSet);
        return runLifecycleStep(clusterSpec, createClusterController(clusterSpec.getServiceName()), optionSet);
    } catch (IllegalArgumentException e) {
        printErrorAndHelpHint(err, e);
        return -1;
    }
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) OptionSet(joptsimple.OptionSet)

Example 59 with ClusterSpec

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

the class CleanupClusterCommand method run.

@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
    OptionSet optionSet = parser.parse(args.toArray(new String[args.size()]));
    if (!optionSet.nonOptionArguments().isEmpty()) {
        printUsage(err);
        return -1;
    }
    try {
        ClusterSpec clusterSpec = getClusterSpec(optionSet);
        printProviderInfo(out, err, clusterSpec, optionSet);
        ClusterController controller = createClusterController(clusterSpec.getServiceName());
        controller.cleanupCluster(clusterSpec);
        return 0;
    } catch (IllegalArgumentException e) {
        printErrorAndHelpHint(err, e);
        return -1;
    }
}
Also used : ClusterController(org.apache.whirr.ClusterController) ClusterSpec(org.apache.whirr.ClusterSpec) OptionSet(joptsimple.OptionSet)

Example 60 with ClusterSpec

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

the class DestroyClusterCommand method run.

@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
    OptionSet optionSet = parser.parse(args.toArray(new String[args.size()]));
    if (!optionSet.nonOptionArguments().isEmpty()) {
        printUsage(err);
        return -1;
    }
    try {
        ClusterSpec clusterSpec = getClusterSpec(optionSet);
        printProviderInfo(out, err, clusterSpec, optionSet);
        return run(in, out, err, clusterSpec);
    } catch (IllegalArgumentException e) {
        printErrorAndHelpHint(err, e);
        return -1;
    }
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) OptionSet(joptsimple.OptionSet)

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