BryanMLima commented on code in PR #6589:
URL: https://github.com/apache/cloudstack/pull/6589#discussion_r1572775460


##########
engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java:
##########
@@ -141,32 +141,37 @@ public List<Backup> syncBackups(Long zoneId, Long vmId, 
List<Backup> externalBac
 
     @Override
     public BackupResponse newBackupResponse(Backup backup) {
-        VMInstanceVO vm = 
vmInstanceDao.findByIdIncludingRemoved(backup.getVmId());
-        AccountVO account = 
accountDao.findByIdIncludingRemoved(vm.getAccountId());
-        DomainVO domain = domainDao.findByIdIncludingRemoved(vm.getDomainId());
-        DataCenterVO zone = 
dataCenterDao.findByIdIncludingRemoved(vm.getDataCenterId());
-        BackupOffering offering = 
backupOfferingDao.findByIdIncludingRemoved(vm.getBackupOfferingId());
-
-        BackupResponse response = new BackupResponse();
-        response.setId(backup.getUuid());
-        response.setVmId(vm.getUuid());
-        response.setVmName(vm.getHostName());
-        response.setExternalId(backup.getExternalId());
-        response.setType(backup.getType());
-        response.setDate(backup.getDate());
-        response.setSize(backup.getSize());
-        response.setProtectedSize(backup.getProtectedSize());
-        response.setStatus(backup.getStatus());
-        response.setVolumes(new 
Gson().toJson(vm.getBackupVolumeList().toArray(), Backup.VolumeInfo[].class));
-        response.setBackupOfferingId(offering.getUuid());
-        response.setBackupOffering(offering.getName());
-        response.setAccountId(account.getUuid());
-        response.setAccount(account.getAccountName());
-        response.setDomainId(domain.getUuid());
-        response.setDomain(domain.getName());
-        response.setZoneId(zone.getUuid());
-        response.setZone(zone.getName());
-        response.setObjectName("backup");
-        return response;
+        try {
+            VMInstanceVO vm = 
vmInstanceDao.findByIdIncludingRemoved(backup.getVmId());
+            AccountVO account = 
accountDao.findByIdIncludingRemoved(vm.getAccountId());
+            DomainVO domain = 
domainDao.findByIdIncludingRemoved(vm.getDomainId());
+            DataCenterVO zone = 
dataCenterDao.findByIdIncludingRemoved(vm.getDataCenterId());
+            BackupOffering offering = 
backupOfferingDao.findByIdIncludingRemoved(backup.getBackupOfferingId());
+
+            BackupResponse response = new BackupResponse();
+            response.setId(backup.getUuid());
+            response.setVmId(vm.getUuid());
+            response.setVmName(vm.getHostName());
+            response.setExternalId(backup.getExternalId());
+            response.setType(backup.getType());
+            response.setDate(backup.getDate());
+            response.setSize(backup.getSize());
+            response.setProtectedSize(backup.getProtectedSize());
+            response.setStatus(backup.getStatus());
+            
response.setVolumes(GSON.toJson(backup.getBackupVolumeList().toArray(), 
Backup.VolumeInfo[].class));
+            response.setBackupOfferingId(offering.getUuid());
+            response.setBackupOffering(offering.getName());
+            response.setAccountId(account.getUuid());
+            response.setAccount(account.getAccountName());
+            response.setDomainId(domain.getUuid());
+            response.setDomain(domain.getName());
+            response.setZoneId(zone.getUuid());
+            response.setZone(zone.getName());
+            response.setObjectName("backup");
+            return response;
+        } catch (Exception e) {

Review Comment:
   Same here.



##########
engine/schema/src/main/resources/META-INF/db/schema-41720to41800.sql:
##########
@@ -1562,6 +1562,21 @@ DELETE FROM `cloud`.`snapshot_store_ref`
 WHERE store_role = "Primary" AND store_id IN (SELECT id FROM storage_pool 
WHERE removed IS NOT NULL);
 
 
+ALTER TABLE `cloud`.`backups` ADD backup_volumes TEXT NULL COMMENT 'details of 
backedup volumes';
+
+-- Populate column backup_volumes in table backups with a GSON
+-- formed by concatenating the UUID, type, size, path and deviceId
+-- of the volumes of VMs that have some backup offering.
+-- Required for the restore process of a backup using Veeam
+-- The Gson result can be in one of this formats:
+-- When VM has only ROOT disk: 
[{"uuid":"<uuid>","type":"<type>","size":<size>,"path":"<path>","deviceId":<deviceId>}]
+-- When VM has more tha one disk: 
[{"uuid":"<uuid>","type":"<type>","size":<size>,"path":"<path>","deviceId":<deviceId>},
 
{"uuid":"<uuid>","type":"<type>","size":<size>,"path":"<path>","deviceId":<deviceId>},
 <>]
+UPDATE `cloud`.`backups` b INNER JOIN `cloud`.`vm_instance` vm ON b.vm_id = 
vm.id SET b.backup_volumes = (SELECT CONCAT("[", GROUP_CONCAT( 
CONCAT("{\"uuid\":\"", v.uuid, "\",\"type\":\"", v.volume_type, "\",\"size\":", 
v.`size`, ",\"path\":\"", v.path, "\",\"deviceId\":", v.device_id, "}") 
SEPARATOR ","), "]") FROM `cloud`.`volumes` v WHERE v.instance_id = vm.id);

Review Comment:
   The volumes are already removed, I think it is better to keep all of them 
consistent. But I do not see a problem adding this condition.



##########
plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java:
##########
@@ -397,6 +404,30 @@ public void doInTransactionWithoutResult(TransactionStatus 
status) {
         });
     }
 
+    protected String createVolumeInfoFromVolumes(List<String> paths) {
+        List<VolumeVO> vmVolumes = new ArrayList<>();
+        try {
+            for (String diskName : paths) {
+                VolumeVO volumeVO = volumeDao.findByPath(diskName);
+                if (volumeVO != null) {
+                    vmVolumes.add(volumeVO);
+                }
+            }
+            List<Backup.VolumeInfo> list = new ArrayList<>();
+            for (VolumeVO vol : vmVolumes) {
+                list.add(new Backup.VolumeInfo(vol.getUuid(), vol.getPath(), 
vol.getVolumeType(), vol.getSize(), vol.getDeviceId()));
+            }
+            return new Gson().toJson(list.toArray(), 
Backup.VolumeInfo[].class);
+        } catch (Exception e) {

Review Comment:
   Speaking to @SadiJr, he mentioned that an exception was thrown when trying 
to parse to a JSON object, though, he does not remember exactly which. In this 
case, I think I prefer to keep the catch all here, just to be safe.



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