|
32 | 32 | import javax.inject.Inject; |
33 | 33 | import javax.naming.ConfigurationException; |
34 | 34 |
|
| 35 | +import com.cloud.domain.DomainDetailVO; |
| 36 | +import com.cloud.domain.dao.DomainDetailsDao; |
35 | 37 | import com.cloud.user.Account; |
| 38 | +import com.cloud.user.AccountDetailVO; |
| 39 | +import com.cloud.user.AccountDetailsDao; |
| 40 | +import org.apache.cloudstack.framework.config.ConfigKey; |
36 | 41 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
37 | 42 | import org.apache.cloudstack.quota.activationrule.presetvariables.Configuration; |
38 | 43 | import org.apache.cloudstack.quota.activationrule.presetvariables.GenericPresetVariable; |
@@ -89,6 +94,10 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { |
89 | 94 |
|
90 | 95 | @Inject |
91 | 96 | protected PresetVariableHelper presetVariableHelper; |
| 97 | + @Inject |
| 98 | + protected AccountDetailsDao accountDetailsDao; |
| 99 | + @Inject |
| 100 | + protected DomainDetailsDao domainDetailsDao; |
92 | 101 |
|
93 | 102 | private static TimeZone usageAggregationTimeZone = TimeZone.getTimeZone("GMT"); |
94 | 103 | static final BigDecimal GiB_DECIMAL = BigDecimal.valueOf(ByteScaleUtils.GiB); |
@@ -340,12 +349,41 @@ protected List<QuotaUsageVO> createQuotaUsagesAccordingToQuotaTariffs(AccountVO |
340 | 349 | } |
341 | 350 |
|
342 | 351 | protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageRecord) { |
343 | | - if (Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId()))) { |
| 352 | + boolean calculateUsageRecord = findConfigurationValue(accountVO, QuotaConfig.QuotaAccountEnabled); |
| 353 | + if (!calculateUsageRecord && usageRecord != null) { |
344 | 354 | logger.debug("Considering usage record [{}] as calculated and skipping it because account [{}] has the quota plugin disabled.", |
345 | 355 | usageRecord.toString(usageAggregationTimeZone), accountVO.reflectionToString()); |
346 | 356 | return false; |
347 | 357 | } |
348 | | - return true; |
| 358 | + return calculateUsageRecord; |
| 359 | + } |
| 360 | + |
| 361 | + @Override |
| 362 | + public boolean findConfigurationValue(AccountVO accountVO, ConfigKey<Boolean> key) { |
| 363 | + boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key)); |
| 364 | + logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO); |
| 365 | + AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key()); |
| 366 | + if (accountDetail != null) { |
| 367 | + result = Boolean.TRUE.equals(Boolean.valueOf(accountDetail.getValue())); |
| 368 | + logger.trace("Using value [{}] found in account [{}] settings to configuration [{}].", result, accountVO, key.key()); |
| 369 | + return result; |
| 370 | + } |
| 371 | + |
| 372 | + if (Boolean.parseBoolean(_configDao.getValue("enable.account.settings.for.domain"))) { |
| 373 | + logger.trace("Searching for configuration [{}] of account [{}] in its domain [{}] settings.", key.key(), accountVO, accountVO.getDomainId()); |
| 374 | + DomainDetailVO domainDetail = domainDetailsDao.findDetail(accountVO.getDomainId(), key.key()); |
| 375 | + if (domainDetail != null) { |
| 376 | + result = Boolean.TRUE.equals(Boolean.valueOf(domainDetail.getValue())); |
| 377 | + logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key()); |
| 378 | + return result; |
| 379 | + } |
| 380 | + } |
| 381 | + logger.trace("Using default value [{}] to configuration [{}].", result, key.key()); |
| 382 | + return result; |
| 383 | + } |
| 384 | + |
| 385 | + protected String getConfigValueOrDefaultValue(ConfigKey<?> key) { |
| 386 | + return ObjectUtils.defaultIfNull(_configDao.getValue(key.key()), key.defaultValue()); |
349 | 387 | } |
350 | 388 |
|
351 | 389 | protected List<QuotaUsageVO> persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsages(List<Pair<UsageVO, QuotaUsageVO>> pairsUsageAndQuotaUsage) { |
|
0 commit comments