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