Skip to content

Commit fce33d9

Browse files
author
Julien Hervot de Mattos Vaz
committed
Adição de logs na reordenação de storage pools
Substitui por nova sintaxe do Log4j
1 parent 22c7192 commit fce33d9

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

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

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ protected List<StoragePool> reorderPoolsByCapacity(DeploymentPlan plan, List<Sto
137137
storageType = "shared";
138138
}
139139

140-
logger.debug(String.format(
141-
"Filtering storage pools by capacity type [%s] as the first storage pool of the list, with name [%s] and ID [%s], is a [%s] storage.",
140+
logger.debug(
141+
"Filtering storage pools by capacity type [{}] as the first storage pool of the list, with name [{}] and ID [{}], is a [{}] storage.",
142142
capacityType, storagePool.getName(), storagePool.getUuid(), storageType
143-
));
143+
);
144144

145145
List<Long> poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
146146

147-
logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity));
147+
logger.debug("List of pools in descending order of available capacity [{}].", poolIdsByCapacity);
148148

149149

150150
//now filter the given list of Pools by this ordered list
@@ -173,7 +173,7 @@ protected List<StoragePool> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L
173173
Long clusterId = plan.getClusterId();
174174

175175
List<Long> poolIdsByVolCount = volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, account.getAccountId());
176-
logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount));
176+
logger.debug("List of pools in ascending order of number of volumes for account [{}] is [{}].", account, poolIdsByVolCount);
177177

178178
// now filter the given list of Pools by this ordered list
179179
Map<Long, StoragePool> poolMap = new HashMap<>();
@@ -194,16 +194,11 @@ protected List<StoragePool> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L
194194

195195
@Override
196196
public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachineProfile vmProfile, DeploymentPlan plan, DiskProfile dskCh) {
197-
if (logger.isTraceEnabled()) {
198-
logger.trace("reordering pools");
199-
}
200197
if (pools == null) {
201-
logger.trace("There are no pools to reorder; returning null.");
198+
logger.debug("There are no pools to reorder; returning null.");
202199
return null;
203200
}
204-
if (logger.isTraceEnabled()) {
205-
logger.trace(String.format("reordering %d pools", pools.size()));
206-
}
201+
logger.debug("Reordering [{}] pools", pools.size());
207202
Account account = null;
208203
if (vmProfile.getVirtualMachine() != null) {
209204
account = vmProfile.getOwner();
@@ -212,9 +207,7 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
212207
pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
213208

214209
if (vmProfile.getVirtualMachine() == null) {
215-
if (logger.isTraceEnabled()) {
216-
logger.trace("The VM is null, skipping pools reordering by disk provisioning type.");
217-
}
210+
logger.debug("The VM is null, skipping pool reordering by disk provisioning type.");
218211
return pools;
219212
}
220213

@@ -227,15 +220,11 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
227220
}
228221

229222
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account) {
230-
logger.debug(String.format("Using allocation algorithm [%s] to reorder pools.", allocationAlgorithm));
223+
logger.debug("Using allocation algorithm [{}] to reorder pools.", allocationAlgorithm);
231224

232225
if (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
233226
reorderRandomPools(pools);
234227
} else if (StringUtils.equalsAny(allocationAlgorithm, "userdispersing", "firstfitleastconsumed")) {
235-
if (logger.isTraceEnabled()) {
236-
logger.trace(String.format("Using reordering algorithm [%s]", allocationAlgorithm));
237-
}
238-
239228
if (allocationAlgorithm.equals("userdispersing")) {
240229
pools = reorderPoolsByNumberOfVolumes(plan, pools, account);
241230
} else {
@@ -248,15 +237,16 @@ List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, D
248237
void reorderRandomPools(List<StoragePool> pools) {
249238
StorageUtil.traceLogStoragePools(pools, logger, "pools to choose from: ");
250239
if (logger.isTraceEnabled()) {
251-
logger.trace(String.format("Shuffle this so that we don't check the pools in the same order. Algorithm == '%s' (or no account?)", allocationAlgorithm));
240+
logger.trace("Shuffle this so that we don't check the pools in the same order. Algorithm == '[{}]' (or no account?)", allocationAlgorithm);
252241
}
253-
StorageUtil.traceLogStoragePools(pools, logger, "pools to shuffle: ");
242+
logger.debug("Pools to shuffle: [{}]", pools);
254243
Collections.shuffle(pools, secureRandom);
255-
StorageUtil.traceLogStoragePools(pools, logger, "shuffled list of pools to choose from: ");
244+
logger.debug("Shuffled list of pools to choose from: [{}]", pools);
256245
}
257246

258247
private List<StoragePool> reorderPoolsByDiskProvisioningType(List<StoragePool> pools, DiskProfile diskProfile) {
259248
if (diskProfile != null && diskProfile.getProvisioningType() != null && !diskProfile.getProvisioningType().equals(Storage.ProvisioningType.THIN)) {
249+
logger.debug("Reordering [{}] pools by disk provisioning type [{}].", pools.size(), diskProfile.getProvisioningType());
260250
List<StoragePool> reorderedPools = new ArrayList<>();
261251
int preferredIndex = 0;
262252
for (StoragePool pool : pools) {
@@ -270,22 +260,24 @@ private List<StoragePool> reorderPoolsByDiskProvisioningType(List<StoragePool> p
270260
reorderedPools.add(preferredIndex++, pool);
271261
}
272262
}
263+
logger.debug("Reordered list of pools by disk provisioning type [{}]: [{}]", diskProfile.getProvisioningType(), pools);
273264
return reorderedPools;
274265
} else {
266+
logger.debug("Reordering pools by disk provisioning type wasn't necessary.");
275267
return pools;
276268
}
277269
}
278270

279271
protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, DeploymentPlan plan) {
280-
logger.debug(String.format("Checking if storage pool [%s] is suitable to disk [%s].", pool, dskCh));
272+
logger.debug("Checking if storage pool [{}] is suitable to disk [{}].", pool, dskCh);
281273
if (avoid.shouldAvoid(pool)) {
282-
logger.debug(String.format("StoragePool [%s] is in avoid set, skipping this pool to allocation of disk [%s].", pool, dskCh));
274+
logger.debug("StoragePool [{}] is in avoid set, skipping this pool to allocation of disk [{}].", pool, dskCh);
283275
return false;
284276
}
285277

286278
if (dskCh.requiresEncryption() && !pool.getPoolType().supportsEncryption()) {
287279
if (logger.isDebugEnabled()) {
288-
logger.debug(String.format("Storage pool type '%s' doesn't support encryption required for volume, skipping this pool", pool.getPoolType()));
280+
logger.debug("Storage pool type '[{}]' doesn't support encryption required for volume, skipping this pool", pool.getPoolType());
289281
}
290282
return false;
291283
}
@@ -307,8 +299,8 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh,
307299
}
308300

309301
if (!checkDiskProvisioningSupport(dskCh, pool)) {
310-
logger.debug(String.format("Storage pool [%s] does not have support to disk provisioning of disk [%s].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh,
311-
"type", "name", "diskOfferingId", "templateId", "volumeId", "provisioningType", "hyperType")));
302+
logger.debug("Storage pool [{}] does not have support to disk provisioning of disk [{}].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh,
303+
"type", "name", "diskOfferingId", "templateId", "volumeId", "provisioningType", "hyperType"));
312304
return false;
313305
}
314306

