Package org.jclouds.compute.domain

Examples of org.jclouds.compute.domain.TemplateBuilder


      } 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()) {
View Full Code Here


        String hardwareId = getHardwareId(exchange);

        if (group == null) {
            throw new CamelException("Group must be specific in the URI or as exchange property for the destroy node operation.");
        }
        TemplateBuilder builder = computeService.templateBuilder();
        builder.any();

        if (locationId != null) {
            builder.locationId(locationId);
        }
        if (imageId != null) {
            builder.imageId(imageId);
        }
        if (hardwareId != null) {
            builder.hardwareId(hardwareId);
        }

        try {
            Set<? extends NodeMetadata> nodeMetadatas = computeService.createNodesInGroup(group, 1, builder.build());
            exchange.getOut().setBody(nodeMetadatas);
            exchange.getOut().setHeaders(exchange.getIn().getHeaders());
        } catch (RunNodesException e) {
            throw new CamelException("Error creating jclouds node.", e);
        }
View Full Code Here

   abstract protected Module getSshModule();

   @BeforeClass(groups = { "integration", "live" }, dependsOnMethods = "setupContext")
   public void createNodes() throws RunNodesException {
      try {
         TemplateBuilder builder = computeContext.getComputeService().templateBuilder();
         if (template != null)
            builder.from(template);
         nodes = computeContext.getComputeService().createNodesInGroup(group, 2, builder.build());
      } catch (RunNodesException e) {
         nodes = e.getSuccessfulNodes();
         throw e;
      }
   }
View Full Code Here

    if (LOG.isDebugEnabled()) {
      LOG.debug("Running script {}:\n{}", name, bootstrap.render(OsFamily.UNIX));
    }

    TemplateBuilder templateBuilder = computeService.templateBuilder().from(
        instanceTemplate.getTemplate() != null ? instanceTemplate.getTemplate() :
        clusterSpec.getTemplate());
    Template template = templateBuilder.build();
    template.getOptions().runScript(bootstrap);
    return setSpotInstancePriceIfSpecified(
      computeService.getContext(), clusterSpec, template, instanceTemplate
    );
  }
View Full Code Here

    public void start(String id, NodeLauncherConfig cfg) throws Exception {
        JcloudsNodeLauncherConfig config = (JcloudsNodeLauncherConfig) cfg;
        m_currentConfig = config;

        ComputeService computeService = config.getComputeService();
        TemplateBuilder template = computeService.templateBuilder()
                .imageId(config.getImageId())
                .hardwareId(config.getHardwareId())
                .locationId(config.getLocation());

        int[] extraPorts = parseExtraPorts(config.getExtraPorts());
        int[] inboundPorts = mergePorts(DEFAULT_PORTS, extraPorts);

        TemplateOptions options = new EC2TemplateOptions()
                .as(EC2TemplateOptions.class).inboundPorts(inboundPorts)
                .blockOnComplete(false)
                .runAsRoot(config.isRunAsRoot());

        if (useConfiguredKeyPair(config)) {
            options.as(EC2TemplateOptions.class).keyPair(config.getKeyPair());
        }

        template.options(options);

        Set<? extends NodeMetadata> tag = computeService.createNodesInGroup(config.getTagPrefix() + id, 1, template.build());
        if (!useConfiguredPrivateKey(config)) {
            System.out.println("In case you need it, this is the key to ssh to " + id + ":\n" + tag.iterator().next().getCredentials().credential);
        }

        LoginCredentials.Builder loginBuilder = LoginCredentials.builder();
View Full Code Here

    Payload bootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
      "sun/java/install",
      "apache/zookeeper/install"));
   
    TemplateBuilder templateBuilder = computeService.templateBuilder()
      .options(runScript(bootScript)
      .installPrivateKey(clusterSpec.getPrivateKey())
      .authorizePublicKey(clusterSpec.getPublicKey()));
   
    new TemplateBuilderStrategy().configureTemplateBuilder(clusterSpec,
        templateBuilder);
   
    LOG.info("Configuring template");
    Template template = templateBuilder.build();
   
    InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(ZOOKEEPER_ROLE);
    checkNotNull(instanceTemplate);
    int ensembleSize = instanceTemplate.getNumberOfInstances();
    Set<? extends NodeMetadata> nodeMap;
View Full Code Here

    Payload bootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
        "sun/java/install",
        "apache/cassandra/install"));

    TemplateBuilder templateBuilder = computeService.templateBuilder()
        .options(
            runScript(bootScript).installPrivateKey(
                clusterSpec.getPrivateKey()).authorizePublicKey(
                clusterSpec.getPublicKey()));

    new TemplateBuilderStrategy().configureTemplateBuilder(clusterSpec,
        templateBuilder);

    LOG.info("Configuring template");
    Template template = templateBuilder.build();

    InstanceTemplate instanceTemplate = clusterSpec
        .getInstanceTemplate(CASSANDRA_ROLE);
    checkNotNull(instanceTemplate);
    int clusterSize = instanceTemplate.getNumberOfInstances();
View Full Code Here

    if (LOG.isDebugEnabled()) {
      LOG.debug("Running script {}:\n{}", name, bootstrap.render(OsFamily.UNIX));
    }

    TemplateBuilder templateBuilder = computeService.templateBuilder().from(
        instanceTemplate.getTemplate() != null ? instanceTemplate.getTemplate() :
        clusterSpec.getTemplate());
    Template template = templateBuilder.build();
    template.getOptions().runScript(bootstrap);
    return setSpotInstancePriceIfSpecified(
      computeService.getContext(), clusterSpec, template, instanceTemplate
    );
  }
View Full Code Here

        .put("hadoop-tasktracker", handler).build());

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);
    TemplateOptions templateOptions = mock(TemplateOptions.class);
   
    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.getContext()).thenReturn(serviceContext);
    when(serviceContext.getBackendType()).thenReturn(TypeToken.class.cast(TypeToken.of(Context.class)));
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    when(template.getOptions()).thenReturn(templateOptions);
   
    // here is a scenario when jt+nn fails once, then the retry is successful
    // and from the dn+tt one node fails, then the retry is successful
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
View Full Code Here

        .put("hadoop-tasktracker", handler).build());

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);
    TemplateOptions templateOptions = mock(TemplateOptions.class);

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.getContext()).thenReturn(serviceContext);
    when(serviceContext.getBackendType()).thenReturn(TypeToken.class.cast(TypeToken.of(Context.class)));
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    when(template.getOptions()).thenReturn(templateOptions);
   
    // here is a scenario when jt+nn does not fail
    // but the dn+tt one node fails 3, then in the retry fails 2
    // at the end result, the cluster will fail, throwing IOException
View Full Code Here

TOP

Related Classes of org.jclouds.compute.domain.TemplateBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.