winterhazel commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2126699551
##########
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java:
##########
@@ -340,12 +349,41 @@ protected List<QuotaUsageVO>
createQuotaUsagesAccordingToQuotaTariffs(AccountVO
}
protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO
usageRecord) {
- if
(Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId())))
{
+ boolean calculateUsageRecord = findConfigurationValue(accountVO,
QuotaConfig.QuotaAccountEnabled);
+ if (!calculateUsageRecord && usageRecord != null) {
logger.debug("Considering usage record [{}] as calculated and
skipping it because account [{}] has the quota plugin disabled.",
usageRecord.toString(usageAggregationTimeZone),
accountVO.reflectionToString());
return false;
}
- return true;
+ return calculateUsageRecord;
+ }
+
+ @Override
+ public boolean findConfigurationValue(AccountVO accountVO,
ConfigKey<Boolean> key) {
+ boolean result =
Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
Review Comment:
I would move this DB access to the end of the method
##########
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java:
##########
@@ -340,12 +349,41 @@ protected List<QuotaUsageVO>
createQuotaUsagesAccordingToQuotaTariffs(AccountVO
}
protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO
usageRecord) {
- if
(Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId())))
{
+ boolean calculateUsageRecord = findConfigurationValue(accountVO,
QuotaConfig.QuotaAccountEnabled);
+ if (!calculateUsageRecord && usageRecord != null) {
logger.debug("Considering usage record [{}] as calculated and
skipping it because account [{}] has the quota plugin disabled.",
usageRecord.toString(usageAggregationTimeZone),
accountVO.reflectionToString());
return false;
}
- return true;
+ return calculateUsageRecord;
+ }
+
+ @Override
+ public boolean findConfigurationValue(AccountVO accountVO,
ConfigKey<Boolean> key) {
+ boolean result =
Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+ logger.trace("Searching configuration [{}] of account [{}] in its
settings.", key.key(), accountVO);
+ AccountDetailVO accountDetail =
accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+ if (accountDetail != null) {
+ result =
Boolean.TRUE.equals(Boolean.valueOf(accountDetail.getValue()));
Review Comment:
```suggestion
result = Boolean.parseBoolean(accountDetail.getValue());
```
This can be simplified
##########
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java:
##########
@@ -340,12 +349,41 @@ protected List<QuotaUsageVO>
createQuotaUsagesAccordingToQuotaTariffs(AccountVO
}
protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO
usageRecord) {
- if
(Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId())))
{
+ boolean calculateUsageRecord = findConfigurationValue(accountVO,
QuotaConfig.QuotaAccountEnabled);
+ if (!calculateUsageRecord && usageRecord != null) {
logger.debug("Considering usage record [{}] as calculated and
skipping it because account [{}] has the quota plugin disabled.",
usageRecord.toString(usageAggregationTimeZone),
accountVO.reflectionToString());
return false;
}
- return true;
+ return calculateUsageRecord;
+ }
+
+ @Override
+ public boolean findConfigurationValue(AccountVO accountVO,
ConfigKey<Boolean> key) {
+ boolean result =
Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+ logger.trace("Searching configuration [{}] of account [{}] in its
settings.", key.key(), accountVO);
+ AccountDetailVO accountDetail =
accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+ if (accountDetail != null) {
+ result =
Boolean.TRUE.equals(Boolean.valueOf(accountDetail.getValue()));
+ logger.trace("Using value [{}] found in account [{}] settings to
configuration [{}].", result, accountVO, key.key());
+ return result;
+ }
+
+ if
(Boolean.parseBoolean(_configDao.getValue("enable.account.settings.for.domain")))
{
+ logger.trace("Searching for configuration [{}] of account [{}] in
its domain [{}] settings.", key.key(), accountVO, accountVO.getDomainId());
+ DomainDetailVO domainDetail =
domainDetailsDao.findDetail(accountVO.getDomainId(), key.key());
+ if (domainDetail != null) {
+ result =
Boolean.TRUE.equals(Boolean.valueOf(domainDetail.getValue()));
Review Comment:
```suggestion
result = Boolean.parseBoolean(domainDetail.getValue());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]