Package org.jclouds.ec2

Examples of org.jclouds.ec2.EC2Client


   @SuppressWarnings("unchecked")
   @Test
   public void testDestroyNodeDisassociatesAndReleasesIpThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Client client = createMock(EC2Client.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressClient ipClient = createMock(ElasticIPAddressClient.class);
      InstanceClient instanceClient = createMock(InstanceClient.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andReturn("1.1.1.1");

      expect(client.getElasticIPAddressServices()).andReturn(ipClient).atLeastOnce();
      ipClient.disassociateAddressInRegion("region", "1.1.1.1");
      ipClient.releaseAddressInRegion("region", "1.1.1.1");
      elasticIpCache.invalidate(new RegionAndName("region", "i-blah"));


      expect(client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
      expect(instanceClient.terminateInstancesInRegion("region", "i-blah")).andReturn(null);
      expect(getNode.getNode("region/i-blah")).andReturn(node);

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


*/
public class DescribeAvailabilityZonesInRegionTest {
   @Test
   public void testDescribeAvailabilityZonesInRegion_BestEffort() {
      IMocksControl control = createControl();
      EC2Client client = control.createMock(EC2Client.class);
      AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class);
      AvailabilityZoneInfo info1 = control.createMock(AvailabilityZoneInfo.class);
      AvailabilityZoneInfo info2 = control.createMock(AvailabilityZoneInfo.class);
      HttpCommand command = control.createMock(HttpCommand.class);
      HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...",
               command, null);

      expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
      expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion1")).andReturn(
               ImmutableSet.of(info1));
      expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception);
      expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion2")).andReturn(
               ImmutableSet.of(info2));
View Full Code Here

   @SuppressWarnings("unchecked")
   @Test
   public void testDestroyNodeSafeOnCacheMissThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Client client = createMock(EC2Client.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressClient ipClient = createMock(ElasticIPAddressClient.class);
      InstanceClient instanceClient = createMock(InstanceClient.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andThrow(new CacheLoader.InvalidCacheLoadException(null));

      expect(client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
      expect(instanceClient.terminateInstancesInRegion("region", "i-blah")).andReturn(null);
      expect(getNode.getNode("region/i-blah")).andReturn(node);

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

   }

   @Test
   public void testDescribeAvailabilityZonesInRegion_RethrowIfNoneFound() {
      IMocksControl control = createControl();
      EC2Client client = control.createMock(EC2Client.class);
      AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class);
      HttpCommand command = control.createMock(HttpCommand.class);
      HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...",
               command, null);

      expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
      expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception);

      Set<String> regions = ImmutableSet.of("inaccessibleRegion");
      control.replay();
View Full Code Here

   }

   @Test
   public void testDescribeAvailabilityZonesInRegion_NoZones() {
      IMocksControl control = createControl();
      EC2Client client = control.createMock(EC2Client.class);
      AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class);

      expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
      expect(regionClient.describeAvailabilityZonesInRegion("emptyRegion")).andReturn(
               ImmutableSet.<AvailabilityZoneInfo> of());

      Set<String> regions = ImmutableSet.of("emptyRegion");
      control.replay();
View Full Code Here

   @SuppressWarnings("unchecked")
   @Test
   public void testDestroyNodeSafeOnCacheExecutionExceptionThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Client client = createMock(EC2Client.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressClient ipClient = createMock(ElasticIPAddressClient.class);
      InstanceClient instanceClient = createMock(InstanceClient.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andThrow(new ExecutionException(null));

      expect(client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
      expect(instanceClient.terminateInstancesInRegion("region", "i-blah")).andReturn(null);
      expect(getNode.getNode("region/i-blah")).andReturn(node);

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

   @SuppressWarnings("unchecked")
   @Test
   public void testApply() throws ExecutionException {

      EC2ImageParser parser = createMock(EC2ImageParser.class);
      EC2Client caller = createMock(EC2Client.class);
      AMIClient client = createMock(AMIClient.class);

      org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class);
      Image image = createNiceMock(Image.class);
      Set<? extends org.jclouds.ec2.domain.Image> images = ImmutableSet.<org.jclouds.ec2.domain.Image> of(ec2Image);

      expect(caller.getAMIServices()).andReturn(client).atLeastOnce();
      expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(Set.class.cast(images));
      expect(parser.apply(ec2Image)).andReturn(image);

      replay(caller);
      replay(image);
View Full Code Here

   @SuppressWarnings("unchecked")
   @Test(expectedExceptions = ExecutionException.class)
   public void testApplyNotFoundMakesExecutionException() throws ExecutionException {

      EC2ImageParser parser = createMock(EC2ImageParser.class);
      EC2Client caller = createMock(EC2Client.class);
      AMIClient client = createMock(AMIClient.class);

      org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class);
      Image image = createNiceMock(Image.class);
      Set<? extends org.jclouds.ec2.domain.Image> images = ImmutableSet.<org.jclouds.ec2.domain.Image> of(ec2Image);

      expect(caller.getAMIServices()).andReturn(client).atLeastOnce();
      expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(Set.class.cast(images));
      expect(parser.apply(ec2Image)).andThrow(new ResourceNotFoundException());

      replay(caller);
      replay(image);
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

      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.