This is an automated email from the ASF dual-hosted git repository.

harikrishna pushed a commit to branch CheckVolumeAPI
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit e67c43497e2fdb25ee7d2dfbd2fb9d40e2bf724b
Author: Harikrishna Patnala <[email protected]>
AuthorDate: Thu Feb 1 13:13:23 2024 +0530

    used volume name in logs
---
 .../api/command/user/volume/CheckAndRepairVolumeCmd.java     |  3 ++-
 .../main/java/com/cloud/storage/VolumeApiServiceImpl.java    | 12 ++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java
index 4be4b99c0ab..ce1559c4342 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java
@@ -74,8 +74,9 @@ public class CheckAndRepairVolumeCmd extends BaseCmd {
             if (repairType == null) {
                 throw new InvalidParameterValueException(String.format("Repair 
parameter can only take the following values: %s" + 
Arrays.toString(RepairValues.values())));
             }
+            return repair.toLowerCase();
         }
-        return repair.toLowerCase();
+        return null;
     }
 
     /////////////////////////////////////////////////////
diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 6a89ac4d4d9..0daa82a4bf2 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -1895,14 +1895,14 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
         Account caller = CallContext.current().getCallingAccount();
         _accountMgr.checkAccess(caller, null, true, volume);
 
-        Long volumeId = volume.getId();
+        String volumeName = volume.getName();
         Long vmId = volume.getInstanceId();
         if (vmId != null) {
-            validateVMforCheckVolumeOperation(vmId, volumeId);
+            validateVMforCheckVolumeOperation(vmId, volumeName);
         }
 
         if (volume.getState() != Volume.State.Ready) {
-            throw new InvalidParameterValueException(String.format("VolumeId: 
%d is not in Ready state", volumeId));
+            throw new InvalidParameterValueException(String.format("Volume: %s 
is not in Ready state", volumeName));
         }
 
         HypervisorType hypervisorType = 
_volsDao.getHypervisorType(volume.getId());
@@ -1911,17 +1911,17 @@ public class VolumeApiServiceImpl extends ManagerBase 
implements VolumeApiServic
         }
     }
 
-    private void validateVMforCheckVolumeOperation(Long vmId, Long volumeId) {
+    private void validateVMforCheckVolumeOperation(Long vmId, String 
volumeName) {
         Account caller = CallContext.current().getCallingAccount();
         UserVmVO vm = _userVmDao.findById(vmId);
         if (vm == null) {
-            throw new InvalidParameterValueException(String.format("VM not 
found, please check the VM to which this volume %d is attached", volumeId));
+            throw new InvalidParameterValueException(String.format("VM not 
found, please check the VM to which this volume %s is attached", volumeName));
         }
 
         _accountMgr.checkAccess(caller, null, true, vm);
 
         if (vm.getState() != State.Stopped) {
-            throw new InvalidParameterValueException(String.format("VM to 
which the volume %d is attached should be in stopped state", volumeId));
+            throw new InvalidParameterValueException(String.format("VM to 
which the volume %s is attached should be in stopped state", volumeName));
         }
     }
 

Reply via email to