Search in sources :

Example 11 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project whirr by apache.

the class ScriptBasedClusterAction method runScripts.

protected void runScripts(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws InterruptedException, IOException {
    final String phaseName = getAction();
    final Collection<Future<ExecResponse>> futures = Sets.newHashSet();
    final ClusterSpec clusterSpec = eventMap.values().iterator().next().getClusterSpec();
    final RunScriptOptions options = overrideLoginCredentials(LoginCredentials.builder().user(clusterSpec.getClusterUser()).privateKey(clusterSpec.getPrivateKey()).build());
    for (Map.Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
        if (shouldIgnoreInstanceTemplate(entry.getKey())) {
            // skip if not in the target
            continue;
        }
        Cluster cluster = entry.getValue().getCluster();
        StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
        if (statementBuilder.isEmpty()) {
            // skip execution if we have an empty list
            continue;
        }
        Set<Instance> instances = cluster.getInstancesMatching(Predicates.<Instance>and(onlyRolesIn(entry.getKey().getRoles()), not(instanceIsNotInTarget())));
        LOG.info("Starting to run scripts on cluster for phase {} " + "on instances: {}", phaseName, asString(instances));
        for (Instance instance : instances) {
            futures.add(runStatementOnInstanceInCluster(statementBuilder, instance, clusterSpec, options));
        }
    }
    for (Future<ExecResponse> future : futures) {
        try {
            future.get();
        } catch (ExecutionException e) {
            throw new IOException(e.getCause());
        }
    }
    LOG.info("Finished running {} phase scripts on all cluster instances", phaseName);
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) Instance(org.apache.whirr.Cluster.Instance) ExecResponse(org.jclouds.compute.domain.ExecResponse) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterActionEvent(org.apache.whirr.service.ClusterActionEvent) IOException(java.io.IOException) StatementBuilder(org.apache.whirr.service.jclouds.StatementBuilder) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Future(java.util.concurrent.Future) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) InstanceTemplate(org.apache.whirr.InstanceTemplate)

Example 12 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project whirr by apache.

the class Cdh3HadoopServiceTest method testVersion.

@Test
public void testVersion() throws Exception {
    Statement checkVersion = Statements.exec("ls /etc/alternatives/hadoop-lib");
    Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, ALL, checkVersion);
    printResponses(checkVersion, responses);
    assertResponsesContain(responses, checkVersion, "cdh3");
}
Also used : ExecResponse(org.jclouds.compute.domain.ExecResponse) Statement(org.jclouds.scriptbuilder.domain.Statement) Test(org.junit.Test)

Example 13 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project whirr by apache.

the class PhaseExecutionBarrierTest method testNoRemoteExecutionOverlap.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testNoRemoteExecutionOverlap() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    ClusterController controller = (new ClusterControllerFactory()).create(spec.getServiceName());
    try {
        controller.launchCluster(spec);
        Map<? extends NodeMetadata, ExecResponse> responseMap = controller.runScriptOnNodesMatching(spec, Predicates.<NodeMetadata>alwaysTrue(), exec("cat /tmp/bootstrap-start /tmp/bootstrap-end /tmp/configure-start"));
        ExecResponse response = Iterables.get(responseMap.values(), 0);
        LOG.info("Got response: {}", response);
        String[] parts = Strings.split(response.getOutput(), '\n');
        int bootstrapStart = parseInt(deleteWhitespace(parts[0]));
        int bootstrapEnd = parseInt(deleteWhitespace(parts[1]));
        int configureStart = parseInt(deleteWhitespace(parts[2]));
        assertTrue(bootstrapStart < bootstrapEnd);
        assertTrue(bootstrapEnd < configureStart);
    } finally {
        controller.destroyCluster(spec);
    }
    assertNoOverlapOnLocalMachine();
}
Also used : ClusterController(org.apache.whirr.ClusterController) ExecResponse(org.jclouds.compute.domain.ExecResponse) ClusterSpec(org.apache.whirr.ClusterSpec) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) Test(org.junit.Test)

Example 14 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project whirr by apache.

the class ChefServiceTest method testChefRunRecipesFromProvidedCookbooks.

/**
 * Test the execution of recipes (one with attribs and one with non-default
 * recipe) from the provided recipes dowloaded from opscode's git repo.
 *
 * @throws Exception
 */
@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testChefRunRecipesFromProvidedCookbooks() throws Exception {
    Recipe java = new Recipe("java");
    java.attribs.put("install_flavor", "openjdk");
    // Recipes have to run directly against ComputeService as they need to be
    // ran as initscripts, a future version of ClusterController might avoid
    // taht.
    Map<? extends NodeMetadata, ExecResponse> responses = runRecipe(java);
    printResponses(java, responses);
    Statement stmt = Statements.exec("java -version");
    responses = controller.runScriptOnNodesMatching(clusterSpec, allNodes, stmt);
    assertResponsesContain(responses, stmt, "Runtime Environment");
    Recipe postgreSql = new Recipe("postgresql", "server");
    responses = runRecipe(postgreSql);
    printResponses(postgreSql, responses);
    stmt = Statements.exec("psql --version");
    responses = controller.runScriptOnNodesMatching(clusterSpec, allNodes, stmt);
    assertResponsesContain(responses, stmt, "PostgreSQL");
}
Also used : Recipe(org.apache.whirr.service.chef.Recipe) ExecResponse(org.jclouds.compute.domain.ExecResponse) Statement(org.jclouds.scriptbuilder.domain.Statement) Test(org.junit.Test)

Example 15 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project whirr by apache.

the class ChefServiceTest method testRecipesWereRanInServiceBootstrap.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testRecipesWereRanInServiceBootstrap() throws Exception {
    // and shoudl be installed by the main handlers
    Statement testAnt = Statements.exec("ant -version");
    Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, allNodes, testAnt);
    printResponses(testAnt, responses);
    assertResponsesContain(responses, testAnt, "Apache Ant");
    Statement testMaven = Statements.exec("mvn --version");
    responses = controller.runScriptOnNodesMatching(clusterSpec, allNodes, testMaven);
    printResponses(testMaven, responses);
    assertResponsesContain(responses, testMaven, "Apache Maven");
}
Also used : ExecResponse(org.jclouds.compute.domain.ExecResponse) Statement(org.jclouds.scriptbuilder.domain.Statement) Test(org.junit.Test)

Aggregations

ExecResponse (org.jclouds.compute.domain.ExecResponse)19 Test (org.junit.Test)8 Statement (org.jclouds.scriptbuilder.domain.Statement)7 RunScriptOptions (org.jclouds.compute.options.RunScriptOptions)6 IOException (java.io.IOException)5 Map (java.util.Map)4 Cluster (org.apache.whirr.Cluster)4 ComputeService (org.jclouds.compute.ComputeService)4 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)4 LoginCredentials (org.jclouds.domain.LoginCredentials)4 ClusterSpec (org.apache.whirr.ClusterSpec)3 RunNodesException (org.jclouds.compute.RunNodesException)3 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)2 ToRunScriptOptions (io.fabric8.service.jclouds.functions.ToRunScriptOptions)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 Instance (org.apache.whirr.Cluster.Instance)2