Search in sources :

Example 1 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project camel by apache.

the class JcloudsSpringComputeTest method testCreateAndDestroyNode.

@Test
public void testCreateAndDestroyNode() throws InterruptedException {
    result.expectedMessageCount(1);
    template.sendBodyAndHeaders("direct:start", null, createHeaders("1", "default"));
    result.assertIsSatisfied();
    List<Exchange> exchanges = result.getExchanges();
    if (exchanges != null && !exchanges.isEmpty()) {
        for (Exchange exchange : exchanges) {
            Set<?> nodeMetadatas = exchange.getIn().getBody(Set.class);
            assertEquals("There should be no node running", 1, nodeMetadatas.size());
            for (Object obj : nodeMetadatas) {
                NodeMetadata nodeMetadata = (NodeMetadata) obj;
                template.sendBodyAndHeaders("direct:start", null, destroyHeaders(nodeMetadata.getId(), null));
            }
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Test(org.junit.Test)

Example 2 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project camel by apache.

the class JcloudsSpringComputeTest method testRunScript.

@SuppressWarnings("unchecked")
@Ignore("For now not possible to combine stub provider with ssh module, required for runScript")
@Test
public void testRunScript() throws InterruptedException {
    Map<String, Object> runScriptHeaders = new HashMap<String, Object>();
    runScriptHeaders.put(JcloudsConstants.OPERATION, JcloudsConstants.RUN_SCRIPT);
    Set<? extends NodeMetadata> nodeMetadatas = (Set<? extends NodeMetadata>) template.requestBodyAndHeaders("direct:in-out", null, createHeaders("1", "default"));
    assertEquals("There should be a node running", 1, nodeMetadatas.size());
    for (NodeMetadata nodeMetadata : nodeMetadatas) {
        runScriptHeaders.put(JcloudsConstants.NODE_ID, nodeMetadata.getId());
        template.requestBodyAndHeaders("direct:in-out", null, runScriptHeaders);
        template.sendBodyAndHeaders("direct:in-out", null, destroyHeaders(nodeMetadata.getId(), null));
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Set(java.util.Set) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project camel by apache.

the class JcloudsSpringComputeTest method testCreateAndSuspendNode.

@Test
public void testCreateAndSuspendNode() throws InterruptedException {
    result.expectedMessageCount(1);
    template.sendBodyAndHeaders("direct:start", null, createHeaders("1", "default"));
    result.assertIsSatisfied();
    List<Exchange> exchanges = result.getExchanges();
    if (exchanges != null && !exchanges.isEmpty()) {
        for (Exchange exchange : exchanges) {
            Set<?> nodeMetadatas = exchange.getIn().getBody(Set.class);
            assertEquals("There should be one node running", 1, nodeMetadatas.size());
            for (Object obj : nodeMetadatas) {
                NodeMetadata nodeMetadata = (NodeMetadata) obj;
                template.sendBodyAndHeaders("direct:start", null, suspendHeaders(nodeMetadata.getId(), null));
            }
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Test(org.junit.Test)

Example 4 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project hive by apache.

the class CloudExecutionContextProvider method replaceBadHosts.

@Override
public void replaceBadHosts(ExecutionContext executionContext) throws CreateHostsFailedException {
    Set<String> hostsToTerminate = Sets.newHashSet();
    Set<Host> hostsNotRemoved = Sets.newHashSet();
    for (Host host : executionContext.getBadHosts()) {
        hostsToTerminate.add(host.getName());
        if (!executionContext.removeHost(host)) {
            hostsNotRemoved.add(host);
        }
    }
    executionContext.clearBadHosts();
    if (!hostsToTerminate.isEmpty()) {
        LOG.info("Replacing " + hostsToTerminate);
        terminate(hostsToTerminate, true);
        Set<NodeMetadata> nodes = createNodes(hostsToTerminate.size());
        for (NodeMetadata node : nodes) {
            executionContext.addHost(new Host(publicIp(node), mUser, mSlaveLocalDirs, mNumThreads));
        }
    }
    Preconditions.checkState(hostsNotRemoved.isEmpty(), "Host " + hostsNotRemoved + " was in bad hosts but could not be removed");
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Host(org.apache.hive.ptest.execution.conf.Host)

Example 5 with NodeMetadata

use of org.jclouds.compute.domain.NodeMetadata in project hive by apache.

the class CloudExecutionContextProvider method verifyHosts.

private Set<NodeMetadata> verifyHosts(Set<? extends NodeMetadata> hosts) throws CreateHostsFailedException {
    final Set<NodeMetadata> result = Collections.synchronizedSet(new HashSet<NodeMetadata>());
    if (!hosts.isEmpty()) {
        persistHostnamesToLog(hosts);
        ExecutorService executorService = Executors.newFixedThreadPool(Math.min(hosts.size(), 25));
        try {
            for (final NodeMetadata node : hosts) {
                executorService.submit(new Runnable() {

                    @Override
                    public void run() {
                        String ip = publicIpOrHostname(node);
                        SSHCommand command = new SSHCommand(mSSHCommandExecutor, mPrivateKey, mUser, ip, 0, "pkill -f java", true);
                        mSSHCommandExecutor.execute(command);
                        if (command.getExitCode() == Constants.EXIT_CODE_UNKNOWN || command.getException() != null) {
                            LOG.error("Node " + node + " is bad on startup", command.getException());
                            terminateInternal(node);
                        } else {
                            result.add(node);
                        }
                    }
                });
            }
            executorService.shutdown();
            if (!executorService.awaitTermination(10, TimeUnit.MINUTES)) {
                LOG.error("Verify command still executing on a host after 10 minutes");
            }
        } catch (InterruptedException e) {
            terminateInternal(result);
            throw new CreateHostsFailedException("Interrupted while trying to create hosts", e);
        } finally {
            if (!executorService.isShutdown()) {
                executorService.shutdownNow();
            }
        }
    }
    return result;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) SSHCommand(org.apache.hive.ptest.execution.ssh.SSHCommand) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

NodeMetadata (org.jclouds.compute.domain.NodeMetadata)35 RunNodesException (org.jclouds.compute.RunNodesException)11 Template (org.jclouds.compute.domain.Template)9 ComputeService (org.jclouds.compute.ComputeService)7 IOException (java.io.IOException)6 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)6 Test (org.junit.Test)5 Exchange (org.apache.camel.Exchange)4 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)4 RunScriptOnNodesException (org.jclouds.compute.RunScriptOnNodesException)4 Statement (org.jclouds.scriptbuilder.domain.Statement)4 File (java.io.File)3 Set (java.util.Set)3 InstanceTemplate (org.apache.whirr.service.ClusterSpec.InstanceTemplate)3 ComputeMetadata (org.jclouds.compute.domain.ComputeMetadata)3 LoginCredentials (org.jclouds.domain.LoginCredentials)3 Predicate (com.google.common.base.Predicate)2 Properties (java.util.Properties)2 Host (org.apache.hive.ptest.execution.conf.Host)2 RunListBuilder (org.jclouds.chef.util.RunListBuilder)2