Search in sources :

Example 1 with AWSEC2TemplateOptions

use of org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions in project legacy-jclouds-examples by jclouds.

the class NodeManager method createNodeWithAdminUserAndJDKInGroupOpeningPortAndMinRam.

public NodeMetadata createNodeWithAdminUserAndJDKInGroupOpeningPortAndMinRam(String group, int port, int minRam) {
    ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String>of("Name", group);
    // we want everything as defaults except ram
    Template defaultTemplate = compute.templateBuilder().build();
    Template minecraft = compute.templateBuilder().fromTemplate(defaultTemplate).minRam(minRam).build();
    // setup the template to customize the node with jdk, etc. also opening ports.
    Statement bootstrap = newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK());
    minecraft.getOptions().inboundPorts(22, port).userMetadata(userMetadata).runScript(bootstrap);
    // example of using a cloud-specific hook
    if (minecraft.getOptions() instanceof AWSEC2TemplateOptions)
        minecraft.getOptions().as(AWSEC2TemplateOptions.class).enableMonitoring();
    logger.info(">> creating node type(%s) in group %s, opening ports 22, %s with admin user and jdk", minecraft.getHardware().getId(), group, port);
    try {
        NodeMetadata node = getOnlyElement(compute.createNodesInGroup(group, 1, minecraft));
        logger.info("<< available node(%s) os(%s) publicAddresses%s", node.getId(), node.getOperatingSystem(), node.getPublicAddresses());
        return node;
    } catch (RunNodesException e) {
        throw destroyBadNodesAndPropagate(e);
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) RunNodesException(org.jclouds.compute.RunNodesException) Statement(org.jclouds.scriptbuilder.domain.Statement) AWSEC2TemplateOptions(org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions) Template(org.jclouds.compute.domain.Template)

Aggregations

AWSEC2TemplateOptions (org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions)1 RunNodesException (org.jclouds.compute.RunNodesException)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 Template (org.jclouds.compute.domain.Template)1 Statement (org.jclouds.scriptbuilder.domain.Statement)1