Package org.jclouds.compute

Examples of org.jclouds.compute.ComputeServiceContext


@Test(groups = "unit", testName = "ServerManagerContextBuilderTest")
public class SmartOSManagerComputeServiceContextBuilderTest {

   @Test
   public void testCanBuildWithApiMetadata() {
      ComputeServiceContext context = ContextBuilder.newBuilder(new SmartOSApiMetadata())
               .modules(ImmutableSet.<Module> of(getSshModule())).build(ComputeServiceContext.class);
      context.close();
   }
View Full Code Here


      context.close();
   }

   @Test
   public void testCanBuildById() {
      ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh")
               .modules(ImmutableSet.<Module> of(getSshModule())).build(ComputeServiceContext.class);
      context.close();
   }
View Full Code Here

   public void testCanBuildWithOverridingProperties() {
      Properties overrides = new Properties();
      overrides.setProperty("smartos-ssh.endpoint", "http://host");
      overrides.setProperty("smartos-ssh.api-version", "1");

      ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh")
               .modules(ImmutableSet.<Module> of(getSshModule())).overrides(overrides)
               .build(ComputeServiceContext.class);

      context.close();
   }
View Full Code Here

      context.close();
   }

   @Test
   public void testUnwrapIsCorrectType() {
      ComputeServiceContext context = ContextBuilder.newBuilder("smartos-ssh")
               .modules(ImmutableSet.<Module> of(getSshModule())).build(ComputeServiceContext.class);

      assertEquals(context.unwrap().getClass(), ContextImpl.class);

      context.close();
   }
View Full Code Here

                    builder = builder.modules(ImmutableSet.<Module>of(credentialStore));
                }

                builder = builder.name(id).credentials(identity, credential).overrides(props);

                ComputeServiceContext context = builder.build(ComputeServiceContext.class);

                ComputeService service = null;

                if (enableEventSupport) {
                    service = new ComputeServiceEventProxy(bundleContext, context.getComputeService());
                } else {
                    service = context.getComputeService();
                }

                newRegistration = bundleContext.registerService(
                        ComputeService.class.getName(), service, properties);
View Full Code Here

         globalAdminClient.getAccountClient().deleteAccount(testAccount.getId());
      }
   }

   private void checkAuthAsUser(ApiKeyPair keyPair) {
      ComputeServiceContext context = createView(credentialsAsProperties(keyPair), setupModules());

      CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
      Set<Account> accounts = client.getAccountClient().listAccounts();

      assert accounts.size() > 0;

      context.close();
   }
View Full Code Here

      TemplateOptions options = view.getComputeService().templateOptions();

      options.authorizePublicKey(keyPair.get("public")).as(AWSEC2TemplateOptions.class);

      ComputeServiceContext noSshContext = null;
      try {
         noSshContext = createView(setupProperties(), ImmutableSet.<Module> of(new Log4JLoggingModule()));

         Set<? extends NodeMetadata> nodes = noSshContext.getComputeService().createNodesInGroup(group, 1, options);

         NodeMetadata first = get(nodes, 0);
         assert first.getCredentials() != null : first;
         assert first.getCredentials().identity != null : first;
         // credentials should not be present as the import public key call doesn't have access to
         // the related private key
         assert first.getCredentials().credential == null : first;

         AWSRunningInstance instance = getInstance(instanceClient, first.getProviderId());

         assertEquals(instance.getKeyName(), "jclouds#" + group);

         Map<? extends NodeMetadata, ExecResponse> responses = view.getComputeService()
               .runScriptOnNodesMatching(
                     runningInGroup(group),
                     exec("echo hello"),
                     overrideLoginCredentials(
                           LoginCredentials.builder().user(first.getCredentials().identity)
                                 .privateKey(keyPair.get("private")).build()).wrapInInitScript(false).runAsRoot(false));

         ExecResponse hello = getOnlyElement(responses.values());
         assertEquals(hello.getOutput().trim(), "hello");

      } finally {
         noSshContext.close();
         view.getComputeService().destroyNodesMatching(inGroup(group));
      }
   }
