Package org.jclouds.compute

Examples of org.jclouds.compute.ComputeService


    Files.deleteRecursively(clusterSpec.getClusterDirectory());
  }
 
  public Set<? extends NodeMetadata> getNodes(ClusterSpec clusterSpec)
    throws IOException, InterruptedException {
    ComputeService computeService =
      ComputeServiceContextBuilder.build(clusterSpec).getComputeService();
    return computeService.listNodesDetailsMatching(
        runningWithTag(clusterSpec.getClusterName()));
  }
View Full Code Here


  @Override
  public Cluster execute(ClusterSpec clusterSpec, Cluster cluster)
      throws IOException, InterruptedException {
    LOG.info("Destroying " + clusterSpec.getClusterName() + " cluster");
    ComputeService computeService =
      ComputeServiceContextBuilder.build(clusterSpec).getComputeService();
    computeService.destroyNodesMatching(withTag(clusterSpec.getClusterName()));
    LOG.info("Cluster {} destroyed", clusterSpec.getClusterName());
    return null;
  }
View Full Code Here

      final InstanceTemplate instanceTemplate = entry.getKey();
      final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext =
        ComputeServiceContextBuilder.build(clusterSpec);
      final ComputeService computeService =
        computeServiceContext.getComputeService();
      final Template template = buildTemplate(clusterSpec, computeService,
          statementBuilder, entry.getValue().getTemplateBuilderStrategy());
     
      Future<Set<? extends NodeMetadata>> nodesFuture = executorService.submit(
        new Callable<Set<? extends NodeMetadata>>() {
          public Set<? extends NodeMetadata> call() throws Exception {
            int num = instanceTemplate.getNumberOfInstances();
            LOG.info("Starting {} node(s) with roles {}", num,
                instanceTemplate.getRoles());
            Set<? extends NodeMetadata> nodes = computeService
                .runNodesWithTag(clusterSpec.getClusterName(), num, template);
            LOG.info("Nodes started: {}", nodes);
            return nodes;
          }
        }
View Full Code Here

      ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      Cluster cluster = entry.getValue().getCluster();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext =
        ComputeServiceContextBuilder.build(clusterSpec);
      ComputeService computeService = computeServiceContext.getComputeService();
      Credentials credentials = new Credentials(
          Iterables.get(cluster.getInstances(), 0).getLoginCredentials().identity,
          clusterSpec.readPrivateKey());
      try {
        LOG.info("Running configuration script");
        Payload script = newStringPayload(statementBuilder.render(OsFamily.UNIX));
        LOG.debug("Running script:\n{}", script.getRawContent());
        computeService.runScriptOnNodesMatching(
            toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles()),
            script,
            RunScriptOptions.Builder.overrideCredentialsWith(credentials));
        LOG.info("Configuration script run completed");
      } catch (RunScriptOnNodesException e) {
View Full Code Here

    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {
      ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      Cluster cluster = entry.getValue().getCluster();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      ComputeService computeService = computeServiceContext.getComputeService();
      Credentials credentials = new Credentials(
          clusterSpec.getClusterUser(),
          clusterSpec.getPrivateKey());
      try {
        LOG.info("Running configuration script");
        if (LOG.isDebugEnabled())
          LOG.debug("Running script:\n{}", statementBuilder.render(OsFamily.UNIX));
        computeService.runScriptOnNodesMatching(
            toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles()),
            statementBuilder,
            RunScriptOptions.Builder.overrideCredentialsWith(credentials));
        LOG.info("Configuration script run completed");
      } catch (RunScriptOnNodesException e) {
View Full Code Here

    for (Entry<InstanceTemplate, ClusterActionEvent> entry : eventMap.entrySet()) {

      ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      final StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      final ComputeService computeService = computeServiceContext.getComputeService();
      Credentials credentials = new Credentials(clusterSpec.getIdentity(), clusterSpec.getCredential());
     
      if (numberAllocated == 0) {
        for (ComputeMetadata compute : computeService.listNodes()) {
          if (!(compute instanceof NodeMetadata)) {
            throw new IllegalArgumentException("Not an instance of NodeMetadata: " + compute);
          }
          nodes.add((NodeMetadata) compute);
        }
      }
      int num = entry.getKey().getNumberOfInstances();
      final List<NodeMetadata> templateNodes =
        nodes.subList(numberAllocated, numberAllocated + num);
      numberAllocated += num;
     
      instances.addAll(getInstances(credentials,
          entry.getKey().getRoles(), templateNodes));
     
      futures.add(executorService.submit(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          LOG.info("Running script");
          if (LOG.isDebugEnabled())
            LOG.debug("Running script:\n{}", statementBuilder.render(OsFamily.UNIX));
          computeService.runScriptOnNodesMatching(
              Predicates.in(templateNodes),
              statementBuilder);
          LOG.info("Script run completed");
          return null;
        }
View Full Code Here

      final InstanceTemplate instanceTemplate = entry.getKey();
      final ClusterSpec clusterSpec = entry.getValue().getClusterSpec();
      final int maxNumberOfRetries = clusterSpec.getMaxStartupRetries();
      StatementBuilder statementBuilder = entry.getValue().getStatementBuilder();
      ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      final ComputeService computeService =
        computeServiceContext.getComputeService();
      final Template template = buildTemplate(clusterSpec, computeService,
          statementBuilder, entry.getValue().getTemplateBuilderStrategy());
     
      Future<Set<? extends NodeMetadata>> nodesFuture = executorService.submit(
View Full Code Here

    handlerMap.put("hadoop-datanode", handler);
    handlerMap.put("hadoop-tasktracker", handler);

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

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
   
    // 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
View Full Code Here

    handlerMap.put("hadoop-datanode", handler);
    handlerMap.put("hadoop-tasktracker", handler);

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

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
   
    // here is a scenario when jt+nn does not fail
    // but the dn+tt one node fails 3, then in the retry fails 2
View Full Code Here

   }

   @Test(groups = { "integration", "live" }, singleThreaded = true)
   public void testCreateImage() throws RunNodesException, InterruptedException, ExecutionException {

      ComputeService computeService = view.getComputeService();

      Optional<ImageExtension> imageExtension = computeService.getImageExtension();

      assertTrue(imageExtension.isPresent(), "image extension was not present");

      Template template = getNodeTemplate();

      NodeMetadata node = Iterables.getOnlyElement(computeService.createNodesInGroup("test-create-image", 1, template));

      checkReachable(node);

      logger.info("Creating image from node %s, started with template: %s", node, template);

      ImageTemplate newImageTemplate = imageExtension.get().buildImageTemplateFromNode("test-create-image",
               node.getId());

      Image image = imageExtension.get().createImage(newImageTemplate).get();

      logger.info("Image created: %s", image);

      assertEquals("test-create-image", image.getName());

      imageId = image.getId();

      computeService.destroyNode(node.getId());

      Optional<? extends Image> optImage = getImage();

      assertTrue(optImage.isPresent());
View Full Code Here

TOP

Related Classes of org.jclouds.compute.ComputeService

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.