Skip to content

Commit cb43664

Browse files
committed
Address reviews
1 parent 5ac7a39 commit cb43664

File tree

5 files changed

+56
-27
lines changed

5 files changed

+56
-27
lines changed

core/src/main/java/com/cloud/agent/api/storage/MigrateVolumeCommand.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class MigrateVolumeCommand extends Command {
3636
String attachedVmName;
3737
Volume.Type volumeType;
3838
String hostGuidInTargetCluster;
39-
Long newIops;
39+
Long newMaxIops;
40+
Long newMinIops;
4041

4142
private DataTO srcData;
4243
private DataTO destData;
@@ -147,12 +148,20 @@ public int getWaitInMillSeconds() {
147148

148149
public String getChainInfo() { return chainInfo; }
149150

150-
public void setNewIops(Long newIops) {
151-
this.newIops = newIops;
151+
public Long getNewMinIops() {
152+
return newMinIops;
152153
}
153154

154-
public Long getNewIops() {
155-
return newIops;
155+
public void setNewMinIops(Long newMinIops) {
156+
this.newMinIops = newMinIops;
157+
}
158+
159+
public Long getNewMaxIops() {
160+
return newMaxIops;
161+
}
162+
163+
public void setNewMaxIops(Long newMaxIops) {
164+
this.newMaxIops = newMaxIops;
156165
}
157166

158167
@Override

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
import com.cloud.storage.ScopeType;
7575
import com.cloud.storage.Snapshot.Type;
7676
import com.cloud.storage.SnapshotVO;
77-
import com.cloud.storage.DiskOfferingVO;
7877
import com.cloud.storage.StorageManager;
7978
import com.cloud.storage.Storage.StoragePoolType;
8079
import com.cloud.storage.StoragePool;
@@ -548,15 +547,6 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
548547
StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
549548
MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval, volume.getChainInfo());
550549

551-
if (volume.getpayload() instanceof DiskOfferingVO) {
552-
DiskOfferingVO offering = (DiskOfferingVO) volume.getpayload();
553-
Long newIops = null;
554-
if (offering.getIopsReadRate() != null && offering.getIopsWriteRate() != null) {
555-
newIops = offering.getIopsReadRate() + offering.getIopsWriteRate();
556-
}
557-
command.setNewIops(newIops);
558-
}
559-
560550
if (srcPool.getParent() != 0) {
561551
command.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
562552
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5217,7 +5217,14 @@ private Answer execute(MigrateVolumeCommand cmd) {
52175217
* Sets the disk IOPS limitation, if the {@link MigrateVolumeCommand} did not specify this limitation, then it is set to -1 (unlimited).
52185218
*/
52195219
private void setDiskIops(MigrateVolumeCommand cmd, VirtualMachineMO vmMo, String volumePath) throws Exception {
5220-
Long newIops = cmd.getNewIops() == null ? -1L : cmd.getNewIops();
5220+
Long newIops = -1L;
5221+
Long newMinIops = cmd.getNewMinIops();
5222+
Long newMaxIops = cmd.getNewMaxIops();
5223+
5224+
if (ObjectUtils.allNotNull(newMinIops, newMaxIops) && newMinIops > 0 && newMaxIops > 0) {
5225+
newIops = newMinIops + newMaxIops;
5226+
}
5227+
52215228
VirtualDisk disk = vmMo.getDiskDevice(volumePath, true, true).first();
52225229

52235230
try {

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4040
import org.apache.cloudstack.storage.to.VolumeObjectTO;
4141
import org.apache.commons.collections.CollectionUtils;
42+
import org.apache.commons.lang3.ObjectUtils;
4243
import org.apache.logging.log4j.Logger;
4344
import org.apache.logging.log4j.LogManager;
4445
import org.springframework.stereotype.Component;
@@ -253,14 +254,22 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
253254
, targetPool
254255
, hostIdForVmAndHostGuidInTargetCluster.second(), ((VolumeObjectTO) srcData.getTO()).getChainInfo());
255256

256-
VolumeInfo volumeInfo = (VolumeInfo) srcData;
257-
if (volumeInfo.getpayload() instanceof DiskOfferingVO) {
258-
DiskOfferingVO offering = (DiskOfferingVO) volumeInfo.getpayload();
259-
Long newIops = null;
260-
if (offering.getIopsReadRate() != null && offering.getIopsWriteRate() != null) {
261-
newIops = offering.getIopsReadRate() + offering.getIopsWriteRate();
257+
VolumeInfo volume = (VolumeInfo) srcData;
258+
if (volume.getpayload() instanceof DiskOfferingVO) {
259+
DiskOfferingVO offering = (DiskOfferingVO) volume.getpayload();
260+
261+
Long offeringIopsReadRate = offering.getIopsReadRate();
262+
Long offeringIopsWriteRate = offering.getIopsWriteRate();
263+
264+
Long minIops = null;
265+
Long maxIops = null;
266+
if (ObjectUtils.allNotNull(offeringIopsReadRate, offeringIopsWriteRate)) {
267+
minIops = Math.min(offeringIopsReadRate, offeringIopsWriteRate);
268+
maxIops = Math.max(offeringIopsReadRate, offeringIopsWriteRate);
262269
}
263-
cmd.setNewIops(newIops);
270+
271+
cmd.setNewMinIops(minIops);
272+
cmd.setNewMaxIops(maxIops);
264273
}
265274

266275
if (sourcePool.getParent() != 0) {

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,20 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
12661266

12671267
validateIops(newMinIops, newMaxIops, volume.getPoolType());
12681268
} else {
1269-
newMinIops = newDiskOffering.getMinIops() != null ? newDiskOffering.getMinIops() : newDiskOffering.getIopsReadRate();
1270-
newMaxIops = newDiskOffering.getMaxIops() != null ? newDiskOffering.getMaxIops() : newDiskOffering.getIopsWriteRate();
1269+
if (newDiskOffering.getMinIops() != null) {
1270+
newMinIops = newDiskOffering.getMinIops();
1271+
}
1272+
1273+
if (newDiskOffering.getMaxIops() != null) {
1274+
newMaxIops = newDiskOffering.getMaxIops();
1275+
}
1276+
1277+
Long newDiskOfferingIopsReadRate = newDiskOffering.getIopsReadRate();
1278+
Long newDiskOfferingIopsWriteRate = newDiskOffering.getIopsWriteRate();
1279+
if (ObjectUtils.allNull(newMinIops, newMaxIops) && ObjectUtils.allNotNull(newDiskOfferingIopsReadRate, newDiskOfferingIopsWriteRate)) {
1280+
newMaxIops = Math.max(newDiskOfferingIopsReadRate, newDiskOfferingIopsWriteRate);
1281+
newMinIops = Math.min(newDiskOfferingIopsReadRate, newDiskOfferingIopsWriteRate);
1282+
}
12711283
}
12721284

12731285
// if the hypervisor snapshot reserve value is null, it must remain null (currently only KVM uses null and null is all KVM uses for a value here)
@@ -1335,8 +1347,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
13351347
volumeMigrateRequired = true;
13361348
}
13371349

1338-
boolean volumeResizeRequired = currentSize != newSize || !compareEqualsIncludingNullOrZero(newMaxIops, volume.getMaxIops()) || !compareEqualsIncludingNullOrZero(newMinIops, volume.getMinIops())
1339-
|| !compareEqualsIncludingNullOrZero(newMaxIops, diskOffering.getIopsWriteRate()) || !compareEqualsIncludingNullOrZero(newMinIops, diskOffering.getIopsReadRate());
1350+
boolean volumeResizeRequired = currentSize != newSize || !compareEqualsIncludingNullOrZero(newMaxIops, volume.getMaxIops()) || !compareEqualsIncludingNullOrZero(newMinIops, volume.getMinIops());
13401351
if (!volumeMigrateRequired && !volumeResizeRequired && newDiskOffering != null) {
13411352
_volsDao.updateDiskOffering(volume.getId(), newDiskOffering.getId());
13421353
volume = _volsDao.findById(volume.getId());
@@ -1405,6 +1416,9 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
14051416
if (newDiskOffering != null) {
14061417
_volsDao.updateDiskOffering(volumeId, newDiskOffering.getId());
14071418
}
1419+
volume.setMinIops(newMinIops);
1420+
volume.setMinIops(newMaxIops);
1421+
_volsDao.update(volumeId, volume);
14081422
return _volsDao.findById(volumeId);
14091423
}
14101424
}

0 commit comments

Comments
 (0)