View Full Code Here

      }
   }

   @Test(enabled = true) //, dependsOnMethods = "testCompareSizes")
   public void testAutoIpAllocation() throws Exception {
      ComputeServiceContext context = null;
      String group = this.group + "aip";
      try {
         Properties overrides = setupProperties();
         overrides.setProperty(EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "true");

         context = createView(overrides, setupModules());

         // create a node
         Set<? extends NodeMetadata> nodes =
               context.getComputeService().createNodesInGroup(group, 1);
         assertEquals(nodes.size(), 1, "One node should have been created");

         // Get public IPs (We should get 1)
         NodeMetadata node = Iterables.get(nodes, 0);
         String region = node.getLocation().getParent().getId();
         Set<String> publicIps = node.getPublicAddresses();
         assertFalse(Iterables.isEmpty(publicIps), String.format("no public addresses attached to node %s", node));
         assertEquals(Iterables.size(publicIps), 1);

         // Check that the address is public and port 22 is accessible
         String ip = Iterables.getOnlyElement(publicIps);
         assertFalse(InetAddresses2.isPrivateIPAddress(ip));
         HostAndPort socket = HostAndPort.fromParts(ip, 22);
         assertTrue(socketTester.apply(socket), String.format("failed to open socket %s on node %s", socket, node));

         // check that there is an elastic ip correlating to it
         EC2Client ec2 = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi());
         Set<PublicIpInstanceIdPair> ipidpairs =
               ec2.getElasticIPAddressServices().describeAddressesInRegion(region, publicIps.toArray(new String[0]));
         assertEquals(ipidpairs.size(), 1, String.format("there should only be one address pair (%s)",
               Iterables.toString(ipidpairs)));

         // check that the elastic ip is in node.publicAddresses
         PublicIpInstanceIdPair ipidpair = Iterables.get(ipidpairs, 0);
         assertEquals(region + "/" + ipidpair.getInstanceId(), node.getId());
        
         // delete the node
         context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));

         // check that the ip is deallocated
         Set<PublicIpInstanceIdPair> ipidcheck =
                 ec2.getElasticIPAddressServices().describeAddressesInRegion(region, ipidpair.getPublicIp());
         assertTrue(Iterables.isEmpty(ipidcheck), String.format("there should be no address pairs (%s)",
               Iterables.toString(ipidcheck)));
      } finally {
         context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
         if (context != null)
            context.close();
      }
   }
View Full Code Here

   public void testTemplateBuilderCanUseImageIdWithoutFetchingAllImages() throws Exception {
      Template defaultTemplate = view.getComputeService().templateBuilder().build();
      String defaultImageId = defaultTemplate.getImage().getId();
      String defaultImageProviderId = defaultTemplate.getImage().getProviderId();

      ComputeServiceContext context = null;
      try {
         // Track http commands
         final List<HttpCommand> commandsInvoked = Lists.newArrayList();
         context = createView(
               setupProperties(),
               ImmutableSet.<Module> of(new Log4JLoggingModule(),
                     TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)));
        
         Template template = context.getComputeService().templateBuilder().imageId(defaultImageId)
                  .build();
         assertEquals(template.getImage(), defaultTemplate.getImage());

         Collection<HttpCommand> filteredCommandsInvoked = Collections2.filter(commandsInvoked, new Predicate<HttpCommand>() {
            private final Collection<Method> ignored = ImmutableSet.of(
                     AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", DescribeRegionsOptions[].class),
                     AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class));
            @Override
            public boolean apply(HttpCommand input) {
               return !ignored.contains(getInvokerOfRequest(input));
            }
         });
        
         assert filteredCommandsInvoked.size() == 1 : commandsInvoked;
         assertEquals(getInvokerOfRequestAtIndex(filteredCommandsInvoked, 0), AMIAsyncClient.class
                  .getMethod("describeImagesInRegion", String.class, DescribeImagesOptions[].class));
         assertDescribeImagesOptionsEquals((DescribeImagesOptions[])getArgsForRequestAtIndex(filteredCommandsInvoked, 0).get(1),
                  defaultImageProviderId);

      } finally {
         if (context != null)
            context.close();
      }
   }
View Full Code Here

      if (shouldIgnoreInstanceTemplate(instanceTemplate)) {
        continue; // skip execution if this group of instances is not in target
      }
      StatementBuilder statementBuilder = new StatementBuilder();

      ComputeServiceContext computeServiceContext = getCompute().apply(clusterSpec);
      FirewallManager firewallManager = new FirewallManager(
          computeServiceContext, clusterSpec, newCluster);

      VelocityEngine velocityEngine = TemplateUtils.newVelocityEngine();
View Full Code Here

TOP

Related Classes of org.jclouds.compute.ComputeServiceContext

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.