Ejemplo n.º 1
0
 @Test(dataProvider = "osNotSupported", expectedExceptions = NoSuchElementException.class)
 public void testTemplateBuilderCannotFind(OsFamilyVersion64Bit matrix)
     throws InterruptedException {
   TemplateBuilder builder =
       context
           .getComputeService()
           .templateBuilder()
           .osFamily(matrix.family)
           .os64Bit(matrix.is64Bit);
   if (!matrix.version.equals("")) builder.osVersionMatches("^" + matrix.version + "$");
   builder.build();
 }
Ejemplo n.º 2
0
 @Test(dataProvider = "osSupported")
 public void testTemplateBuilderCanFind(OsFamilyVersion64Bit matrix) throws InterruptedException {
   TemplateBuilder builder =
       context
           .getComputeService()
           .templateBuilder()
           .osFamily(matrix.family)
           .os64Bit(matrix.is64Bit);
   if (!matrix.version.equals("")) builder.osVersionMatches("^" + matrix.version + "$");
   Template template = builder.build();
   if (!matrix.version.equals(""))
     assertEquals(template.getImage().getOperatingSystem().getVersion(), matrix.version);
   assertEquals(template.getImage().getOperatingSystem().is64Bit(), matrix.is64Bit);
   assertEquals(template.getImage().getOperatingSystem().getFamily(), matrix.family);
 }
  @Override
  protected Object doExecute() throws Exception {
    ComputeService service = null;
    try {
      service = getComputeService();
    } catch (Throwable t) {
      System.err.println(t.getMessage());
      return null;
    }

    TemplateBuilder builder = service.templateBuilder();
    builder.any();
    if (smallest) {
      builder.smallest();
    }
    if (fastest) {
      builder.fastest();
    }
    if (biggest) {
      builder.biggest();
    }
    if (locationId != null) {
      builder.locationId(locationId);
    }
    if (imageId != null) {
      builder.imageId(imageId);
    }
    if (hardwareId != null) {
      builder.hardwareId(hardwareId);
    }

    if (osFamily != null) {
      builder.osFamily(OsFamily.fromValue(osFamily));
    }

    if (osVersion != null) {
      builder.osVersionMatches(osVersion);
    }

    TemplateOptions options = service.templateOptions();
    List<Statement> statements = Lists.newLinkedList();

    if (adminAccess) {
      statements.add(AdminAccess.standard());
    }
    if (recipes != null) {
      for (String recipe : recipes) {
        statements.add(recipeManager.createStatement(recipe, group));
      }
    }
    if (ec2SecurityGroups != null) {
      options.as(EC2TemplateOptions.class).securityGroups(ec2SecurityGroups);
    }
    if (ec2KeyPair != null) {
      options.as(EC2TemplateOptions.class).keyPair(ec2KeyPair);
    }
    if (ec2NoKeyPair != null) {
      options.as(EC2TemplateOptions.class).noKeyPair();
    }

    Set<? extends NodeMetadata> metadatas = null;

    if (!statements.isEmpty()) {
      options.runScript(new StatementList(statements));
    }

    try {
      metadatas = service.createNodesInGroup(group, number, builder.options(options).build());
    } catch (RunNodesException ex) {
      System.out.println("Failed to create nodes:" + ex.getMessage());
    }

    if (metadatas != null && !metadatas.isEmpty()) {
      System.out.println("Created nodes:");
      printNodes(service, metadatas, System.out);

      for (NodeMetadata node : metadatas) {
        for (String cacheKey : ServiceHelper.findCacheKeysForService(service)) {
          cacheProvider
              .getProviderCacheForType(Constants.ACTIVE_NODE_CACHE)
              .put(cacheKey, node.getId());
          cacheProvider
              .getProviderCacheForType(Constants.INACTIVE_NODE_CACHE)
              .put(cacheKey, node.getId());
          cacheProvider
              .getProviderCacheForType(Constants.SUSPENDED_NODE_CACHE)
              .put(cacheKey, node.getId());
        }
      }
    }

    return null;
  }