Search in sources :

Example 81 with ClusterSpec

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

the class WhirrCommandSupport method getClusterSpec.

/**
 * Returns the {@link ClusterSpec}
 *
 * @return
 * @throws Exception
 */
protected ClusterSpec getClusterSpec() throws Exception {
    ClusterSpec clusterSpec = null;
    if (pid != null || fileName != null) {
        PropertiesConfiguration properties = getConfiguration(pid, fileName);
        clusterSpec = new ClusterSpec(properties);
    } else {
        clusterSpec = new ClusterSpec();
    }
    if (name != null) {
        clusterSpec.setContextName(name);
    }
    if (provider != null) {
        clusterSpec.setProvider(provider);
    }
    if (endpoint != null) {
        clusterSpec.setEndpoint(endpoint);
    }
    if (templates != null) {
        clusterSpec.setInstanceTemplates(getTemplate(templates, imageId, hardwareId));
    }
    if (privateKey != null) {
        clusterSpec.setPrivateKey(privateKey);
    }
    if (clusterName != null) {
        clusterSpec.setClusterName(clusterName);
    }
    return clusterSpec;
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 82 with ClusterSpec

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

the class CassandraClusterActionHandler method beforeBootstrap.

@Override
protected void beforeBootstrap(ClusterActionEvent event) throws IOException {
    ClusterSpec clusterSpec = event.getClusterSpec();
    Configuration conf = clusterSpec.getConfiguration();
    addStatement(event, call("retry_helpers"));
    addStatement(event, call("install_tarball"));
    addStatement(event, call("install_service"));
    addStatement(event, call(getInstallFunction(conf, "java", "install_openjdk")));
    Configuration config = clusterSpec.getConfiguration();
    String tarball = prepareRemoteFileUrl(event, config.getString(BIN_TARBALL, null));
    String major = config.getString(MAJOR_VERSION, null);
    if (tarball != null && major != null) {
        addStatement(event, call("install_cassandra", major, tarball));
    } else {
        addStatement(event, call("install_cassandra"));
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ClusterSpec(org.apache.whirr.ClusterSpec)

Example 83 with ClusterSpec

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

the class BaseServiceDryRunTest method testBootstrapAndConfigure.

/**
 * Tests that a simple cluster is correctly loaded and executed.
 */
@Test
public void testBootstrapAndConfigure() throws Exception {
    ClusterSpec cookbookWithDefaultRecipe = newClusterSpecForProperties(ImmutableMap.of("whirr.instance-templates", "1 " + Joiner.on("+").join(getInstanceRoles())));
    DryRun dryRun = launchWithClusterSpec(cookbookWithDefaultRecipe);
    assertScriptPredicateOnPhase(dryRun, "bootstrap", bootstrapPredicate());
    assertScriptPredicateOnPhase(dryRun, "configure", configurePredicate());
}
Also used : DryRun(org.apache.whirr.service.DryRunModule.DryRun) ClusterSpec(org.apache.whirr.ClusterSpec) Test(org.junit.Test)

Example 84 with ClusterSpec

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

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

the class DestroyInstance method doExecute.

@Override
protected Object doExecute() throws Exception {
    DestroyInstanceCommand command = new DestroyInstanceCommand(clusterControllerFactory);
    ClusterSpec clusterSpec = getClusterSpec();
    if (clusterSpec != null) {
        command.run(System.in, System.out, System.err, clusterSpec, instance);
    }
    return null;
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) DestroyInstanceCommand(org.apache.whirr.cli.command.DestroyInstanceCommand)

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