Search in sources :

Example 16 with TemplateBuilder

use of org.jclouds.compute.domain.TemplateBuilder in project iobserve-analysis by research-iobserve.

the class AllocateActionScript method execute.

@Override
public void execute() throws RunNodesException {
    final ResourceContainer container = this.action.getTargetResourceContainer();
    final ResourceContainerCloud cloudContainer = this.getResourceContainerCloud(container);
    final ComputeService client = this.getComputeServiceForContainer(cloudContainer);
    final TemplateBuilder templateBuilder = client.templateBuilder();
    final VMType instanceType = cloudContainer.getInstanceType();
    templateBuilder.hardwareId(instanceType.getName());
    templateBuilder.locationId(instanceType.getLocation());
    // TODO maybe make this configurable
    templateBuilder.osFamily(OsFamily.UBUNTU);
    final Statement setupAdminInstructions = AdminAccess.standard();
    // Necessary to set hostname to allow mapping for later events
    final TemplateOptions options = Builder.runScript(setupAdminInstructions).runScript(AllocateActionScript.getChangeHostnameScript(cloudContainer)).runScript(this.getStartupScript());
    templateBuilder.options(options);
    final Template template = templateBuilder.build();
    final String groupName = ModelHelper.getGroupName(cloudContainer);
    final NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(groupName, 1, template));
    AllocateActionScript.LOGGER.info(String.format("Allocated node for resource container '%s'. NodeID: %s, Hostname: %s, Adresses: %s", cloudContainer.getEntityName(), node.getId(), node.getHostname(), Iterables.concat(node.getPrivateAddresses(), node.getPublicAddresses())));
// TODO write resource container to original model to enable mapping
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ResourceContainerCloud(org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud) VMType(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType) Statement(org.jclouds.scriptbuilder.domain.Statement) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) TemplateOptions(org.jclouds.compute.options.TemplateOptions) ComputeService(org.jclouds.compute.ComputeService) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer) Template(org.jclouds.compute.domain.Template)

Aggregations

TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)16 ComputeService (org.jclouds.compute.ComputeService)13 Template (org.jclouds.compute.domain.Template)11 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)9 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)8 RunNodesException (org.jclouds.compute.RunNodesException)7 TemplateOptions (org.jclouds.compute.options.TemplateOptions)7 Statement (org.jclouds.scriptbuilder.domain.Statement)6 ImmutableSet (com.google.common.collect.ImmutableSet)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Stack (java.util.Stack)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)4 Configuration (org.apache.commons.configuration.Configuration)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 ClusterSpec (org.apache.whirr.ClusterSpec)4 ClusterActionHandler (org.apache.whirr.service.ClusterActionHandler)4 RunScriptOnNodesException (org.jclouds.compute.RunScriptOnNodesException)4 Test (org.junit.Test)4