Package org.jclouds.openstack.cinder.v1.domain

Examples of org.jclouds.openstack.cinder.v1.domain.Volume


      this.client = client;
   }

   public boolean apply(Attachment attachment) {
      logger.trace("looking for volume %s", attachment.getVolumeId());
      Volume volume = Iterables.getOnlyElement(client.describeVolumesInRegion(attachment
               .getRegion(), attachment.getVolumeId()));
      if (volume.getAttachments().size() == 0) {
         return false;
      }
      Attachment lastAttachment = Sets.newTreeSet(volume.getAttachments()).last();
      logger.trace("%s: looking for status %s: currently: %s", lastAttachment,
               Attachment.Status.ATTACHED, lastAttachment.getStatus());
      return lastAttachment.getStatus() == Attachment.Status.ATTACHED;
   }
View Full Code Here


      this.client = client;
   }

   public boolean apply(Attachment attachment) {
      logger.trace("looking for volume %s", attachment.getVolumeId());
      Volume volume = Iterables.getOnlyElement(client.describeVolumesInRegion(attachment
              .getRegion(), attachment.getVolumeId()));

      /*If attachment size is 0 volume is detached for sure.*/
      if (volume.getAttachments().size() == 0) {
         return true;
      }

      /* But if attachment size is > 0, then the attachment could be in any state.
         * So we need to check if the status is DETACHED (return true) or not (return false).
         */
      Attachment lastAttachment = getLast(volume.getAttachments());
      logger.trace("%s: looking for status %s: currently: %s", lastAttachment,
              Attachment.Status.DETACHED, lastAttachment.getStatus());
      return lastAttachment.getStatus() == Attachment.Status.DETACHED;
   }
View Full Code Here

      }
      currentText = new StringBuilder();
   }

   private Volume newVolume() {
      Volume volume = new Volume(region, id, size, snapshotId, availabilityZone, volumeStatus, createTime, attachments);
      id = null;
      size = 0;
      snapshotId = null;
      availabilityZone = null;
      volumeStatus = null;
View Full Code Here

   public void testApplyInputStream() {
      DateService dateService = injector.getInstance(DateService.class);
      InputStream is = getClass().getResourceAsStream("/created_volume.xml");

      Volume expected = new Volume(Region.US_EAST_1, "vol-2a21e543", 1, null,
            "us-east-1a", Volume.Status.CREATING, dateService
                        .iso8601DateParse("2009-12-28T05:42:53.000Z"), Sets
                        .<Attachment> newLinkedHashSet());

      CreateVolumeResponseHandler handler = injector.getInstance(CreateVolumeResponseHandler.class);
      addDefaultRegionToHandler(handler);
      Volume result = factory.create(handler).parse(is);

      assertEquals(result, expected);
   }
View Full Code Here

         }

      });

      // 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

   public void testApplyInputStream() {
      DateService dateService = injector.getInstance(DateService.class);
      InputStream is = getClass().getResourceAsStream("/describe_volumes.xml");

      Set<Volume> expected = Sets.newLinkedHashSet();
      expected.add(new Volume(defaultRegion, "vol-2a21e543", 1, null, "us-east-1a",
               Volume.Status.AVAILABLE, dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"),
               Sets.<Attachment> newLinkedHashSet()));
      expected.add(new Volume(defaultRegion, "vol-4282672b", 800, "snap-536d1b3a",
               "us-east-1a", Volume.Status.IN_USE, dateService
                        .iso8601DateParse("2008-05-07T11:51:50.000Z"), Sets
                        .<Attachment> newHashSet(new Attachment(defaultRegion, "vol-4282672b", "i-6058a509",
                                 "/dev/sdh", Attachment.Status.ATTACHED, dateService
                                          .iso8601DateParse("2008-05-07T12:51:50.000Z")))));
View Full Code Here

      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_volumes_single.xml", "text/xml")).build();

      EC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filterVolumes, filterResponse);

      Volume volume = getOnlyElement(apiWhenExist.getElasticBlockStoreApi().get().describeVolumesInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("snapshot-id", "snap-536d1b3a")
                      .build()));

      assertEquals(volume.getId(), "vol-4282672b");
   }
View Full Code Here

   void testDescribeVolumes() {
      String region = defaultRegion;
      SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region));
      assertNotNull(allResults);
      assertFalse(allResults.isEmpty());
      Volume volume = allResults.last();
      SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion(region, volume.getId()));
      assertNotNull(result);
      Volume compare = result.last();
      assertEquals(compare, volume);
   }
View Full Code Here

   void testDescribeVolumesWithFilter() {
      String region = defaultRegion;
      SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region));
      assertNotNull(allResults);
      assertFalse(allResults.isEmpty());
      Volume volume = allResults.last();
      SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegionWithFilter(region,
              ImmutableMultimap.<String, String>builder()
                      .put("volume-id", volume.getId()).build()));
      assertNotNull(result);
      Volume compare = result.last();
      assertEquals(compare, volume);
   }
View Full Code Here

   void testDescribeVolumesWithInvalidFilter() {
      String region = defaultRegion;
      SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region));
      assertNotNull(allResults);
      assertFalse(allResults.isEmpty());
      Volume volume = allResults.last();
      SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegionWithFilter(region,
              ImmutableMultimap.<String, String>builder()
                      .put("invalid-filter", volume.getId()).build()));
   }
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.cinder.v1.domain.Volume

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.