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));
}
}
}
}
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));
}
}
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));
}
}
}
}
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");
}
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;
}
Aggregations