Examples of ElasticBlockStoreApi


Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

               + ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
      }
      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      ElasticBlockStoreApi ebsClient = view.unwrapApi(EC2Api.class)
               .getElasticBlockStoreApi().get();

      String group = this.group + "e";
      int volumeSize = 8;
     
      final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();

      Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

         @Override
         public boolean apply(Location arg0) {
            return arg0.getScope() == LocationScope.ZONE
                     && arg0.getParent().getId().equals(template.getLocation().getId());
         }

      });

      // create volume only to make a snapshot
      Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
      // Sleep for 5 seconds to make sure the volume creation finishes.
      Thread.sleep(5000);

      Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
      ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());

      template.getOptions().as(EC2TemplateOptions.class)//
               // .unmapDeviceNamed("/dev/foo)
               .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
               .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
               .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);

      try {
         NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));

         // TODO figure out how to validate the ephemeral drive. perhaps with df -k?

         Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
                  .getParent().getId(), node.getProviderId());

         BlockDevice device = devices.get("/dev/sdn");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());

         device = devices.get("/dev/sdo");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());
         // check volume's snapshot id
         assertEquals(snapshot.getId(), volume.getSnapshotId());

      } finally {
         client.destroyNodesMatching(NodePredicates.inGroup(group));
         ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
      }
   }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

      log.fatal("Cannot create a new volume in the [region] : "+region
          +", [zone] : "+zone+" of Iaas : "+iaasInfo);
      return null;
    }
   
    ElasticBlockStoreApi blockStoreApi = context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();
   
    Volume volume = blockStoreApi.createVolumeInAvailabilityZone(zone, sizeGB);
   
    if (volume == null) {
      log.fatal("Volume creation was unsuccessful. [region] : " + region
          + ", [zone] : " + zone + " of Iaas : " + iaasInfo);
      return null;
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

      log.fatal("Cannot attach the volume [id]: "+volumeId+" in the [region] : "+region
          +", [zone] : "+zone+" of Iaas : "+iaasInfo);
      return null;
    }
   
    ElasticBlockStoreApi blockStoreApi = context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();

        Volume.Status volumeStatus = this.getVolumeStatus(blockStoreApi, region, volumeId);

        if(log.isDebugEnabled()){
            log.debug("Volume " + volumeId + " is in state " + volumeStatus);
        }

        while(volumeStatus != Volume.Status.AVAILABLE){
            try {
                // TODO Use a proper mechanism to wait till volume becomes available.
                Thread.sleep(1000);
                volumeStatus = this.getVolumeStatus(blockStoreApi, region, volumeId);
                if(log.isDebugEnabled()){
                    log.debug("Volume " + volumeId + " is still NOT in AVAILABLE. Current State=" + volumeStatus);
                }
            } catch (InterruptedException e) {
                // Ignoring the exception
            }
        }
        if(log.isDebugEnabled()){
            log.debug("Volume " + volumeId + " became  AVAILABLE");
        }

    Attachment attachment = blockStoreApi.attachVolumeInRegion(region, volumeId, instanceId, device);

    if (attachment == null) {
      log.fatal("Volume [id]: "+volumeId+" attachment for instance [id]: "+instanceId
          +" was unsuccessful. [region] : " + region
          + ", [zone] : " + zone + " of Iaas : " + iaasInfo);
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

          +" of the [region] : "+region
          +" of Iaas : "+iaasInfo);
      return;
    }

    ElasticBlockStoreApi blockStoreApi = context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();

        Set<Volume> volumeDescriptions = blockStoreApi.describeVolumesInRegion(region, volumeId);
        Iterator<Volume> it = volumeDescriptions.iterator();

        while(it.hasNext()){
            Volume.Status status  = it.next().getStatus();

            if(status == Volume.Status.AVAILABLE){
                log.warn(String.format("Volume %s is already in AVAILABLE state. Volume seems to be detached somehow", volumeId));
                return;
            }
        }

    blockStoreApi.detachVolumeInRegion(region, volumeId, true, DetachVolumeOptions.Builder.fromInstance(instanceId));

    log.info("Detachment of Volume [id]: "+volumeId+" from instance [id]: "+instanceId
        +" was successful. [region] : " + region
        + " of Iaas : " + iaasInfo);
  }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

      log.fatal("Cannot delete the volume [id]: "+volumeId+" of the [region] : "+region
          +" of Iaas : "+iaasInfo);
      return;
    }
   
    ElasticBlockStoreApi blockStoreApi = context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();
    blockStoreApi.deleteVolumeInRegion(region, volumeId);
   
    log.info("Deletion of Volume [id]: "+volumeId+" was successful. [region] : " + region
        + " of Iaas : " + iaasInfo);
  }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

               + ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
      }
      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      ElasticBlockStoreApi ebsClient = view.unwrapApi(EC2Api.class)
               .getElasticBlockStoreApi().get();

      String group = this.group + "e";
      int volumeSize = 8;
     
      final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();

      Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

         @Override
         public boolean apply(Location arg0) {
            return arg0.getScope() == LocationScope.ZONE
                     && arg0.getParent().getId().equals(template.getLocation().getId());
         }

      });

      // create volume only to make a snapshot
      Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
      // Sleep for 5 seconds to make sure the volume creation finishes.
      Thread.sleep(5000);

      Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
      ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());

      template.getOptions().as(EC2TemplateOptions.class)//
               // .unmapDeviceNamed("/dev/foo)
               .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
               .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
               .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);

      try {
         NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));

         // TODO figure out how to validate the ephemeral drive. perhaps with df -k?

         Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
                  .getParent().getId(), node.getProviderId());

         BlockDevice device = devices.get("/dev/sdn");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());

         device = devices.get("/dev/sdo");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());
         // check volume's snapshot id
         assertEquals(snapshot.getId(), volume.getSnapshotId());

      } finally {
         client.destroyNodesMatching(NodePredicates.inGroup(group));
         ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
      }
   }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

