Skip to content

Commit d5ba23c

Browse files
authored
Introduce volume allocation algorithm global configuration (#10696)
1 parent 7bab40d commit d5ba23c

File tree

14 files changed

+1067
-139
lines changed

14 files changed

+1067
-139
lines changed

api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface DeploymentClusterPlanner extends DeploymentPlanner {
6262
"vm.allocation.algorithm",
6363
"Advanced",
6464
"random",
65-
"Order in which hosts within a cluster will be considered for VM/volume allocation. The value can be 'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit', or 'firstfitleastconsumed'.",
65+
"Order in which hosts within a cluster will be considered for VM allocation. The value can be 'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit', or 'firstfitleastconsumed'.",
6666
true,
6767
ConfigKey.Scope.Global, null, null, null, null, null,
6868
ConfigKey.Kind.Select,

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public interface VolumeOrchestrationService {
8484
"The maximum size for a volume (in GiB).",
8585
true);
8686

87+
ConfigKey<String> VolumeAllocationAlgorithm = new ConfigKey<>(
88+
String.class,
89+
"volume.allocation.algorithm",
90+
"Advanced",
91+
"random",
92+
"Order in which storage pool within a cluster will be considered for volume allocation. The value can be 'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit', or 'firstfitleastconsumed'.",
93+
true,
94+
ConfigKey.Scope.Global, null, null, null, null, null,
95+
ConfigKey.Kind.Select,
96+
"random,firstfit,userdispersing,userconcentratedpod_random,userconcentratedpod_firstfit,firstfitleastconsumed");
97+
8798
VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType)
8899
throws ConcurrentOperationException, StorageUnavailableException;
89100

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import javax.inject.Inject;
3939
import javax.naming.ConfigurationException;
4040

41+
import com.cloud.deploy.DeploymentClusterPlanner;
4142
import com.cloud.exception.ResourceAllocationException;
4243
import com.cloud.storage.DiskOfferingVO;
4344
import com.cloud.storage.VMTemplateVO;
@@ -74,6 +75,7 @@
7475
import org.apache.cloudstack.framework.config.ConfigDepot;
7576
import org.apache.cloudstack.framework.config.ConfigKey;
7677
import org.apache.cloudstack.framework.config.Configurable;
78+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
7779
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
7880
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
7981
import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO;
@@ -262,6 +264,10 @@ public enum UserVmCloneType {
262264
StoragePoolHostDao storagePoolHostDao;
263265
@Inject
264266
DiskOfferingDao diskOfferingDao;
267+
@Inject
268+
ConfigDepot configDepot;
269+
@Inject
270+
ConfigurationDao configurationDao;
265271

266272
@Inject
267273
protected SnapshotHelper snapshotHelper;
@@ -2047,7 +2053,9 @@ public boolean canVmRestartOnAnotherServer(long vmId) {
20472053

20482054
@Override
20492055
public ConfigKey<?>[] getConfigKeys() {
2050-
return new ConfigKey<?>[] {RecreatableSystemVmEnabled, MaxVolumeSize, StorageHAMigrationEnabled, StorageMigrationEnabled, CustomDiskOfferingMaxSize, CustomDiskOfferingMinSize, VolumeUrlCheck};
2056+
return new ConfigKey<?>[] {
2057+
RecreatableSystemVmEnabled, MaxVolumeSize, StorageHAMigrationEnabled, StorageMigrationEnabled,
2058+
CustomDiskOfferingMaxSize, CustomDiskOfferingMinSize, VolumeUrlCheck, VolumeAllocationAlgorithm};
20512059
}
20522060

20532061
@Override
@@ -2060,6 +2068,18 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
20602068
return true;
20612069
}
20622070

2071+
@Override
2072+
public boolean start() {
2073+
if (configDepot.isNewConfig(VolumeAllocationAlgorithm)) {
2074+
String vmAllocationAlgo = DeploymentClusterPlanner.VmAllocationAlgorithm.value();
2075+
if (com.cloud.utils.StringUtils.isNotEmpty(vmAllocationAlgo) && !VolumeAllocationAlgorithm.defaultValue().equalsIgnoreCase(vmAllocationAlgo)) {
2076+
logger.debug("Updating value for configuration: {} to {}", VolumeAllocationAlgorithm.key(), vmAllocationAlgo);
2077+
configurationDao.update(VolumeAllocationAlgorithm.key(), vmAllocationAlgo);
2078+
}
2079+
}
2080+
return true;
2081+
}
2082+
20632083
private void cleanupVolumeDuringAttachFailure(Long volumeId, Long vmId) {
20642084
VolumeVO volume = _volsDao.findById(volumeId);
20652085
if (volume == null) {

0 commit comments

Comments
 (0)