@Test
  public void testExtendingDiskWithQuota() {
    Guid quotaId = Guid.newGuid();

    DiskImage oldDiskImage = createDiskImage();
    oldDiskImage.setQuotaId(quotaId);
    oldDiskImage.setSize(
        SizeConverter.convert(3, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES)
            .longValue());

    DiskImage newDiskImage = createDiskImage();
    newDiskImage.setQuotaId(quotaId);
    newDiskImage.setSize(
        SizeConverter.convert(5, SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES)
            .longValue());

    UpdateVmDiskParameters parameters =
        new UpdateVmDiskParameters(vmId, diskImageGuid, newDiskImage);
    long diskExtendingDiffInGB =
        newDiskImage.getSizeInGigabytes() - oldDiskImage.getSizeInGigabytes();

    when(diskDao.get(diskImageGuid)).thenReturn(oldDiskImage);
    initializeCommand(parameters);

    QuotaStorageConsumptionParameter consumptionParameter =
        (QuotaStorageConsumptionParameter) command.getQuotaStorageConsumptionParameters().get(0);
    assertEquals(consumptionParameter.getRequestedStorageGB().longValue(), diskExtendingDiffInGB);
  }
Esempio n. 2
0
 @Override
 public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
   if (getParameters().isRemoveDisks()) {
     List<QuotaConsumptionParameter> list = new ArrayList<>();
     ImagesHandler.fillImagesBySnapshots(getVm());
     for (DiskImage disk : getVm().getDiskList()) {
       for (DiskImage snapshot : disk.getSnapshots()) {
         if (snapshot.getQuotaId() != null && !Guid.Empty.equals(snapshot.getQuotaId())) {
           if (snapshot.getActive()) {
             list.add(
                 new QuotaStorageConsumptionParameter(
                     snapshot.getQuotaId(),
                     null,
                     QuotaStorageConsumptionParameter.QuotaAction.RELEASE,
                     disk.getStorageIds().get(0),
                     (double) snapshot.getSizeInGigabytes()));
           } else {
             list.add(
                 new QuotaStorageConsumptionParameter(
                     snapshot.getQuotaId(),
                     null,
                     QuotaStorageConsumptionParameter.QuotaAction.RELEASE,
                     disk.getStorageIds().get(0),
                     snapshot.getActualSize()));
           }
         }
       }
     }
     return list;
   }
   return Collections.emptyList();
 }
  @Override
  public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
    List<QuotaConsumptionParameter> list = new ArrayList<>();
    for (DiskImage disk : diskInfoDestinationMap.values()) {
      list.add(
          new QuotaStorageConsumptionParameter(
              disk.getQuotaId(),
              null,
              QuotaConsumptionParameter.QuotaAction.CONSUME,
              disk.getStorageIds().get(0),
              (double)
                  (disk.getSizeInGigabytes()
                      * getParameters().getVmsCount()
                      * getBlockSparseInitSizeInGB())));
    }

    return list;
  }
 @Override
 public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() {
   List<QuotaConsumptionParameter> list = new ArrayList<>();
   fetchImageTemplates();
   if (imageTemplates != null) {
     for (DiskImage disk : imageTemplates) {
       if (disk.getQuotaId() != null && !Guid.Empty.equals(disk.getQuotaId())) {
         for (Guid storageId : disk.getStorageIds()) {
           list.add(
               new QuotaStorageConsumptionParameter(
                   disk.getQuotaId(),
                   null,
                   QuotaStorageConsumptionParameter.QuotaAction.RELEASE,
                   storageId,
                   (double) disk.getSizeInGigabytes()));
         }
       }
     }
   }
   return list;
 }
 private void updateDiskSize(DiskImage diskImage) {
   long sizeToAddInGigabytes = Long.parseLong(getSizeExtend().getEntity());
   if (sizeToAddInGigabytes > 0) {
     diskImage.setSizeInGigabytes(diskImage.getSizeInGigabytes() + sizeToAddInGigabytes);
   }
 }