Skip to content

Commit efbf74e

Browse files
JoaoJandreJoão Paraquetti
andauthored
Added new logs to volume creation (#6689)
Co-authored-by: João Paraquetti <joao@scclouds.com.br>
1 parent 3889e46 commit efbf74e

File tree

11 files changed

+132
-130
lines changed

11 files changed

+132
-130
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,21 @@ public StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Lo
359359
s_logger.trace(String.format("we have a preferred pool: %b", storagePool.isPresent()));
360360
}
361361

362-
return (storagePool.isPresent()) ? (StoragePool) this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary) :
363-
(StoragePool)dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
362+
StoragePool storage;
363+
if (storagePool.isPresent()) {
364+
storage = (StoragePool)this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary);
365+
s_logger.debug(String.format("VM [%s] has a preferred storage pool [%s]. Volume Orchestrator found this storage using Storage Pool Allocator [%s] and will"
366+
+ " use it.", vm, storage, allocator));
367+
} else {
368+
storage = (StoragePool)dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
369+
s_logger.debug(String.format("VM [%s] does not have a preferred storage pool or it cannot be used. Volume Orchestrator will use the available Storage Pool"
370+
+ " [%s], which was discovered using Storage Pool Allocator [%s].", vm, storage, allocator));
371+
}
372+
return storage;
364373
}
374+
s_logger.debug(String.format("Could not find any available Storage Pool using Storage Pool Allocator [%s].", allocator));
365375
}
376+
s_logger.info("Volume Orchestrator could not find any available Storage Pool.");
366377
return null;
367378
}
368379

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

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import javax.naming.ConfigurationException;
2929

3030
import com.cloud.exception.StorageUnavailableException;
31+
import com.cloud.storage.ScopeType;
3132
import com.cloud.storage.StoragePoolStatus;
3233
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
3334
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
3435
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3536
import org.apache.commons.lang3.StringUtils;
37+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
38+
import org.apache.commons.collections.CollectionUtils;
3639
import org.apache.log4j.Logger;
3740

3841
import com.cloud.utils.Pair;
@@ -111,37 +114,41 @@ public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile
111114
return reorderPools(pools, vmProfile, plan, dskCh);
112115
}
113116

114-
protected List<StoragePool> reorderPoolsByCapacity(DeploymentPlan plan,
115-
List<StoragePool> pools) {
117+
protected List<StoragePool> reorderPoolsByCapacity(DeploymentPlan plan, List<StoragePool> pools) {
116118
Long zoneId = plan.getDataCenterId();
117119
Long clusterId = plan.getClusterId();
118120
short capacityType;
119-
if(pools != null && pools.size() != 0){
120-
capacityType = pools.get(0).getPoolType().isShared() ? Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED : Capacity.CAPACITY_TYPE_LOCAL_STORAGE;
121-
} else{
121+
122+
if (CollectionUtils.isEmpty(pools)) {
122123
return null;
123124
}
124125

125-
List<Long> poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
126-
if (s_logger.isDebugEnabled()) {
127-
s_logger.debug("List of pools in descending order of free capacity: "+ poolIdsByCapacity);
126+
if (pools.get(0).getPoolType().isShared()) {
127+
capacityType = Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED;
128+
} else {
129+
capacityType = Capacity.CAPACITY_TYPE_LOCAL_STORAGE;
128130
}
129131

132+
List<Long> poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
133+
134+
s_logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity));
135+
136+
130137
//now filter the given list of Pools by this ordered list
131-
Map<Long, StoragePool> poolMap = new HashMap<>();
132-
for (StoragePool pool : pools) {
133-
poolMap.put(pool.getId(), pool);
134-
}
135-
List<Long> matchingPoolIds = new ArrayList<>(poolMap.keySet());
138+
Map<Long, StoragePool> poolMap = new HashMap<>();
139+
for (StoragePool pool : pools) {
140+
poolMap.put(pool.getId(), pool);
141+
}
142+
List<Long> matchingPoolIds = new ArrayList<>(poolMap.keySet());
136143

137-
poolIdsByCapacity.retainAll(matchingPoolIds);
144+
poolIdsByCapacity.retainAll(matchingPoolIds);
138145

139-
List<StoragePool> reorderedPools = new ArrayList<>();
140-
for(Long id: poolIdsByCapacity){
141-
reorderedPools.add(poolMap.get(id));
142-
}
146+
List<StoragePool> reorderedPools = new ArrayList<>();
147+
for (Long id: poolIdsByCapacity) {
148+
reorderedPools.add(poolMap.get(id));
149+
}
143150

144-
return reorderedPools;
151+
return reorderedPools;
145152
}
146153

147154
protected List<StoragePool> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, List<StoragePool> pools, Account account) {
@@ -153,9 +160,7 @@ protected List<StoragePool> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L
153160
Long clusterId = plan.getClusterId();
154161

155162
List<Long> poolIdsByVolCount = volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, account.getAccountId());
156-
if (s_logger.isDebugEnabled()) {
157-
s_logger.debug("List of pools in ascending order of number of volumes for account id: " + account.getAccountId() + " is: " + poolIdsByVolCount);
158-
}
163+
s_logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount));
159164

