Package org.jclouds.compute

Examples of org.jclouds.compute.ComputeService


      overrides.setProperty(NodePoolProperties.BASEDIR, basedir);
      // note no ssh module since we are stub and not trying ssh, yet
      overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
      overrides.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpass");

      ComputeService stub = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").endpoint("gooend")
               .apiVersion("1.1").buildVersion("1.1-2").overrides(overrides).buildInjector()
               .getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>() {
               }, Backend.class)).get();

      assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend");
      assertEquals(stub.getContext().unwrap().getProviderMetadata().getApiMetadata().getVersion(), "1.1");
      assertEquals(stub.getContext().unwrap().getProviderMetadata().getApiMetadata().getBuildVersion().get(), "1.1-2");

      stub.getContext().close();
      new File(basedir).delete();

   }
View Full Code Here


    @Test
    public void testNodeCreateLive() throws InterruptedException {
        if (isComputeLiveConfigured()) {
            createManagedComputeService("cloudservers-us", false);
            ComputeService computeService = getOsgiService(ComputeService.class, 1000000L);
            Thread.sleep(DEFAULT_TIMEOUT);
            System.err.println(executeCommand("jclouds:image-list"));
            System.err.println(executeCommand("jclouds:node-create --imageId " + image + " --locationId " + location + " " + group));
            System.err.println(executeCommand("jclouds:group-runscript -d ls -u " + user + " " + group));
            assertTrue("Expected at least one node", computeService.listNodes().size() >= 1);
        }
    }
View Full Code Here

    @Test
    public void testCreateNodeLive() throws InterruptedException {
        if (isComputeLiveConfigured()) {
            createManagedComputeService("aws-ec2", false);
            ComputeService computeService = getOsgiService(ComputeService.class,1000000L);

            System.err.println(executeCommand("jclouds:image-list"));
            System.err.println(executeCommand("jclouds:node-create --imageId " + image + " --locationId " + location + " " + group));
            System.err.println(executeCommand("jclouds:group-runscript -d ls -u " + user + " " + group));
            assertTrue("Expected at least one node", computeService.listNodes().size() >= 1);
        }
    }
View Full Code Here

               .payload(payloadFromResourceWithContentType("/new_machine.json", "application/json; charset=UTF-8"))
               .build();

      requestResponseMap.put(createMachine, createMachineResponse);

      ComputeService apiThatCreatesNode = requestsSendResponses(requestResponseMap.build(), new AbstractModule() {

         @Override
         protected void configure() {
            // predicatable node names
            final AtomicInteger suffix = new AtomicInteger();
            bind(new TypeLiteral<Supplier<String>>() {
            }).toInstance(new Supplier<String>() {

               @Override
               public String get() {
                  return suffix.getAndIncrement() + "";
               }

            });
            bind(SshKeyPairGenerator.class).toInstance(new SshKeyPairGenerator() {

               @Override
               public Map<String, String> get() {
                  return keyPair;
               }

            });
           
         }

      }, onlySW);

      TemplateOptions options = apiThatCreatesNode.templateOptions().blockUntilRunning(false);
     
      assertTrue(options.as(JoyentCloudTemplateOptions.class).shouldGenerateKey().get());

      NodeMetadata node = Iterables.getOnlyElement(apiThatCreatesNode.createNodesInGroup("test", 1, options));
     
      assertEquals(node.getCredentials().getPrivateKey(), keyPair.get("private"));
   }
View Full Code Here

   @Argument(name = "id", description = "The id of the node.", required = true, multiValued = false)
   private String id;

   @Override
   protected Object doExecute() throws Exception {
      ComputeService service = null;
      try {
         service = getComputeService();
      } catch (Throwable t) {
         System.err.println(t.getMessage());
         return null;
      }
      service.suspendNode(id);
      return null;
   }
View Full Code Here

   @Argument(name = "id", description = "The ids of the nodes to destroy.", required = true, multiValued = true)
   private List<String> ids;

   @Override
   protected Object doExecute() throws Exception {
      ComputeService service = null;
      try {
         service = getComputeService();
      } catch (Throwable t) {
         System.err.println(t.getMessage());
         return null;
      }

      for (String id : ids) {
         service.destroyNode(id);
         cacheProvider.getProviderCacheForType(Constants.ACTIVE_NODE_CACHE).remove(
                  service.getContext().unwrap().getId(), id);
         cacheProvider.getProviderCacheForType(Constants.INACTIVE_NODE_CACHE).remove(
                  service.getContext().unwrap().getId(), id);
         cacheProvider.getProviderCacheForType(Constants.SUSPENDED_NODE_CACHE).remove(
                  service.getContext().unwrap().getId(), id);
      }
      return null;
   }
View Full Code Here

   private RecipeManager recipeManager = new RecipeManagerImpl();

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

   public List<ComputeService> getComputeServices() {
      if (provider == null && api == null) {
         return computeServices;
      } else {
         try {
            ComputeService service = getComputeService();
            return Collections.singletonList(service);
         } catch (Throwable t) {
            return Collections.emptyList();
         }
      }
View Full Code Here

   protected ComputeService getComputeService() throws IOException {
      if ((name == null && provider == null && api == null) &&(computeServices != null && computeServices.size() == 1)) {
         return computeServices.get(0);
      }

      ComputeService computeService = null;
      if (propertiesFile != null) {
         EnvHelper.loadProperties(new File(propertiesFile));
      }
      String providerValue = EnvHelper.getComputeProvider(provider);
      String apiValue = EnvHelper.getComputeApi(api);
View Full Code Here

@Command(scope = "jclouds", name = "node-destroy-all", description = "Destroys all nodes.")
public class NodeDestroyAllCommand extends ComputeCommandWithOptions {

   @Override
   protected Object doExecute() throws Exception {
      ComputeService service = null;
      try {
         service = getComputeService();
      } catch (Throwable t) {
         System.err.println(t.getMessage());
         return null;
      }
      Set<? extends NodeMetadata> nodeMetadatas = service.destroyNodesMatching(new Predicate<NodeMetadata>() {
         @Override
         public boolean apply(@Nullable NodeMetadata input) {
            return true;
         }
      });
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.