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

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


The following commit(s) were added to refs/heads/4.20 by this push:
     new 454bba0f3e5 server: report distinct read/write volume throttle rates 
(#14048)
454bba0f3e5 is described below

commit 454bba0f3e5fec14652d291cec58f049d4a3bcd9
Author: The Kernel Nomad <[email protected]>
AuthorDate: Thu Oct 29 06:33:16 2026 -0400

    server: report distinct read/write volume throttle rates (#14048)
    
    VolumeJoinDaoImpl.newVolumeResponse fed the read getter to the write setter 
for
    the byte rate, and the write getter to the read setter for IOPS, so 
listVolumes
    returned the read byte-rate as the write byte-rate and the write IOPS as the
    read IOPS for any volume with asymmetric throttling. Map each rate to its 
own
    field. The assignments are extracted into setThrottleRates so the mapping is
    covered by a unit test.
---
 .../com/cloud/api/query/dao/VolumeJoinDaoImpl.java    | 12 ++++++++----
 .../cloud/api/query/dao/VolumeJoinDaoImplTest.java    | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git 
a/server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java 
b/server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java
index 4f5d984c969..6367f472b18 100644
--- a/server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/VolumeJoinDaoImpl.java
@@ -77,6 +77,13 @@ public class VolumeJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<VolumeJo
         _count = "select count(distinct id) from volume_view WHERE ";
     }
 
+    protected void setThrottleRates(VolumeResponse volResponse, VolumeJoinVO 
volume) {
+        volResponse.setBytesReadRate(volume.getBytesReadRate());
+        volResponse.setBytesWriteRate(volume.getBytesWriteRate());
+        volResponse.setIopsReadRate(volume.getIopsReadRate());
+        volResponse.setIopsWriteRate(volume.getIopsWriteRate());
+    }
+
     @Override
     public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO 
volume) {
         VolumeResponse volResponse = new VolumeResponse();
@@ -206,10 +213,7 @@ public class VolumeJoinDaoImpl extends 
GenericDaoBaseWithTagInformation<VolumeJo
             if (view == ResponseView.Full) {
                 volResponse.setStorageType(volume.isUseLocalStorage() ? 
ServiceOffering.StorageType.local.toString() : 
ServiceOffering.StorageType.shared.toString());
             }
-            volResponse.setBytesReadRate(volume.getBytesReadRate());
-            volResponse.setBytesWriteRate(volume.getBytesReadRate());
-            volResponse.setIopsReadRate(volume.getIopsWriteRate());
-            volResponse.setIopsWriteRate(volume.getIopsWriteRate());
+            setThrottleRates(volResponse, volume);
 
         }
 
diff --git 
a/server/src/test/java/com/cloud/api/query/dao/VolumeJoinDaoImplTest.java 
b/server/src/test/java/com/cloud/api/query/dao/VolumeJoinDaoImplTest.java
index 8ac60f4a64c..e4e0b69de7d 100755
--- a/server/src/test/java/com/cloud/api/query/dao/VolumeJoinDaoImplTest.java
+++ b/server/src/test/java/com/cloud/api/query/dao/VolumeJoinDaoImplTest.java
@@ -18,10 +18,12 @@ package com.cloud.api.query.dao;
 
 import com.cloud.api.query.vo.VolumeJoinVO;
 import org.apache.cloudstack.api.response.VolumeResponse;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
+import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -43,4 +45,21 @@ public class VolumeJoinDaoImplTest extends 
GenericDaoBaseWithTagInformationBaseT
         testUpdateTagInformation(_volumeJoinDaoImpl, volume, volumeResponse);
     }
 
+    @Test
+    public void testSetThrottleRatesMapsReadAndWriteDistinctly() {
+        VolumeJoinVO vol = Mockito.mock(VolumeJoinVO.class);
+        Mockito.when(vol.getBytesReadRate()).thenReturn(100L);
+        Mockito.when(vol.getBytesWriteRate()).thenReturn(200L);
+        Mockito.when(vol.getIopsReadRate()).thenReturn(300L);
+        Mockito.when(vol.getIopsWriteRate()).thenReturn(400L);
+
+        VolumeResponse response = new VolumeResponse();
+        _volumeJoinDaoImpl.setThrottleRates(response, vol);
+
+        Assert.assertEquals(Long.valueOf(100L), response.getBytesReadRate());
+        Assert.assertEquals(Long.valueOf(200L), response.getBytesWriteRate());
+        Assert.assertEquals(Long.valueOf(300L), response.getIopsReadRate());
+        Assert.assertEquals(Long.valueOf(400L), response.getIopsWriteRate());
+    }
+
 }

Reply via email to