Package org.jclouds.ec2

Examples of org.jclouds.ec2.EC2Client


@Test(groups = "unit", testName = "CreateUniqueKeyPairTest")
public class CreateUniqueKeyPairTest {
  
   @Test
   public void testApply() throws UnknownHostException {
      final EC2Client client = createMock(EC2Client.class);
      KeyPairClient keyClient = createMock(KeyPairClient.class);
      KeyPair pair = createMock(KeyPair.class);

      expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce();

      expect(keyClient.createKeyPairInRegion("region", "jclouds#group#1")).andReturn(pair);

      replay(client);
      replay(keyClient);
View Full Code Here


   }

   @SuppressWarnings( { "unchecked" })
   @Test
   public void testApplyWithIllegalStateException() throws UnknownHostException {
      final EC2Client client = createMock(EC2Client.class);
      KeyPairClient keyClient = createMock(KeyPairClient.class);
      final Supplier<String> uniqueIdSupplier = createMock(Supplier.class);

      KeyPair pair = createMock(KeyPair.class);

      expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce();

      expect(uniqueIdSupplier.get()).andReturn("1");
      expect(keyClient.createKeyPairInRegion("region", "jclouds#group#1")).andThrow(new IllegalStateException());
      expect(uniqueIdSupplier.get()).andReturn("2");
      expect(keyClient.createKeyPairInRegion("region", "jclouds#group#2")).andReturn(pair);
View Full Code Here

    if (EC2ApiMetadata.CONTEXT_TOKEN.isAssignableFrom(computeServiceContext.getBackendType())) {
      // This code (or something like it) may be added to jclouds (see
      // http://code.google.com/p/jclouds/issues/detail?id=336).
      // Until then we need this temporary workaround.
      String region = AWSUtils.parseHandle(Iterables.get(instances, 0).getId())[0];
      EC2Client ec2Client = computeServiceContext.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi();
      String groupName = "jclouds#" + clusterSpec.getClusterName();
      for (String cidr : cidrs) {
        for (int port : ports) {
          try {
            ec2Client.getSecurityGroupServices()
              .authorizeSecurityGroupIngressInRegion(region, groupName,
                                                     IpProtocol.TCP, port, port, cidr);
          } catch(IllegalStateException e) {
            LOG.warn(e.getMessage());
            /* ignore, it means that this permission was already granted */
 
View Full Code Here

  }

  @Test(timeout = TestConstants.ITEST_TIMEOUT)
  public void testFirewallAuthorizationIsIdempotent() throws IOException {
    if (EC2ApiMetadata.CONTEXT_TOKEN.isAssignableFrom(context.getBackendType())) {
      EC2Client ec2Client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi();

      String groupName = "jclouds#" + clusterSpec.getClusterName();

      ec2Client.getSecurityGroupServices()
          .createSecurityGroupInRegion(region, groupName, "group description");
      try {
        manager.addRule(
          Rule.create().destination(instances).port(23344)
        );

        /* The second call should not throw an exception. */
        manager.addRule(
          Rule.create().destination(instances).port(23344)
        );

        manager.authorizeAllRules();
      } finally {
        ec2Client.getSecurityGroupServices()
            .deleteSecurityGroupInRegion(region, groupName);
      }
    }
  }
View Full Code Here

    if (EC2ApiMetadata.CONTEXT_TOKEN.isAssignableFrom(computeServiceContext.getBackendType())) {
      // This code (or something like it) may be added to jclouds (see
      // http://code.google.com/p/jclouds/issues/detail?id=336).
      // Until then we need this temporary workaround.
      String region = AWSUtils.parseHandle(Iterables.get(instances, 0).getId())[0];
      EC2Client ec2Client = computeServiceContext.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi();
      String groupName = "jclouds#" + clusterSpec.getClusterName();
      for (String cidr : cidrs) {
        for (int port : ports) {
          try {
            ec2Client.getSecurityGroupServices()
              .authorizeSecurityGroupIngressInRegion(region, groupName,
                IpProtocol.TCP, port, port, cidr);
          } catch(IllegalStateException e) {
            LOG.warn(e.getMessage());
            /* ignore, it means that this permission was already granted */
 
View Full Code Here

  }

  @Test(timeout = TestConstants.ITEST_TIMEOUT)
  public void testFirewallAuthorizationIsIdempotent() throws IOException {
    if (EC2ApiMetadata.CONTEXT_TOKEN.isAssignableFrom(context.getBackendType())) {
      EC2Client ec2Client = context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi();

      String groupName = "jclouds#" + clusterSpec.getClusterName();

      ec2Client.getSecurityGroupServices()
          .createSecurityGroupInRegion(region, groupName, "group description");
      try {
        manager.addRule(
          Rule.create().destination(instances).port(23344)
        );

        /* The second call should not throw an exception. */
        manager.addRule(
          Rule.create().destination(instances).port(23344)
        );

      } finally {
        ec2Client.getSecurityGroupServices()
            .deleteSecurityGroupInRegion(region, groupName);
      }
    }
  }
View Full Code Here

          EC2Client) {
      // This code (or something like it) may be added to jclouds (see
      // http://code.google.com/p/jclouds/issues/detail?id=336).
      // Until then we need this temporary workaround.
      String region = AWSUtils.parseHandle(Iterables.get(instances, 0).getId())[0];
      EC2Client ec2Client = EC2Client.class.cast(
          computeServiceContext.getProviderSpecificContext().getApi());
      String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" + region;
      for (String cidr : cidrs) {
        for (int port : ports) {
          ec2Client.getSecurityGroupServices()
            .authorizeSecurityGroupIngressInRegion(region, groupName,
                IpProtocol.TCP, port, port, cidr);
        }
      }
    }
View Full Code Here

          EC2Client) {
      // This code (or something like it) may be added to jclouds (see
      // http://code.google.com/p/jclouds/issues/detail?id=336).
      // Until then we need this temporary workaround.
      String region = AWSUtils.parseHandle(Iterables.get(instances, 0).getId())[0];
      EC2Client ec2Client = EC2Client.class.cast(
          computeServiceContext.getProviderSpecificContext().getApi());
      String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" + region;
      for (String cidr : cidrs) {
        for (int port : ports) {
          try {
            ec2Client.getSecurityGroupServices()
              .authorizeSecurityGroupIngressInRegion(region, groupName,
                IpProtocol.TCP, port, port, cidr);
          } catch(IllegalStateException e) {
            LOG.warn(e.getMessage());
            /* ignore, it means that this permission was already granted */
 
View Full Code Here

  }

  @Test
  public void testFirewallAuthorizationIsIdempotent() throws IOException {
    if (context.getProviderSpecificContext().getApi() instanceof EC2Client) {
      EC2Client ec2Client = EC2Client.class.cast(
          context.getProviderSpecificContext().getApi());
      String groupName = "jclouds#" + spec.getClusterName() + "#" + REGION;

      ec2Client.getSecurityGroupServices()
          .createSecurityGroupInRegion(REGION, groupName, "group description");
      try {
        FirewallSettings.authorizeIngress(context, instances, spec, 23344);

        /* The second call should not throw an exception. */
        FirewallSettings.authorizeIngress(context, instances, spec, 23344);

      } finally {
        ec2Client.getSecurityGroupServices()
            .deleteSecurityGroupInRegion(REGION, groupName);
      }
    }
  }
View Full Code Here

      RestContext<EC2Client, EC2AsyncClient> context = ContextBuilder
        .newBuilder("aws-ec2").credentials(accesskeyid, secretkey)
        .build();

      // Get a synchronous client
      EC2Client client = context.getApi();

      try {
         if (command.equals("create")) {

            KeyPair pair = createKeyPair(client, name);
View Full Code Here

TOP

Related Classes of org.jclouds.ec2.EC2Client

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.