use of org.apache.whirr.Cluster in project whirr by apache.
the class RunScriptCommandTest method createTestCluster.
private Cluster createTestCluster(String[] ids, String[] roles) {
checkArgument(ids.length == roles.length, "each ID should have a role");
Credentials credentials = new Credentials("dummy", "dummy");
Set<Cluster.Instance> instances = Sets.newHashSet();
for (int i = 0; i < ids.length; i++) {
String ip = "127.0.0." + (i + 1);
instances.add(new Cluster.Instance(credentials, Sets.newHashSet(roles[i]), ip, ip, ids[i], null));
}
return new Cluster(instances);
}
use of org.apache.whirr.Cluster 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.apache.whirr.Cluster in project whirr by apache.
the class ClusterStateStore method unserialize.
/**
* Rebuild the {@link Cluster} instance by using the string representation
*
* @param spec
* @param content
* @return
* @throws UnknownHostException
*/
protected Cluster unserialize(ClusterSpec spec, String content) throws UnknownHostException {
Credentials credentials = new Credentials(spec.getClusterUser(), spec.getPrivateKey());
Set<Cluster.Instance> instances = Sets.newLinkedHashSet();
for (String line : Splitter.on("\n").split(content)) {
if (line.trim().equals(""))
continue;
/* ignore empty lines */
Iterator<String> fields = Splitter.on("\t").split(line).iterator();
String id = fields.next();
Set<String> roles = Sets.newLinkedHashSet(Splitter.on(",").split(fields.next()));
String publicIPAddress = fields.next();
String privateIPAddress = fields.next();
instances.add(new Cluster.Instance(credentials, roles, publicIPAddress, privateIPAddress, id, null));
}
return new Cluster(instances);
}
use of org.apache.whirr.Cluster 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.Cluster in project whirr by apache.
the class ZooKeeperClusterActionHandler method afterConfigure.
@Override
protected void afterConfigure(ClusterActionEvent event) {
ClusterSpec clusterSpec = event.getClusterSpec();
Cluster cluster = event.getCluster();
LOG.info("Completed configuration of {}", clusterSpec.getClusterName());
String hosts = Joiner.on(',').join(getHosts(cluster.getInstancesMatching(role(ZOOKEEPER_ROLE))));
LOG.info("Hosts: {}", hosts);
}
Aggregations