nitin-maharana commented on a change in pull request #2486: [CLOUDSTACK-10323] 
Allow changing disk offering during volume migration 
URL: https://github.com/apache/cloudstack/pull/2486#discussion_r175389327
 
 

 ##########
 File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
 ##########
 @@ -2097,26 +2079,102 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
             }
         }
 
-        return orchestrateMigrateVolume(vol.getId(), destPool.getId(), 
liveMigrateVolume);
+        return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, 
newDiskOffering);
     }
 
-    private Volume orchestrateMigrateVolume(long volumeId, long destPoolId, 
boolean liveMigrateVolume) {
-        VolumeVO vol = _volsDao.findById(volumeId);
-        assert (vol != null);
-        StoragePool destPool = 
(StoragePool)dataStoreMgr.getDataStore(destPoolId, DataStoreRole.Primary);
-        assert (destPool != null);
+    /**
+     * Retrieve the new disk offering UUID that might be sent to replace the 
current one in the volume being migrated.
+     * If no disk offering UUID is provided we return null. Otherwise, we 
perform the following checks.
+     * <ul>
+     *  <li>Is the disk offering UUID entered valid? If not, an  {@link 
InvalidParameterValueException} is thrown;
+     *  <li>If the disk offering was already removed, we thrown an {@link 
InvalidParameterValueException} is thrown;
+     *  <li>We then check if the user executing the operation has access to 
the given disk offering.
+     * </ul>
+     *
+     * If all checks pass, we move forward returning the disk offering object.
+     */
+    private DiskOfferingVO retrieveAndValidateNewDiskOffering(MigrateVolumeCmd 
cmd) {
+        String newDiskOfferingUuid = cmd.getNewDiskOfferingUuid();
+        if (org.apache.commons.lang.StringUtils.isBlank(newDiskOfferingUuid)) {
+            return null;
+        }
+        DiskOfferingVO newDiskOffering = 
_diskOfferingDao.findByUuid(newDiskOfferingUuid);
+        if (newDiskOffering == null) {
+            throw new InvalidParameterValueException(String.format("The disk 
offering informed is not valid [id=%s].", newDiskOfferingUuid));
+        }
+        if (newDiskOffering.getRemoved() != null) {
+            throw new InvalidParameterValueException(String.format("We cannot 
assign a removed disk offering [id=%s] to a volume. ", 
newDiskOffering.getUuid()));
+        }
+        Account caller = CallContext.current().getCallingAccount();
+        _accountMgr.checkAccess(caller, newDiskOffering);
+        return newDiskOffering;
+    }
+
+    /**
+     * Performs the validations required for replacing the disk offering while 
migrating the volume of storage. If no new disk offering is provided, we do not 
execute any validation.
+     * If a disk offering is informed, we then proceed with the following 
checks.
+     * <ul>
 
 Review comment:
   Same here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to