Search in sources :

Example 31 with ClusterSpec

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);
    }
}
Also used : List(java.util.List) ClusterSpec(org.apache.whirr.ClusterSpec) Rule(org.apache.whirr.service.FirewallManager.Rule)

Example 32 with ClusterSpec

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);
        }
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) Instance(org.apache.whirr.Cluster.Instance) ExecResponse(org.jclouds.compute.domain.ExecResponse) ClusterActionEvent(org.apache.whirr.service.ClusterActionEvent) ComputeMetadata(org.jclouds.compute.domain.ComputeMetadata) LoginCredentials(org.jclouds.domain.LoginCredentials) Builder.overrideLoginCredentials(org.jclouds.compute.options.RunScriptOptions.Builder.overrideLoginCredentials) ExecutionException(java.util.concurrent.ExecutionException) Cluster(org.apache.whirr.Cluster) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) IOException(java.io.IOException) ComputeService(org.jclouds.compute.ComputeService) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) StatementBuilder(org.apache.whirr.service.jclouds.StatementBuilder) Future(java.util.concurrent.Future) InstanceTemplate(org.apache.whirr.InstanceTemplate)

Example 33 with ClusterSpec

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());
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) ComputeService(org.jclouds.compute.ComputeService)

Example 34 with ClusterSpec

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;
    }
}
Also used : ClusterSpec(org.apache.whirr.ClusterSpec) OptionSet(joptsimple.OptionSet)

Example 35 with ClusterSpec

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, "")));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ClusterSpec(org.apache.whirr.ClusterSpec)

Aggregations

ClusterSpec (org.apache.whirr.ClusterSpec)98 Configuration (org.apache.commons.configuration.Configuration)39 Cluster (org.apache.whirr.Cluster)35 Test (org.junit.Test)34 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)16 Instance (org.apache.whirr.Cluster.Instance)14 ClusterController (org.apache.whirr.ClusterController)10 InetAddress (java.net.InetAddress)9 DryRun (org.apache.whirr.service.DryRunModule.DryRun)9 OptionSet (joptsimple.OptionSet)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 ZooKeeperCluster (org.apache.whirr.service.zookeeper.ZooKeeperCluster)8 IOException (java.io.IOException)7 ComputeService (org.jclouds.compute.ComputeService)7 File (java.io.File)6 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)6 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)6 Set (java.util.Set)5 Stack (java.util.Stack)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5