Search in sources :

Example 6 with InstanceTemplate

use of org.apache.whirr.InstanceTemplate in project whirr by apache.

the class BootstrapTemplate method build.

public static Template build(final ClusterSpec clusterSpec, ComputeService computeService, StatementBuilder statementBuilder, InstanceTemplate instanceTemplate) {
    String name = "bootstrap-" + Joiner.on('_').join(instanceTemplate.getRoles());
    LOG.info("Configuring template for {}", name);
    statementBuilder.name(name);
    ensureUserExistsAndAuthorizeSudo(statementBuilder, clusterSpec.getClusterUser(), clusterSpec.getPublicKey(), clusterSpec.getPrivateKey());
    Statement bootstrap = statementBuilder.build(clusterSpec);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Running script {}:\n{}", name, bootstrap.render(OsFamily.UNIX));
    }
    TemplateBuilder templateBuilder = computeService.templateBuilder().from(instanceTemplate.getTemplate() != null ? instanceTemplate.getTemplate() : clusterSpec.getTemplate());
    Template template = templateBuilder.build();
    template.getOptions().runScript(bootstrap);
    return setSpotInstancePriceIfSpecified(computeService.getContext(), clusterSpec, template, instanceTemplate);
}
Also used : Statement(org.jclouds.scriptbuilder.domain.Statement) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) InstanceTemplate(org.apache.whirr.InstanceTemplate) Template(org.jclouds.compute.domain.Template)

Aggregations

InstanceTemplate (org.apache.whirr.InstanceTemplate)6 Cluster (org.apache.whirr.Cluster)4 ClusterActionEvent (org.apache.whirr.service.ClusterActionEvent)4 StatementBuilder (org.apache.whirr.service.jclouds.StatementBuilder)4 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Future (java.util.concurrent.Future)3 Instance (org.apache.whirr.Cluster.Instance)3 ClusterSpec (org.apache.whirr.ClusterSpec)3 ComputeService (org.jclouds.compute.ComputeService)3 Template (org.jclouds.compute.domain.Template)3 ExecResponse (org.jclouds.compute.domain.ExecResponse)2 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)2 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)2 RunScriptOptions (org.jclouds.compute.options.RunScriptOptions)2 Joiner (com.google.common.base.Joiner)1 Predicate (com.google.common.base.Predicate)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1