Search in sources :

Example 1 with StatementOnNode

use of org.jclouds.compute.events.StatementOnNode in project whirr by apache.

the class DryRunModuleTest method testNoInitScriptsAfterConfigurationStartedAndNoConfigScriptsAfterDestroy.

/**
 * Simple test that tests dry run module and at the same time enforces clear
 * separation of script execution phases.
 */
@Test
public void testNoInitScriptsAfterConfigurationStartedAndNoConfigScriptsAfterDestroy() throws ConfigurationException, JSchException, IOException, InterruptedException {
    final List<String> expectedExecutionOrder = ImmutableList.of("bootstrap", "configure", "start", "destroy");
    CompositeConfiguration config = new CompositeConfiguration();
    config.setProperty("whirr.provider", "stub");
    config.setProperty("whirr.cluster-name", "stub-test");
    config.setProperty("whirr.instance-templates", "10 noop+noop3,10 noop2+noop,10 noop3+noop2");
    config.setProperty("whirr.state-store", "memory");
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config);
    ClusterController controller = new ClusterController();
    DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec);
    dryRun.reset();
    controller.launchCluster(clusterSpec);
    controller.destroyCluster(clusterSpec);
    ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions();
    List<StatementOnNode> totalExecutions = dryRun.getTotallyOrderedExecutions();
    for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions.asMap().entrySet()) {
        assertSame("An incorrect number of scripts was executed in the node: " + entry.getValue(), entry.getValue().size(), expectedExecutionOrder.size());
        List<Statement> asList = Lists.newArrayList(entry.getValue());
        int count = 0;
        for (String phase : expectedExecutionOrder) {
            String scriptName = getScriptName(asList.get(count));
            assertTrue("The '" + phase + "' script was executed in the wrong order, found: " + scriptName, scriptName.startsWith(phase));
            count += 1;
        }
    }
    // This tests the barrier by making sure that once a configure
    // script is executed no more setup scripts are executed
    Stack<String> executedPhases = new Stack<String>();
    for (StatementOnNode script : totalExecutions) {
        String[] parts = getScriptName(script.getStatement()).split("-");
        if ((!executedPhases.empty() && !executedPhases.peek().equals(parts[0])) || executedPhases.empty()) {
            executedPhases.push(parts[0]);
        }
    }
    // Assert that all scripts executed in the right order with no overlaps
    assertEquals(expectedExecutionOrder.size(), executedPhases.size());
    for (String phaseName : Lists.reverse(expectedExecutionOrder)) {
        assertEquals(executedPhases.pop(), phaseName);
    }
}
Also used : Statement(org.jclouds.scriptbuilder.domain.Statement) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) DryRun(org.apache.whirr.service.DryRunModule.DryRun) ClusterSpec(org.apache.whirr.ClusterSpec) StatementOnNode(org.jclouds.compute.events.StatementOnNode) Stack(java.util.Stack) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ClusterController(org.apache.whirr.ClusterController) Collection(java.util.Collection) Test(org.junit.Test)

Example 2 with StatementOnNode

use of org.jclouds.compute.events.StatementOnNode in project whirr by apache.

the class ScriptBasedClusterActionTest method testActionIsExecutedOnAllRelevantNodes.

@Test
public void testActionIsExecutedOnAllRelevantNodes() throws Exception {
    T action = newClusterActionInstance(EMPTYSET, EMPTYSET);
    DryRun dryRun = getDryRunForAction(action).reset();
    action.execute(clusterSpec, cluster);
    List<StatementOnNode> executions = dryRun.getTotallyOrderedExecutions();
    // only 2 out of 3 because one instance has only noop
    assertThat(executions.size(), is(2));
}
Also used : DryRun(org.apache.whirr.service.DryRunModule.DryRun) StatementOnNode(org.jclouds.compute.events.StatementOnNode) Test(org.junit.Test)

Example 3 with StatementOnNode

use of org.jclouds.compute.events.StatementOnNode in project whirr by apache.

the class ScriptBasedClusterActionTest method testEmptyInstanceTemplates.

@Test(expected = IllegalArgumentException.class)
public void testEmptyInstanceTemplates() throws Exception {
    T action = newClusterActionInstance(EMPTYSET, EMPTYSET);
    DryRun dryRun = getDryRunForAction(action).reset();
    ClusterSpec tempSpec = ClusterSpec.withTemporaryKeys();
    tempSpec.setClusterName("test-cluster-for-script-exection");
    tempSpec.setProvider("stub");
    tempSpec.setIdentity("dummy");
    tempSpec.setStateStore("none");
    ClusterController controller = new ClusterController();
    Cluster tempCluster = controller.launchCluster(tempSpec);
    action.execute(tempSpec, tempCluster);
    List<StatementOnNode> executions = dryRun.getTotallyOrderedExecutions();
}
Also used : ClusterController(org.apache.whirr.ClusterController) DryRun(org.apache.whirr.service.DryRunModule.DryRun) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) StatementOnNode(org.jclouds.compute.events.StatementOnNode) Test(org.junit.Test)

Example 4 with StatementOnNode

use of org.jclouds.compute.events.StatementOnNode in project whirr by apache.

the class ScriptBasedClusterActionTest method testFilterScriptExecutionByRole.

@Test
public void testFilterScriptExecutionByRole() throws Exception {
    String instanceId = getInstaceForRole(cluster, "noop2").getId();
    T action = newClusterActionInstance(ImmutableSet.of("noop2"), EMPTYSET);
    DryRun dryRun = getDryRunForAction(action).reset();
    action.execute(clusterSpec, cluster);
    List<StatementOnNode> executions = dryRun.getTotallyOrderedExecutions();
    assertThat(executions.size(), is(1));
    assertHasRole(executions.get(0), cluster, "noop2");
    assertEquals(executions.get(0).getNode().getId(), instanceId);
    assertAnyStatementContains(dryRun, "noop2-" + getActionName());
    assertNoStatementContains(dryRun, "noop1-" + getActionName(), "noop3-" + getActionName());
}
Also used : DryRun(org.apache.whirr.service.DryRunModule.DryRun) StatementOnNode(org.jclouds.compute.events.StatementOnNode) Test(org.junit.Test)

Example 5 with StatementOnNode

use of org.jclouds.compute.events.StatementOnNode in project whirr by apache.

the class ScriptBasedClusterActionTest method assertAnyStatementContains.

private void assertAnyStatementContains(DryRun dryRun, String... values) {
    Set<String> toCheck = newHashSet(values);
    for (StatementOnNode node : dryRun.getTotallyOrderedExecutions()) {
        String statement = node.getStatement().render(OsFamily.UNIX);
        for (String term : ImmutableSet.copyOf(toCheck)) {
            if (statement.contains(term)) {
                toCheck.remove(term);
            }
        }
    }
    assertTrue("Unable to find the following terms in any statement: " + toCheck.toString(), toCheck.size() == 0);
}
Also used : StatementOnNode(org.jclouds.compute.events.StatementOnNode)

Aggregations

StatementOnNode (org.jclouds.compute.events.StatementOnNode)9 DryRun (org.apache.whirr.service.DryRunModule.DryRun)7 Test (org.junit.Test)7 ClusterController (org.apache.whirr.ClusterController)2 ClusterSpec (org.apache.whirr.ClusterSpec)2 Collection (java.util.Collection)1 Stack (java.util.Stack)1 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)1 Cluster (org.apache.whirr.Cluster)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 Statement (org.jclouds.scriptbuilder.domain.Statement)1