use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class ConfigureServicesAction method eventSpecificActions.
/**
* Apply the firewall rules specified via configuration.
*/
protected void eventSpecificActions(InstanceTemplate instanceTemplate, ClusterActionEvent event) throws IOException {
ClusterSpec clusterSpec = event.getClusterSpec();
Map<String, List<String>> firewallRules = clusterSpec.getFirewallRules();
for (String role : firewallRules.keySet()) {
if (!roleIsInTarget(role)) {
// skip execution for this role
continue;
}
Rule rule = Rule.create();
if (role == null) {
rule.destination(event.getCluster().getInstances());
} else {
rule.destination(RolePredicates.role(role));
}
List<String> ports = firewallRules.get(role);
rule.ports(Ints.toArray(Collections2.transform(ports, new Function<String, Integer>() {
@Override
public Integer apply(String input) {
return Integer.valueOf(input);
}
})));
event.getFirewallManager().addRule(rule);
}
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class ByonClusterAction method doAction.
@Override
protected void doAction(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException, InterruptedException {
final Collection<Future<ExecResponse>> futures = Sets.newHashSet();
List<NodeMetadata> nodes = Lists.newArrayList();
List<NodeMetadata> usedNodes = Lists.newArrayList();
int numberAllocated = 0;
Set<Instance> allInstances = Sets.newLinkedHashSet();
for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
if (statementBuilder.isEmpty()) {
// skip
continue;
}
final ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
final ComputeService computeService = computeServiceContext.getComputeService();
LoginCredentials credentials = LoginCredentials.builder().user(clusterSpec.getClusterUser()).privateKey(clusterSpec.getPrivateKey()).build();
final RunScriptOptions options = overrideLoginCredentials(credentials);
if (numberAllocated == 0) {
for (ComputeMetadata compute : computeService.listNodes()) {
if (!(compute instanceof NodeMetadata)) {
throw new IllegalArgumentException("Not an instance of NodeMetadata: " + compute);
}
nodes.add((NodeMetadata) compute);
}
}
int num = entry.getKey().getNumberOfInstances();
Predicate<NodeMetadata> unused = not(in(usedNodes));
// TODO: This seems very fragile and a bug. It is not required that someone passes a hardware id,
// so this is likely to break badly. Even if there was, why do we assume it is splittable?!
// this logic should be refactored or removed ASAP
Predicate<NodeMetadata> instancePredicate = Predicates.alwaysTrue();
if (entry.getKey().getTemplate() != null) {
String hardwareId = entry.getKey().getTemplate().getHardwareId();
if (hardwareId != null)
instancePredicate = new TagsPredicate(StringUtils.split(hardwareId));
}
List<NodeMetadata> templateNodes = Lists.newArrayList(filter(nodes, and(unused, instancePredicate)));
if (templateNodes.size() < num) {
LOG.warn("Not enough nodes available for template " + StringUtils.join(entry.getKey().getRoles(), "+"));
}
templateNodes = templateNodes.subList(0, num);
usedNodes.addAll(templateNodes);
numberAllocated = usedNodes.size();
Set<Instance> templateInstances = getInstances(credentials, entry.getKey().getRoles(), templateNodes);
allInstances.addAll(templateInstances);
for (final Instance instance : templateInstances) {
futures.add(runStatementOnInstanceInCluster(statementBuilder, instance, clusterSpec, options));
}
}
for (Future<ExecResponse> future : futures) {
try {
future.get();
} catch (ExecutionException e) {
throw new IOException(e.getCause());
}
}
if (action.equals(ClusterActionHandler.BOOTSTRAP_ACTION)) {
Cluster cluster = new Cluster(allInstances);
for (ClusterActionEvent event : eventMap.values()) {
event.setCluster(cluster);
}
}
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class DestroyClusterAction method postRunScriptsActions.
@Override
protected void postRunScriptsActions(Map<InstanceTemplate, ClusterActionEvent> eventMap) throws IOException {
ClusterSpec clusterSpec = eventMap.values().iterator().next().getClusterSpec();
LOG.info("Destroying " + clusterSpec.getClusterName() + " cluster");
ComputeService computeService = getCompute().apply(clusterSpec).getComputeService();
computeService.destroyNodesMatching(inGroup(clusterSpec.getClusterName()));
LOG.info("Cluster {} destroyed", clusterSpec.getClusterName());
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class LaunchClusterCommand method run.
@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
OptionSet optionSet = parser.parse(args.toArray(new String[args.size()]));
if (!optionSet.nonOptionArguments().isEmpty()) {
printUsage(err);
return -1;
}
try {
ClusterSpec clusterSpec = getClusterSpec(optionSet);
printProviderInfo(out, err, clusterSpec, optionSet);
return run(in, out, err, clusterSpec);
} catch (IllegalArgumentException e) {
printErrorAndHelpHint(err, e);
return -1;
}
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class SolrClusterActionHandler method beforeStart.
@Override
protected void beforeStart(ClusterActionEvent event) throws IOException {
ClusterSpec clusterSpec = event.getClusterSpec();
Configuration config = getConfiguration(clusterSpec, SOLR_DEFAULT_CONFIG);
String solrConfigTarballUrl = prepareRemoteFileUrl(event, config.getString(SOLR_CONFIG_TARBALL_URL));
LOG.info("Preparing solr config tarball url {}", solrConfigTarballUrl);
addStatement(event, call("install_tarball_no_md5", solrConfigTarballUrl, SOLR_HOME));
int jettyPort = config.getInt(SOLR_JETTY_PORT);
int jettyStopPort = config.getInt(SOLR_JETTY_STOP_PORT);
String startFunc = getStartFunction(config, getRole(), "start_" + getRole());
LOG.info("Starting up Solr");
addStatement(event, call(startFunc, String.valueOf(jettyPort), String.valueOf(jettyStopPort), safeSecretString(config.getString(SOLR_JETTY_STOP_SECRET)), SOLR_HOME, SOLR_HOME + "/example/start.jar", config.getString(SOLR_JAVA_OPTS, "")));
}
Aggregations