@@ -321,13 +313,13 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh,
321313
if (!isTempVolume) {
322314
volume = volumeDao.findById(dskCh.getVolumeId());
323315
if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) {
324-
logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume));
316+
logger.debug("Pool [{}] is not compatible with volume [{}], skipping it.", pool, volume);
325317
return false;
326318
}
327319
}
328320

329321
if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) {
330-
logger.debug(String.format("Cannot allocate pool [%s] to volume [%s] because the max number of managed clustered filesystems has been exceeded.", pool, volume));
322+
logger.debug("Cannot allocate pool [{}] to volume [{}] because the max number of managed clustered filesystems has been exceeded.", pool, volume);
331323
return false;
332324
}
333325

@@ -336,13 +328,13 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh,
336328
requestVolumeDiskProfilePairs.add(new Pair<>(volume, dskCh));
337329
if (dskCh.getHypervisorType() == HypervisorType.VMware) {
338330
if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster && storageMgr.isStoragePoolDatastoreClusterParent(pool)) {
339-
logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is a parent datastore cluster.", pool, volume));
331+
logger.debug("Skipping allocation of pool [{}] to volume [{}] because this pool is a parent datastore cluster.", pool, volume);
340332
return false;
341333
}
342334
if (pool.getParent() != 0L) {
343335
StoragePoolVO datastoreCluster = storagePoolDao.findById(pool.getParent());
344336
if (datastoreCluster == null || (datastoreCluster != null && datastoreCluster.getStatus() != StoragePoolStatus.Up)) {
345-
logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not in [%s] state.", datastoreCluster, volume, StoragePoolStatus.Up));
337+
logger.debug("Skipping allocation of pool [{}] to volume [{}] because this pool is not in [{}] state.", datastoreCluster, volume, StoragePoolStatus.Up);
346338
return false;
347339
}
348340
}
@@ -352,11 +344,11 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh,
352344
storageMgr.isStoragePoolCompliantWithStoragePolicy(dskCh.getDiskOfferingId(), pool) :
353345
storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool);
354346
if (!isStoragePoolStoragePolicyCompliance) {
355-
logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume));
347+
logger.debug("Skipping allocation of pool [{}] to volume [{}] because this pool is not compliant with the storage policy required by the volume.", pool, volume);
356348
return false;
357349
}
358350
} catch (StorageUnavailableException e) {
359-
logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
351+
logger.warn("Could not verify storage policy complaince against storage pool [{}] due to exception [{}]", pool.getUuid(), e.getMessage());
360352
return false;
361353
}
362354
}
@@ -405,19 +397,19 @@ private boolean checkHypervisorCompatibility(HypervisorType hyperType, Volume.Ty
405397
protected void logDisabledStoragePools(long dcId, Long podId, Long clusterId, ScopeType scope) {
406398
List<StoragePoolVO> disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, scope);
407399
if (disabledPools != null && !disabledPools.isEmpty()) {
408-
logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools)));
400+
logger.trace("Ignoring pools [{}] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools));
409401
}
410402
}
411403

412404
protected void logStartOfSearch(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, int returnUpTo,
413405
boolean bypassStorageTypeCheck){
414-
logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and "
415-
+ "deployment plan [%s]. Returning up to [%d] and bypassStorageTypeCheck [%s].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck));
406+
logger.trace("[{}] is looking for storage pools that match the VM's disk profile [{}], virtual machine profile [{}] and "
407+
+ "deployment plan [{}]. Returning up to [{}] and bypassStorageTypeCheck [{}].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck);
416408
}
417409

418410
protected void logEndOfSearch(List<StoragePool> storagePoolList) {
419-
logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(),
420-
Arrays.toString(storagePoolList.toArray())));
411+
logger.debug("[{}] is returning [{}] suitable storage pools [{}].", this.getClass().getSimpleName(), storagePoolList.size(),
412+
Arrays.toString(storagePoolList.toArray()));
421413
}
422414

423415
}

0 commit comments

Comments
 (0)