160165
// now filter the given list of Pools by this ordered list
161166
Map<Long, StoragePool> poolMap = new HashMap<>();
@@ -180,6 +185,7 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
180185
s_logger.trace("reordering pools");
181186
}
182187
if (pools == null) {
188+
s_logger.trace("There are no pools to reorder; returning null.");
183189
return null;
184190
}
185191
if (s_logger.isTraceEnabled()) {
@@ -363,4 +369,18 @@ private boolean checkHypervisorCompatibility(HypervisorType hyperType, Volume.Ty
363369
}
364370
return true;
365371
}
372+
373+
protected void logDisabledStoragePools(long dcId, Long podId, Long clusterId, ScopeType scope) {
374+
List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, scope);
375+
if (disabledPools != null && !disabledPools.isEmpty()) {
376+
s_logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools)));
377+
}
378+
}
379+
380+
protected void logStartOfSearch(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, int returnUpTo,
381+
boolean bypassStorageTypeCheck){
382+
s_logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and "
383+
+ "deployment plan [%s]. Returning up to [%d] and bypassStorageTypeCheck [%s].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck));
384+
}
385+
366386
}

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat
4646

4747
@Override
4848
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
49-
s_logger.debug("ClusterScopeStoragePoolAllocator looking for storage pool");
49+
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5050

5151
if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {
5252
return null;
@@ -63,40 +63,34 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
6363
// clusterId == null here because it will break ClusterWide primary
6464
// storage volume operation where
6565
// only podId is passed into this call.
66+
s_logger.debug("ClusterScopeStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage.");
6667
return null;
6768
}
6869
if (dskCh.getTags() != null && dskCh.getTags().length != 0) {
69-
s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having tags:" + Arrays.toString(dskCh.getTags()) +
70-
". Disabled pools will be ignored.");
70+
s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s], cluster [%s], and having tags [%s]. Disabled pools will be ignored.", dcId, podId, clusterId,
71+
Arrays.toString(dskCh.getTags())));
7172
} else {
72-
s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + ". Disabled pools will be ignored.");
73+
s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s]. Disabled pools will be ignored.", dcId, podId, clusterId));
7374
}
7475

7576
if (s_logger.isTraceEnabled()) {
7677
// Log the pools details that are ignored because they are in disabled state
77-
List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, ScopeType.CLUSTER);
78-
if (disabledPools != null && !disabledPools.isEmpty()) {
79-
for (StoragePoolVO pool : disabledPools) {
80-
s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
81-
}
82-
}
78+
logDisabledStoragePools(dcId, podId, clusterId, ScopeType.CLUSTER);
8379
}
8480

8581
List<StoragePoolVO> pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags());
86-
s_logger.debug("Found pools matching tags: " + pools);
82+
s_logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags())));
8783

8884
// add remaining pools in cluster, that did not match tags, to avoid set
8985
List<StoragePoolVO> allPools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, null);
9086
allPools.removeAll(pools);
9187
for (StoragePoolVO pool : allPools) {
92-
s_logger.debug("Adding pool " + pool + " to avoid set since it did not match tags");
88+
s_logger.trace(String.format("Adding pool [%s] to the 'avoid' set since it did not match any tags.", pool));
9389
avoid.addPool(pool.getId());
9490
}
9591

9692
if (pools.size() == 0) {
97-
if (s_logger.isDebugEnabled()) {
98-
s_logger.debug("No storage pools available for " + ServiceOffering.StorageType.shared.toString() + " volume allocation, returning");
99-
}
93+
s_logger.debug(String.format("No storage pools available for [%s] volume allocation.", ServiceOffering.StorageType.shared));
10094
return suitablePools;
10195
}
10296

@@ -106,15 +100,14 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
106100
}
107101
StoragePool storagePool = (StoragePool)dataStoreMgr.getPrimaryDataStore(pool.getId());
108102
if (filter(avoid, storagePool, dskCh, plan)) {
103+
s_logger.trace(String.format("Found suitable local storage pool [%s], adding to list.", pool));
109104
suitablePools.add(storagePool);
110105
} else {
111106
avoid.addPool(pool.getId());
112107
}
113108
}
114109

