diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 3a7c94912730..d2c3a6262eb0 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -646,9 +646,7 @@ protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStor if (templatePoolRef == null) { throw new CloudRuntimeException(String.format("Failed to find template %s in storage pool %s", template.getImage(), dataStore)); } else { - if (logger.isDebugEnabled()) { - logger.debug("Found template {} in storage pool {} with VMTemplateStoragePool: {}", template.getImage(), dataStore, templatePoolRef); - } + logger.debug("Found template {} in storage pool {} with VMTemplateStoragePool: {}", template.getImage(), dataStore, templatePoolRef); } long templatePoolRefId = templatePoolRef.getId(); CreateBaseImageContext context = new CreateBaseImageContext<>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId); @@ -656,15 +654,13 @@ protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStor caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context); int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); - if (logger.isDebugEnabled()) { - logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); - } + + logger.debug("Acquire lock on VMTemplateStoragePool {} with timeout {} seconds", templatePoolRefId, storagePoolMaxWaitSeconds); + templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); if (templatePoolRef == null) { - if (logger.isDebugEnabled()) { - logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); - } + logger.debug("Unable to acquire lock on VMTemplateStoragePool {}", templatePoolRefId); templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId(), deployAsIsConfiguration); if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { logger.info("Unable to acquire lock on VMTemplateStoragePool {}, But " + @@ -675,9 +671,8 @@ protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStor throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId); } - if (logger.isDebugEnabled()) { - logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId); - } + logger.debug("lock is acquired for VMTemplateStoragePool {}", templatePoolRefId); + try { if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { logger.info("Template {} is already copied to primary storage, skip copying", template.getImage()); @@ -694,9 +689,8 @@ protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStor result.setResult(e.toString()); future.complete(result); } finally { - if (logger.isDebugEnabled()) { - logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); - } + logger.debug("releasing lock for VMTemplateStoragePool {}", templatePoolRefId); + _tmpltPoolDao.releaseFromLockTable(templatePoolRefId); } } diff --git a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java index 8eebc04ee683..351183a87e4a 100644 --- a/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java @@ -533,13 +533,11 @@ public boolean checkIfHostHasCapacity(Host host, Integer cpu, long ram, boolean } else { if (checkFromReservedCapacity) { - logger.debug("STATS: Failed to alloc resource from host: {} reservedCpu: {}, requested cpu: {}, reservedMem: {}, requested mem: {}", host, reservedCpu, cpu, toHumanReadableSize(reservedMem), toHumanReadableSize(ram)); + logger.debug("STATS: Failed to alloc reserved resource from host: {} reservedCpu: {}, requested cpu: {}, reservedMem: {}, requested mem: {}", host, reservedCpu, cpu, toHumanReadableSize(reservedMem), toHumanReadableSize(ram)); + logger.info("{} when checking for reserved resources. Checking for available resources now.", failureReason); } else { logger.debug("STATS: Failed to alloc resource from host: {}, reservedCpu: {}, used cpu: {}, requested cpu: {}, actual total cpu: {}, total cpu with overprovisioning: {}, reservedMem: {}, used Mem: {}, requested mem: {}, total Mem: {}, considerReservedCapacity?: {}", host, reservedCpu, usedCpu, cpu, actualTotalCpu, totalCpu, toHumanReadableSize(reservedMem), toHumanReadableSize(usedMem), toHumanReadableSize(ram), toHumanReadableSize(totalMem), considerReservedCapacity); - } - - if (logger.isDebugEnabled()) { - logger.debug(failureReason + ", cannot allocate to this host."); + logger.info("{} when checking for available resources. Cannot allocate to this host.", failureReason); } } diff --git a/utils/src/main/java/com/cloud/utils/LogUtils.java b/utils/src/main/java/com/cloud/utils/LogUtils.java index 654773ee0a09..162e1a9f03b6 100644 --- a/utils/src/main/java/com/cloud/utils/LogUtils.java +++ b/utils/src/main/java/com/cloud/utils/LogUtils.java @@ -95,7 +95,7 @@ public static String logGsonWithoutException(String formatMessage, Object ... ob } catch (Exception e) { Object errObj = ObjectUtils.defaultIfNull(object, "null"); LOGGER.trace(String.format("Failed to log object [%s] using GSON.", errObj.getClass().getSimpleName())); - gsons.add("error decoding " + errObj); + gsons.add(errObj.toString()); } } try {