Skip to content

Commit 33f9e6f

Browse files
committed
make config dynamic in nature to avoid need of mgmt server restart
1 parent 9c3d381 commit 33f9e6f

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public interface VolumeOrchestrationService {
8989
"Advanced",
9090
"random",
9191
"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'.",
92-
false,
92+
true,
9393
ConfigKey.Scope.Global, null, null, null, null, null,
9494
ConfigKey.Kind.Select,
9595
"random,firstfit,userdispersing,userconcentratedpod_random,userconcentratedpod_firstfit,firstfitleastconsumed");

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator {
6868

6969
protected BigDecimal storageOverprovisioningFactor = new BigDecimal(1);
70-
protected String volumeAllocationAlgorithm = "random";
7170
protected long extraBytesPerVolume = 0;
7271
@Inject protected DataStoreManager dataStoreMgr;
7372
@Inject protected PrimaryDataStoreDao storagePoolDao;
@@ -95,10 +94,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
9594
String globalStorageOverprovisioningFactor = configs.get("storage.overprovisioning.factor");
9695
storageOverprovisioningFactor = new BigDecimal(NumbersUtil.parseFloat(globalStorageOverprovisioningFactor, 2.0f));
9796
extraBytesPerVolume = 0;
98-
String volAllocationAlgorithm = VolumeOrchestrationService.VolumeAllocationAlgorithm.value();
99-
if (volAllocationAlgorithm != null) {
100-
this.volumeAllocationAlgorithm = volAllocationAlgorithm;
101-
}
10297
return true;
10398
}
10499
return false;
@@ -209,7 +204,7 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
209204
account = vmProfile.getOwner();
210205
}
211206

212-
pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
207+
pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, VolumeOrchestrationService.VolumeAllocationAlgorithm.value());
213208

214209
if (vmProfile.getVirtualMachine() == null) {
215210
if (logger.isTraceEnabled()) {
@@ -226,7 +221,7 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
226221
return pools;
227222
}
228223

229-
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account) {
224+
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account, String volumeAllocationAlgorithm) {
230225
logger.debug("Using volume allocation algorithm {} to reorder pools.", volumeAllocationAlgorithm);
231226
if (volumeAllocationAlgorithm.equals("random") || volumeAllocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
232227
reorderRandomPools(pools);
@@ -247,7 +242,7 @@ List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, D
247242
void reorderRandomPools(List<StoragePool> pools) {
248243
StorageUtil.traceLogStoragePools(pools, logger, "pools to choose from: ");
249244
if (logger.isTraceEnabled()) {
250-
logger.trace("Shuffle this so that we don't check the pools in the same order. Algorithm == {} (or no account?)", volumeAllocationAlgorithm);
245+
logger.trace("Shuffle this so that we don't check the pools in the same order. Algorithm == 'random' (or no account?)");
251246
}
252247
StorageUtil.traceLogStoragePools(pools, logger, "pools to shuffle: ");
253248
Collections.shuffle(pools, secureRandom);

engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
package org.apache.cloudstack.storage.allocator;
1818

1919

20-
import static org.mockito.Mockito.when;
21-
22-
import java.util.ArrayList;
23-
import java.util.HashSet;
24-
import java.util.List;
25-
import java.util.Set;
20+
import com.cloud.deploy.DeploymentPlan;
21+
import com.cloud.deploy.DeploymentPlanner;
22+
import com.cloud.storage.Storage;
23+
import com.cloud.storage.StoragePool;
24+
import com.cloud.storage.dao.VolumeDao;
25+
import com.cloud.user.Account;
26+
import com.cloud.vm.DiskProfile;
27+
import com.cloud.vm.VirtualMachineProfile;
2628

2729
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
30+
2831
import org.junit.After;
2932
import org.junit.Assert;
3033
import org.junit.Before;
@@ -34,14 +37,12 @@
3437
import org.mockito.Mockito;
3538
import org.mockito.junit.MockitoJUnitRunner;
3639

37-
import com.cloud.deploy.DeploymentPlan;
38-
import com.cloud.deploy.DeploymentPlanner;
39-
import com.cloud.storage.Storage;
40-
import com.cloud.storage.StoragePool;
41-
import com.cloud.storage.dao.VolumeDao;
42-
import com.cloud.user.Account;
43-
import com.cloud.vm.DiskProfile;
44-
import com.cloud.vm.VirtualMachineProfile;
40+
import java.util.ArrayList;
41+
import java.util.HashSet;
42+
import java.util.List;
43+
import java.util.Set;
44+
45+
import static org.mockito.Mockito.when;
4546

4647
@RunWith(MockitoJUnitRunner.class)
4748
public class AbstractStoragePoolAllocatorTest {
@@ -74,25 +75,23 @@ public void tearDown() {
7475

7576
@Test
7677
public void reorderStoragePoolsBasedOnAlgorithm_random() {
77-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
78+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "random");
7879
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
7980
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByNumberOfVolumes(plan, pools, account);
8081
Mockito.verify(allocator, Mockito.times(1)).reorderRandomPools(pools);
8182
}
8283

8384
@Test
8485
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing() {
85-
allocator.volumeAllocationAlgorithm = "userdispersing";
8686
Mockito.doReturn(pools).when(allocator).reorderPoolsByNumberOfVolumes(plan, pools, account);
87-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
87+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account,"userdispersing");
8888
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
8989
Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByNumberOfVolumes(plan, pools, account);
9090
Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools);
9191
}
9292

9393
@Test
9494
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
95-
allocator.volumeAllocationAlgorithm = "userdispersing";
9695
allocator.volumeDao = volumeDao;
9796

9897
when(plan.getDataCenterId()).thenReturn(1l);
@@ -104,7 +103,7 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
104103
poolIds.add(9l);
105104
when(volumeDao.listPoolIdsByVolumeCount(1l,1l,1l,1l)).thenReturn(poolIds);
106105

107-
List<StoragePool> reorderedPools = allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
106+
List<StoragePool> reorderedPools = allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "userdispersing");
108107
Assert.assertEquals(poolIds.size(),reorderedPools.size());
109108

110109
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
@@ -115,9 +114,8 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
115114

116115
@Test
117116
public void reorderStoragePoolsBasedOnAlgorithm_firstfitleastconsumed() {
118-
allocator.volumeAllocationAlgorithm = "firstfitleastconsumed";
119117
Mockito.doReturn(pools).when(allocator).reorderPoolsByCapacity(plan, pools);
120-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
118+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "firstfitleastconsumed");
121119
Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByCapacity(plan, pools);
122120
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByNumberOfVolumes(plan, pools, account);
123121
Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools);

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28-
import com.cloud.utils.exception.CloudRuntimeException;
29-
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
30-
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
31-
import org.springframework.stereotype.Component;
32-
3328
import com.cloud.agent.manager.allocator.HostAllocator;
3429
import com.cloud.capacity.CapacityManager;
3530
import com.cloud.capacity.CapacityVO;
@@ -38,6 +33,7 @@
3833
import com.cloud.dc.ClusterDetailsDao;
3934
import com.cloud.dc.dao.ClusterDao;
4035
import com.cloud.deploy.DeploymentPlan;
36+
import com.cloud.deploy.DeploymentClusterPlanner;
4137
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
4238
import com.cloud.gpu.GPU;
4339
import com.cloud.host.DetailVO;
@@ -58,12 +54,17 @@
5854
import com.cloud.user.Account;
5955
import com.cloud.utils.Pair;
6056
import com.cloud.utils.component.AdapterBase;
57+
import com.cloud.utils.exception.CloudRuntimeException;
6158
import com.cloud.vm.UserVmDetailVO;
6259
import com.cloud.vm.VirtualMachine;
6360
import com.cloud.vm.VirtualMachineProfile;
6461
import com.cloud.vm.dao.UserVmDetailsDao;
6562
import com.cloud.vm.dao.VMInstanceDao;
6663

