use of org.apache.whirr.ClusterController in project whirr by apache.
the class ListClusterCommand method run.
public int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec) throws Exception {
ClusterStateStore stateStore = createClusterStateStore(clusterSpec);
ClusterController controller = createClusterController(clusterSpec.getServiceName());
for (Cluster.Instance instance : controller.getInstances(clusterSpec, stateStore)) {
out.println(Joiner.on('\t').useForNull("-").join(instance.getId(), instance.getNodeMetadata().getImageId(), instance.getPublicIp(), instance.getPrivateIp(), instance.getNodeMetadata().getStatus(), instance.getNodeMetadata().getLocation().getId(), Joiner.on(",").join(instance.getRoles())));
}
return 0;
}
use of org.apache.whirr.ClusterController in project whirr by apache.
the class LaunchClusterCommand method run.
public int run(InputStream in, PrintStream out, PrintStream err, ClusterSpec clusterSpec) throws Exception {
ClusterController controller = createClusterController(clusterSpec.getServiceName());
Cluster cluster = controller.launchCluster(clusterSpec);
out.printf("Started cluster of %s instances\n", cluster.getInstances().size());
out.println(cluster);
Utils.printSSHConnectionDetails(out, clusterSpec, cluster, 20);
out.println("To destroy cluster, run 'whirr destroy-cluster' with the same options used to launch it.");
return 0;
}
use of org.apache.whirr.ClusterController in project whirr by apache.
the class DryRunModuleTest method testExecuteOnlyBootstrapForNoop.
@Test
public void testExecuteOnlyBootstrapForNoop() throws Exception {
CompositeConfiguration config = new CompositeConfiguration();
config.setProperty("whirr.provider", "stub");
config.setProperty("whirr.cluster-name", "stub-test");
config.setProperty("whirr.instance-templates", "1 noop");
config.setProperty("whirr.state-store", "memory");
ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(config);
ClusterController controller = new ClusterController();
DryRun dryRun = getDryRunInControllerForCluster(controller, clusterSpec);
dryRun.reset();
controller.launchCluster(clusterSpec);
controller.destroyCluster(clusterSpec);
ListMultimap<NodeMetadata, Statement> perNodeExecutions = dryRun.getExecutions();
for (Entry<NodeMetadata, Collection<Statement>> entry : perNodeExecutions.asMap().entrySet()) {
assertSame("An incorrect number of scripts was executed in the node " + entry, entry.getValue().size(), 1);
}
}
use of org.apache.whirr.ClusterController in project whirr by apache.
the class HadoopClusterExample method main.
@Override
public int main(String[] args) throws Exception {
if (!System.getenv().containsKey("AWS_ACCESS_KEY_ID")) {
LOG.error("AWS_ACCESS_KEY_ID is undefined in the current environment");
return -1;
}
if (!System.getenv().containsKey("AWS_SECRET_ACCESS_KEY")) {
LOG.error("AWS_SECRET_ACCESS_KEY is undefined in the current environment");
return -2;
}
/**
* Start by loading cluster configuration file and creating a ClusterSpec object
*
* You can find the file in the resources folder.
*/
ClusterSpec spec = new ClusterSpec(new PropertiesConfiguration("whirr-hadoop-example.properties"));
/**
* Create an instance of the generic cluster controller
*/
ClusterControllerFactory factory = new ClusterControllerFactory();
ClusterController controller = factory.create(spec.getServiceName());
/**
* Start the cluster as defined in the configuration file
*/
HadoopProxy proxy = null;
try {
LOG.info("Starting cluster {}", spec.getClusterName());
Cluster cluster = controller.launchCluster(spec);
LOG.info("Starting local SOCKS proxy");
proxy = new HadoopProxy(spec, cluster);
proxy.start();
/**
* Obtain a Hadoop configuration object and wait for services to start
*/
Configuration config = getHadoopConfiguration(cluster);
JobConf job = new JobConf(config, HadoopClusterExample.class);
JobClient client = new JobClient(job);
waitToExitSafeMode(client);
waitForTaskTrackers(client);
/**
* Run a simple job to show that the cluster is available for work.
*/
runWordCountingJob(config);
} finally {
/**
* Stop the proxy and terminate all the cluster instances.
*/
if (proxy != null) {
proxy.stop();
}
controller.destroyCluster(spec);
return 0;
}
}
use of org.apache.whirr.ClusterController 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();
}
Aggregations