Everett Toews created JCLOUDS-467:
-------------------------------------

             Summary: nameNodes only taking first name with AWS
                 Key: JCLOUDS-467
                 URL: https://issues.apache.org/jira/browse/JCLOUDS-467
             Project: jclouds
          Issue Type: Bug
          Components: jclouds-compute
            Reporter: Everett Toews
             Fix For: 1.8.0


I'll put nameNodes into TemplateOptions but only the first gets used.

{code}
public class NameNodes {
    public static final String MCW = "multi-cloud-workshop";
    public static final String LOAD_BALANCER = MCW + "-lb";
    public static final String DATABASE = MCW + "-db";
    public static final String WEB_SERVER_01 = MCW + "-webserver-01";
    public static final String WEB_SERVER_02 = MCW + "-webserver-02";

    private final ComputeService computeService;

    public static void main(String[] args) {
        NameNodes nameNodes = null;

        try {
            nameNodes = new NameNodes();

            nameNodes.createServers();
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
            if (nameNodes != null) {
                nameNodes.close();
            }
        }
    }

    public NameNodes() throws IOException {
        Iterable<Module> modules = ImmutableSet.<Module>of(
                new SLF4JLoggingModule(),
                new SshjSshClientModule());

        Properties overrides = new Properties();
        overrides.setProperty(POLL_INITIAL_PERIOD, "30000");
        overrides.setProperty(POLL_MAX_PERIOD, "30000");

        ComputeServiceContext context = ContextBuilder.newBuilder("aws-ec2")
                .credentials("myAwsAccessKeyId", "myAwsSecretAccessKey")
                .modules(modules)
                .overrides(overrides)
                .buildView(ComputeServiceContext.class);
        computeService = context.getComputeService();
    }

    private Map<String, NodeMetadata> createServers() throws RunNodesException, 
IOException {
        Set<String> nodeNames = ImmutableSet.of(DATABASE, WEB_SERVER_01, 
WEB_SERVER_02, LOAD_BALANCER);

        System.out.println(format("Creating servers %s", Joiner.on(", 
").join(nodeNames)));

        TemplateOptions options = computeService.templateOptions()
                .nodeNames(nodeNames)
                .inboundPorts(22);

        Template template = computeService.templateBuilder()
                
.imageNameMatches("ubuntu/images/ubuntu-precise-12.04-amd64-server-20131003")
                .locationId("us-west-2")
                .hardwareId("m1.small")
                .options(options)
                .build();

        Set<? extends NodeMetadata> nodes = 
computeService.createNodesInGroup(MCW, 4, template);
        Map<String, NodeMetadata> nameToNode = newHashMap();

        System.out.println("Created servers:");
        for (NodeMetadata node: nodes) {
            String name = node.getName();
            String publicIpAddress = getOnlyElement(node.getPublicAddresses());
            String user = node.getCredentials().getUser();

            System.out.println(format("  %-40s %s@%s", name, user, 
publicIpAddress));

            nameToNode.put(name, node);
        }

        return nameToNode;
    }

    private void close() {
        computeService.getContext().close();
    }
}
{code}

The output is
{code}
Creating servers multi-cloud-workshop-db, multi-cloud-workshop-webserver-01, 
multi-cloud-workshop-webserver-02, multi-cloud-workshop-lb
Created servers:
  multi-cloud-workshop-db                  [email protected]
  multi-cloud-workshop-db                  [email protected]
  multi-cloud-workshop-db                  [email protected]
  multi-cloud-workshop-db                  [email protected]
{code}

Confirmed the names of the instances in the AWS console too.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to