GutoVeronezi commented on code in PR #6581:
URL: https://github.com/apache/cloudstack/pull/6581#discussion_r936627445


##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2396,6 +2397,35 @@ private void checkDeviceId(Long deviceId, VolumeInfo 
volumeToAttach, UserVmVO vm
         return volumeToAttach;
     }
 
+    protected void validateIfVmHasBackups(UserVmVO vm, boolean attach) {
+        if ((vm.getBackupOfferingId() != null || 
CollectionUtils.isNotEmpty(vm.getBackupVolumeList())) &&
+                
BooleanUtils.isFalse(BackupManager.BackupEnableAttachDetachVolumes.value())) {
+            String errorMsg = "Unable to detach volume, cannot detach volume 
from a VM that has backups. First remove the VM from the backup offering or "
+                    + "set the global configuration 
'backup.enable.attach.detach.of.volumes' to true.";
+            if (attach)
+                errorMsg = "Unable to attach volume, please specify a VM that 
does not have any backups or set the global configuration "
+                        + "'backup.enable.attach.detach.of.volumes' to true.";
+            throw new InvalidParameterValueException(errorMsg);
+        }
+    }
+
+    protected String createVolumeInfoFromVolumes(List<VolumeVO> vmVolumes) {
+        try {
+            List<Backup.VolumeInfo> list = new ArrayList<>();
+            for (VolumeVO vol : vmVolumes) {
+                list.add(new Backup.VolumeInfo(vol.getUuid(), vol.getPath(), 
vol.getVolumeType(), vol.getSize()));
+            }
+            return new Gson().toJson(list.toArray(), 
Backup.VolumeInfo[].class);

Review Comment:
   We could use `GsonHelper` here.



##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java:
##########
@@ -736,12 +739,14 @@ protected VolumeVO updateVolume(VirtualDisk disk, 
Map<VirtualDisk, VolumeVO> dis
         volume.setPath(volumeName);
         volume.setPoolId(poolId);
         VirtualMachineDiskInfo diskInfo = getDiskInfo(vmToImport, poolId, 
volumeName);
-        volume.setChainInfo(new Gson().toJson(diskInfo));
+        volume.setChainInfo(GSON.toJson(diskInfo));

Review Comment:
   We could use `GsonHelper` here, instead of instantiate a new object.



##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2396,6 +2397,35 @@ private void checkDeviceId(Long deviceId, VolumeInfo 
volumeToAttach, UserVmVO vm
         return volumeToAttach;
     }
 
+    protected void validateIfVmHasBackups(UserVmVO vm, boolean attach) {
+        if ((vm.getBackupOfferingId() != null || 
CollectionUtils.isNotEmpty(vm.getBackupVolumeList())) &&

Review Comment:
   We could invert this `if` to reduce indentation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to