64+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
65+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
66+
67+
import org.springframework.stereotype.Component;
6768

6869
/**
6970
* An allocator that tries to find a fit on a computing host. This allocator does not care whether or not the host supports routing.
@@ -98,8 +99,6 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
9899
UserVmDetailsDao _userVmDetailsDao;
99100

100101
boolean _checkHvm = true;
101-
protected String _allocationAlgorithm = "random";
102-
103102

104103
@Override
105104
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) {
@@ -286,12 +285,13 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
286285

287286
protected List<Host> allocateTo(DeploymentPlan plan, ServiceOffering offering, VMTemplateVO template, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo,
288287
boolean considerReservedCapacity, Account account) {
289-
if (_allocationAlgorithm.equals("random") || _allocationAlgorithm.equals("userconcentratedpod_random")) {
288+
String vmAllocationAlgorithm = DeploymentClusterPlanner.VmAllocationAlgorithm.value();
289+
if (vmAllocationAlgorithm.equals("random") || vmAllocationAlgorithm.equals("userconcentratedpod_random")) {
290290
// Shuffle this so that we don't check the hosts in the same order.
291291
Collections.shuffle(hosts);
292-
} else if (_allocationAlgorithm.equals("userdispersing")) {
292+
} else if (vmAllocationAlgorithm.equals("userdispersing")) {
293293
hosts = reorderHostsByNumberOfVms(plan, hosts, account);
294-
}else if(_allocationAlgorithm.equals("firstfitleastconsumed")){
294+
}else if(vmAllocationAlgorithm.equals("firstfitleastconsumed")){
295295
hosts = reorderHostsByCapacity(plan, hosts);
296296
}
297297

@@ -575,11 +575,6 @@ protected String getTemplateGuestOSCategory(VMTemplateVO template) {
575575
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
576576
if (_configDao != null) {
577577
Map<String, String> configs = _configDao.getConfiguration(params);
578-
579-
String allocationAlgorithm = configs.get("vm.allocation.algorithm");
580-
if (allocationAlgorithm != null) {
581-
_allocationAlgorithm = allocationAlgorithm;
582-
}
583578
String value = configs.get("xenserver.check.hvm");
584579
_checkHvm = value == null ? true : Boolean.parseBoolean(value);
585580
}

0 commit comments

Comments
 (0)