Skip to content

Commit f6e7fa6

Browse files
committed
Address review comments
1 parent b28db5d commit f6e7fa6

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import com.cloud.user.Account;
3737
import com.cloud.utils.NumbersUtil;
3838
import com.cloud.utils.Pair;
39+
import com.cloud.utils.StringUtils;
3940
import com.cloud.utils.component.AdapterBase;
4041
import com.cloud.vm.DiskProfile;
4142
import com.cloud.vm.VirtualMachineProfile;
43+
4244
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
4345
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4446
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
@@ -48,8 +50,8 @@
4850
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
4951
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
5052
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
53+
5154
import org.apache.commons.collections.CollectionUtils;
52-
import org.apache.commons.lang3.StringUtils;
5355

5456
import javax.inject.Inject;
5557
import javax.naming.ConfigurationException;
@@ -65,7 +67,7 @@
6567
public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator {
6668

6769
protected BigDecimal storageOverprovisioningFactor = new BigDecimal(1);
68-
protected String allocationAlgorithm = "random";
70+
protected String volumeAllocationAlgorithm = "random";
6971
protected long extraBytesPerVolume = 0;
7072
@Inject protected DataStoreManager dataStoreMgr;
7173
@Inject protected PrimaryDataStoreDao storagePoolDao;
@@ -93,9 +95,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
9395
String globalStorageOverprovisioningFactor = configs.get("storage.overprovisioning.factor");
9496
storageOverprovisioningFactor = new BigDecimal(NumbersUtil.parseFloat(globalStorageOverprovisioningFactor, 2.0f));
9597
extraBytesPerVolume = 0;
96-
String allocationAlgorithm = VolumeOrchestrationService.VolumeAllocationAlgorithm.value();
97-
if (allocationAlgorithm != null) {
98-
this.allocationAlgorithm = allocationAlgorithm;
98+
String volAllocationAlgorithm = VolumeOrchestrationService.VolumeAllocationAlgorithm.value();
99+
if (volAllocationAlgorithm != null) {
100+
this.volumeAllocationAlgorithm = volAllocationAlgorithm;
99101
}
100102
return true;
101103
}
@@ -225,15 +227,15 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
225227
}
226228

227229
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account) {
228-
logger.debug("Using volume allocation algorithm {} to reorder pools.", allocationAlgorithm);
229-
if (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
230+
logger.debug("Using volume allocation algorithm {} to reorder pools.", volumeAllocationAlgorithm);
231+
if (volumeAllocationAlgorithm.equals("random") || volumeAllocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
230232
reorderRandomPools(pools);
231-
} else if (StringUtils.equalsAny(allocationAlgorithm, "userdispersing", "firstfitleastconsumed")) {
233+
} else if (StringUtils.equalsAny(volumeAllocationAlgorithm, "userdispersing", "firstfitleastconsumed")) {
232234
if (logger.isTraceEnabled()) {
233-
logger.trace("Using reordering algorithm {}", allocationAlgorithm);
235+
logger.trace("Using reordering algorithm {}", volumeAllocationAlgorithm);
234236
}
235237

236-
if (allocationAlgorithm.equals("userdispersing")) {
238+
if (volumeAllocationAlgorithm.equals("userdispersing")) {
237239
pools = reorderPoolsByNumberOfVolumes(plan, pools, account);
238240
} else {
239241
pools = reorderPoolsByCapacity(plan, pools);
@@ -245,7 +247,7 @@ List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, D
245247
void reorderRandomPools(List<StoragePool> pools) {
246248
StorageUtil.traceLogStoragePools(pools, logger, "pools to choose from: ");
247249
if (logger.isTraceEnabled()) {
248-
logger.trace("Shuffle this so that we don't check the pools in the same order. Algorithm == {} (or no account?)", allocationAlgorithm);
250+
logger.trace("Shuffle this so that we don't check the pools in the same order. Algorithm == {} (or no account?)", volumeAllocationAlgorithm);
249251
}
250252
StorageUtil.traceLogStoragePools(pools, logger, "pools to shuffle: ");
251253
Collections.shuffle(pools, secureRandom);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.cloud.storage.dao.DiskOfferingDao;
2626
import com.cloud.vm.DiskProfile;
2727
import com.cloud.vm.VirtualMachineProfile;
28+
2829
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
2930
import org.springframework.stereotype.Component;
3031

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void reorderStoragePoolsBasedOnAlgorithm_random() {
8282

8383
@Test
8484
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing() {
85-
allocator.allocationAlgorithm = "userdispersing";
85+
allocator.volumeAllocationAlgorithm = "userdispersing";
8686
Mockito.doReturn(pools).when(allocator).reorderPoolsByNumberOfVolumes(plan, pools, account);
8787
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
8888
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
@@ -92,7 +92,7 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing() {
9292

9393
@Test
9494
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
95-
allocator.allocationAlgorithm = "userdispersing";
95+
allocator.volumeAllocationAlgorithm = "userdispersing";
9696
allocator.volumeDao = volumeDao;
9797

9898
when(plan.getDataCenterId()).thenReturn(1l);
@@ -115,7 +115,7 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
115115

116116
@Test
117117
public void reorderStoragePoolsBasedOnAlgorithm_firstfitleastconsumed() {
118-
allocator.allocationAlgorithm = "firstfitleastconsumed";
118+
allocator.volumeAllocationAlgorithm = "firstfitleastconsumed";
119119
Mockito.doReturn(pools).when(allocator).reorderPoolsByCapacity(plan, pools);
120120
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
121121
Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByCapacity(plan, pools);

0 commit comments

Comments
 (0)