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);
}
}
Aggregations