Search in sources :

Example 16 with ExecResponse

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

the class ChefServiceTest method testChefRunRecipeFromURL.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testChefRunRecipeFromURL() throws Exception {
    // As chef will be mostly used indirectly in other services
    // this test tests chef's ability to run a recipe, specifically to
    // install nginx.
    Recipe nginx = new Recipe("nginx", null, "http://s3.amazonaws.com/opscode-community/cookbook_versions/tarballs/529/original/nginx.tgz");
    Map<? extends NodeMetadata, ExecResponse> responses = runRecipe(nginx);
    printResponses(nginx, responses);
    HttpClient client = new HttpClient();
    final GetMethod getIndex = new GetMethod(String.format("http://%s", responses.keySet().iterator().next().getPublicAddresses().iterator().next()));
    assertTrue("Could not connect with nginx server", retry(new Predicate<HttpClient>() {

        @Override
        public boolean apply(HttpClient input) {
            try {
                int statusCode = input.executeMethod(getIndex);
                assertEquals("Status code should be 200", HttpStatus.SC_OK, statusCode);
                return true;
            } catch (Exception e) {
                return false;
            }
        }
    }, 10, 1, TimeUnit.SECONDS).apply(client));
    String indexPageHTML = getIndex.getResponseBodyAsString();
    assertTrue("The string 'nginx' should appear on the index page", indexPageHTML.contains("nginx"));
}
Also used : Recipe(org.apache.whirr.service.chef.Recipe) ExecResponse(org.jclouds.compute.domain.ExecResponse) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) RunScriptOnNodesException(org.jclouds.compute.RunScriptOnNodesException) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with ExecResponse

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

the class PigServiceTest method testPigBin.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testPigBin() throws Exception {
    Statement binPig = Statements.exec(". /etc/profile && pig -e fs -ls /");
    Cluster.Instance pigInstance = findPigInstance();
    Predicate<NodeMetadata> pigClientRole = and(alwaysTrue(), withIds(pigInstance.getId()));
    Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, pigClientRole, binPig);
    LOG.info("Responses for Statement: " + binPig);
    for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses.entrySet()) {
        LOG.info("Node[" + entry.getKey().getId() + "]: " + entry.getValue());
    }
    assertResponsesContain(responses, binPig, "/hadoop");
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ExecResponse(org.jclouds.compute.domain.ExecResponse) Statement(org.jclouds.scriptbuilder.domain.Statement) Cluster(org.apache.whirr.Cluster) Map(java.util.Map) Test(org.junit.Test)

Example 18 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project legacy-jclouds-examples by jclouds.

the class CreateVolumeAndAttach method mountVolume.

private void mountVolume(NodeMetadata node) {
    System.out.println("Mount Volume and Create Filesystem");
    String script = new ScriptBuilder().addStatement(exec("mkfs -t ext4 /dev/xvdd")).addStatement(exec("mount /dev/xvdd /mnt")).render(OsFamily.UNIX);
    RunScriptOptions options = RunScriptOptions.Builder.blockOnComplete(true).overrideLoginPassword(Constants.PASSWORD);
    ExecResponse response = compute.runScriptOnNode(node.getId(), script, options);
    if (response.getExitStatus() == 0) {
        System.out.println("  Exit Status: " + response.getExitStatus());
    } else {
        System.out.println("  Error: " + response.getOutput());
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ExecResponse(org.jclouds.compute.domain.ExecResponse) ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder)

Example 19 with ExecResponse

use of org.jclouds.compute.domain.ExecResponse in project legacy-jclouds-examples by jclouds.

the class DetachVolume method unmountVolume.

/**
 * Make sure you've unmounted the volume first. Failure to do so could result in failure or data loss.
 */
private void unmountVolume(VolumeAttachment volumeAttachment) {
    System.out.println("Unmount Volume");
    String script = new ScriptBuilder().addStatement(exec("umount /mnt")).render(OsFamily.UNIX);
    RunScriptOptions options = RunScriptOptions.Builder.overrideLoginUser(Constants.ROOT).overrideLoginPassword(Constants.PASSWORD).blockOnComplete(true);
    ZoneAndId zoneAndId = ZoneAndId.fromZoneAndId(Constants.ZONE, volumeAttachment.getServerId());
    ExecResponse response = compute.runScriptOnNode(zoneAndId.slashEncode(), script, options);
    if (response.getExitStatus() == 0) {
        System.out.println("  Exit Status: " + response.getExitStatus());
    } else {
        System.out.println("  Error: " + response.getOutput());
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ExecResponse(org.jclouds.compute.domain.ExecResponse) ZoneAndId(org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId) ScriptBuilder(org.jclouds.scriptbuilder.ScriptBuilder)

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