Uploaded image for project: 'jclouds'
  1. jclouds
  2. JCLOUDS-467

nameNodes only taking first name with AWS

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.7.3, 1.8.0
    • jclouds-compute
    • None

    Description

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

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

      The output is

      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                  ubuntu@54.184.78.205
        multi-cloud-workshop-db                  ubuntu@54.203.107.107
        multi-cloud-workshop-db                  ubuntu@54.202.100.94
        multi-cloud-workshop-db                  ubuntu@54.184.52.175
      

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

      Attachments

        Activity

          People

            abayer Andrew Bayer
            everett-toews Everett Toews
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: