abh1sar commented on code in PR #10140:
URL: https://github.com/apache/cloudstack/pull/10140#discussion_r2228995688


##########
server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java:
##########
@@ -926,6 +1058,224 @@ private Backup.VolumeInfo 
getVolumeInfo(List<Backup.VolumeInfo> backedUpVolumes,
         return null;
     }
 
+    @Override
+    public void checkVmDisksSizeAgainstBackup(List<VmDiskInfo> vmDiskInfoList, 
Backup backup) {
+        List<VmDiskInfo> vmDiskInfoListFromBackup = 
getDataDiskInfoListFromBackup(backup);
+        int index = 0;
+        if (vmDiskInfoList.size() != vmDiskInfoListFromBackup.size()) {
+            throw new InvalidParameterValueException("Unable to create 
Instance from Backup " +
+                    "as the backup has a different number of disks than the 
Instance.");
+        }
+        for (VmDiskInfo vmDiskInfo : vmDiskInfoList) {
+            if (index < vmDiskInfoListFromBackup.size()) {
+                if (vmDiskInfo.getSize() < 
vmDiskInfoListFromBackup.get(index).getSize()) {
+                    throw new InvalidParameterValueException(
+                            String.format("Instance volume size %d[GiB] cannot 
be less than the backed-up volume size %d[GiB].",
+                            vmDiskInfo.getSize(), 
vmDiskInfoListFromBackup.get(index).getSize()));
+                }
+            }
+            index++;
+        }
+    }
+
+    @Override
+    public VmDiskInfo getRootDiskInfoFromBackup(Backup backup) {
+        List<Backup.VolumeInfo> volumes = backup.getBackedUpVolumes();
+        VmDiskInfo rootDiskOffering = null;
+        if (volumes == null || volumes.isEmpty()) {
+            throw new CloudRuntimeException("Failed to get backed-up volumes 
info from backup");
+        }
+        for (Backup.VolumeInfo volume : volumes) {
+            if (volume.getType() == Volume.Type.ROOT) {
+                DiskOfferingVO diskOffering = 
diskOfferingDao.findByUuid(volume.getDiskOfferingId());
+                if (diskOffering == null) {
+                    throw new CloudRuntimeException(String.format("Unable to 
find the root disk offering with uuid (%s) " +
+                            "stored in backup. Please specify a valid root 
disk offering id while creating the instance",
+                            volume.getDiskOfferingId()));
+                }
+                Long size = volume.getSize() / (1024 * 1024 * 1024);
+                rootDiskOffering = new VmDiskInfo(diskOffering, size, 
volume.getMinIops(), volume.getMaxIops());
+            }
+        }
+        if (rootDiskOffering == null) {
+            throw new CloudRuntimeException("Failed to get the root disk in 
backed-up volumes info from backup");
+        }
+        return rootDiskOffering;
+    }
+
+    @Override
+    public List<VmDiskInfo> getDataDiskInfoListFromBackup(Backup backup) {
+        List<VmDiskInfo> vmDiskInfoList = new ArrayList<>();
+        List<Backup.VolumeInfo> volumes = backup.getBackedUpVolumes();
+        if (volumes == null || volumes.isEmpty()) {
+            throw new CloudRuntimeException("Failed to get backed-up Volumes 
info from backup");
+        }
+        for (Backup.VolumeInfo volume : volumes) {
+            if (volume.getType() == Volume.Type.DATADISK) {
+                DiskOfferingVO diskOffering = 
diskOfferingDao.findByUuid(volume.getDiskOfferingId());
+                if (diskOffering == null || 
diskOffering.getState().equals(DiskOffering.State.Inactive)) {
+                    throw new CloudRuntimeException("Unable to find the disk 
offering with uuid (" + volume.getDiskOfferingId() + ") stored in backup. " +
+                            "Please specify a valid disk offering id while 
creating the instance");
+                }
+                Long size = volume.getSize() / (1024 * 1024 * 1024);
+                vmDiskInfoList.add(new VmDiskInfo(diskOffering, size, 
volume.getMinIops(), volume.getMaxIops(), volume.getDeviceId()));
+            }
+        }
+        return vmDiskInfoList;
+    }
+
+    private List<String> parseAddressString(String input) {
+        if (input == null) return null;
+        return Arrays.stream(input.split(","))
+                .map(s -> "null".equalsIgnoreCase(s.trim()) ? null : s.trim())
+                .collect(Collectors.toList());
+    }

Review Comment:
   no, will remove



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to