*/
@Test(groups = "unit", testName = "NovaEC2ElasticBlockStoreApiTest")
public class NovaEC2ElasticBlockStoreExpectApiTest extends BaseNovaEC2RestApiExpectTest {

   public void testDescribeVolumesWithNovaEC2Status() {
      ElasticBlockStoreApi client = requestsSendResponses(
            describeAvailabilityZonesRequest,
            describeAvailabilityZonesResponse,
            HttpRequest.builder().method("POST")
                  .endpoint("http://localhost:8773/services/Cloud/")
                  .addHeader("Host", "localhost:8773")
                  .payload(payloadFromStringWithContentType("Action=DescribeVolumes&Signature=AvRznSzGExM%2Buaj2JJj66wq4v4f%2BakicyLooRDtC0t0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
            HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_describe_volumes.xml")).build()
                                                          ).getElasticBlockStoreApi().get();

      Set<Volume> expected = ImmutableSet.of(Volume
            .builder()
            .status(Volume.Status.AVAILABLE)
            .availabilityZone("nova")
            .region("nova")
            .id("vol-00000007")
            .size(1)
            .attachments(Attachment.builder().region("nova").build())
            .createTime(dateService.iso8601SecondsDateParse("2012-04-10T10:39:52Z"))
            .build());

      assertEquals(client.describeVolumesInRegion("nova"), expected);
   }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

@Test(groups = "unit", testName = "NovaEC2ElasticBlockStoreApiTest")
public class NovaEC2ElasticBlockStoreExpectApiTest extends BaseNovaEC2RestApiExpectTest {

   public void testDescribeVolumesWithNovaEC2Status() {
      ElasticBlockStoreApi client = requestsSendResponses(
            describeAvailabilityZonesRequest,
            describeAvailabilityZonesResponse,
            HttpRequest.builder().method("POST")
                  .endpoint("http://localhost:8773/services/Cloud/")
                  .addHeader("Host", "localhost:8773")
                  .payload(payloadFromStringWithContentType("Action=DescribeVolumes&Signature=AvRznSzGExM%2Buaj2JJj66wq4v4f%2BakicyLooRDtC0t0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
            HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_describe_volumes.xml")).build()
                                                          ).getElasticBlockStoreApi().get();

      Set<Volume> expected = ImmutableSet.of(Volume
            .builder()
            .status(Volume.Status.AVAILABLE)
            .availabilityZone("nova")
            .region("nova")
            .id("vol-00000007")
            .size(1)
            .attachments(Attachment.builder().region("nova").build())
            .createTime(dateService.iso8601SecondsDateParse("2012-04-10T10:39:52Z"))
            .build());

      assertEquals(client.describeVolumesInRegion("nova"), expected);
   }
View Full Code Here

Examples of org.jclouds.ec2.features.ElasticBlockStoreApi

               + ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
      }
      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      ElasticBlockStoreApi ebsClient = view.unwrapApi(EC2Api.class)
               .getElasticBlockStoreApi().get();

      String group = this.group + "e";
      int volumeSize = 8;
     
      final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();

      Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

         @Override
         public boolean apply(Location arg0) {
            return arg0.getScope() == LocationScope.ZONE
                     && arg0.getParent().getId().equals(template.getLocation().getId());
         }

      });

      // create volume only to make a snapshot
      Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
      // Sleep for 5 seconds to make sure the volume creation finishes.
      Thread.sleep(5000);

      Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
      ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());

      template.getOptions().as(EC2TemplateOptions.class)//
               // .unmapDeviceNamed("/dev/foo)
               .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
               .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
               .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);

      try {
         NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));

         // TODO figure out how to validate the ephemeral drive. perhaps with df -k?

         Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
                  .getParent().getId(), node.getProviderId());

         BlockDevice device = devices.get("/dev/sdn");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());

         device = devices.get("/dev/sdo");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());

         volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
                  device.getVolumeId()));
         // check volume size
         assertEquals(volumeSize, volume.getSize());
         // check volume's snapshot id
         assertEquals(snapshot.getId(), volume.getSnapshotId());

      } finally {
         client.destroyNodesMatching(NodePredicates.inGroup(group));
         ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.