Copilot commented on code in PR #12805:
URL: https://github.com/apache/cloudstack/pull/12805#discussion_r2960931814


##########
plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java:
##########
@@ -552,7 +556,14 @@ public Pair<Long, Long> getBackupStorageStats(Long zoneId) 
{
     @Override
     public void syncBackupStorageStats(Long zoneId) {
         final List<BackupRepository> repositories = 
backupRepositoryDao.listByZoneAndProvider(zoneId, getName());
+        if (CollectionUtils.isEmpty(repositories)) {
+            return;
+        }
         final Host host = 
resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM,
 zoneId);
+        if (host == null) {
+            logger.warn("Unable to find a running KVM host in zone {} to sync 
backup storage stats", zoneId);
+            return;
+        }

Review Comment:
   `syncBackupStorageStats()` now returns early when no running KVM host is 
found. Please add a unit test covering this branch (mock 
`findOneRandomRunningHostByHypervisor(...)` to return `null`) and assert the 
method does not throw and does not call 
`agentManager.send(...)`/`backupRepositoryDao.updateCapacity(...)`.



##########
plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java:
##########
@@ -63,6 +63,7 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
+import org.apache.commons.collections.CollectionUtils;
 import java.util.Comparator;
 import java.util.Date;

Review Comment:
   The new `CollectionUtils` import is placed in the middle of the 
`java.util.*` imports, which breaks the existing import grouping in this file 
and makes the imports harder to scan. Please move 
`org.apache.commons.collections.CollectionUtils` alongside the other `org.*` 
imports and keep the `java.*` imports contiguous.



##########
plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java:
##########
@@ -471,6 +472,9 @@ public boolean deleteBackup(Backup backup, boolean forced) {
         } else {
             host = 
resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM,
 backup.getZoneId());
         }
+        if (host == null) {
+            throw new CloudRuntimeException(String.format("Unable to find a 
running KVM host in zone %d to delete backup %s", backup.getZoneId(), 
backup.getUuid()));
+        }

Review Comment:
   This change adds a new failure path when no running KVM host is available. 
Please add a unit test that mocks 
`getVMHypervisorHost(...)`/`findOneRandomRunningHostByHypervisor(...)` to 
return `null` and asserts that `deleteBackup()` fails with the expected 
`CloudRuntimeException` message (instead of NPE).



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