115-
if (s_logger.isDebugEnabled()) {
116-
s_logger.debug("ClusterScopeStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
117-
}
110+
s_logger.debug(String.format("ClusterScopeStoragePoolAllocator is returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
118111

119112
return suitablePools;
120113
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl
4848

4949
@Override
5050
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
51-
s_logger.debug("GarbageCollectingStoragePoolAllocator looking for storage pool");
51+
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5252
if (!_storagePoolCleanupEnabled) {
5353
s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");
5454
return null;

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,16 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator {
6161

6262
@Override
6363
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
64-
s_logger.debug("LocalStoragePoolAllocator trying to find storage pool to fit the vm");
64+
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
6565

6666
if (!bypassStorageTypeCheck && !dskCh.useLocalStorage()) {
67+
s_logger.debug("LocalStoragePoolAllocator is returning null since the disk profile does not use local storage and bypassStorageTypeCheck is false.");
6768
return null;
6869
}
6970

7071
if (s_logger.isTraceEnabled()) {
7172
// Log the pools details that are ignored because they are in disabled state
72-
List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST);
73-
if (disabledPools != null && !disabledPools.isEmpty()) {
74-
for (StoragePoolVO pool : disabledPools) {
75-
s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
76-
}
77-
}
73+
logDisabledStoragePools(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST);
7874
}
7975

8076
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
@@ -86,7 +82,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
8682
if (pool != null && pool.isLocal()) {
8783
StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
8884
if (filter(avoid, storagePool, dskCh, plan)) {
89-
s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
85+
s_logger.trace(String.format("Found suitable local storage pool [%s], adding to list.", pool));
9086
suitablePools.add(storagePool);
9187
} else {
9288
avoid.addPool(pool.getId());
@@ -100,6 +96,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
10096
} else {
10197
if (plan.getPodId() == null) {
10298
// zone wide primary storage deployment
99+
s_logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment.");
103100
return null;
104101
}
105102
List<StoragePoolVO> availablePools =
@@ -116,18 +113,14 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
116113
}
117114
}
118115

119-
// add remaining pools in cluster, that did not match tags, to avoid
120-
// set
116+
// add remaining pools in cluster to the 'avoid' set which did not match tags
121117
List<StoragePoolVO> allPools = storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), null);
122118
allPools.removeAll(availablePools);
123119
for (StoragePoolVO pool : allPools) {
124120
avoid.addPool(pool.getId());
125121
}
126122
}
127-
128-
if (s_logger.isDebugEnabled()) {
129-
s_logger.debug("LocalStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
130-
}
123+
s_logger.debug(String.format("LocalStoragePoolAllocator returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
131124

132125
return suitablePools;
133126
}

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

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

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -50,26 +51,22 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
5051

5152
@Override
5253
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
53-
LOGGER.debug("ZoneWideStoragePoolAllocator to find storage pool");
54+
logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
5455

5556
if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) {
5657
return null;
5758
}
5859

5960
if (LOGGER.isTraceEnabled()) {
6061
// Log the pools details that are ignored because they are in disabled state
61-
List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), null, null, ScopeType.ZONE);
62-
if (disabledPools != null && !disabledPools.isEmpty()) {
63-
for (StoragePoolVO pool : disabledPools) {
64-
LOGGER.trace("Ignoring pool " + pool + " as it is in disabled state.");
65-
}
66-
}
62+
logDisabledStoragePools(plan.getDataCenterId(), null, null, ScopeType.ZONE);
6763
}
6864

6965
List<StoragePool> suitablePools = new ArrayList<>();
7066

7167
List<StoragePoolVO> storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags());
7268
if (storagePools == null) {
69+
LOGGER.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags())));
7370
storagePools = new ArrayList<>();
7471
}
7572

@@ -97,13 +94,16 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
9794
}
9895
StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(storage.getId());
9996
if (filter(avoid, storagePool, dskCh, plan)) {
97+
LOGGER.trace(String.format("Found suitable local storage pool [%s], adding to list.", storage));
10098
suitablePools.add(storagePool);
10199
} else {
102100
if (canAddStoragePoolToAvoidSet(storage)) {
103101
avoid.addPool(storagePool.getId());
104102
}
105103
}
106104
}
105+
LOGGER.debug(String.format("ZoneWideStoragePoolAllocator is returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
106+
107107
return suitablePools;
108108
}
109109

0 commit comments

Comments
 (0)