You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "julien-vaz (via GitHub)" <gi...@apache.org> on 2025/05/19 14:26:03 UTC

[PR] Consider Quota settings during processing [cloudstack]

julien-vaz opened a new pull request, #10892:
URL: https://github.com/apache/cloudstack/pull/10892

   Consider Quota settings during processing
   
   ### Description
   
   Currently, when using the Quota plugin, it is possible to enable/disable the plugin specifically in the account settings. However, even if the plugin is disabled for the account, the setting is not considered because the Quota manager is failing to get its value, so that the account's Quota balance is always processed. This PR fixes this behavior.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] build/CI
   - [ ] test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [x] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   
   1. A account was created and, before the Usage job was run, the Quota plugin was disabled for the account. It was attested via GUI and logs that the account didn't appear in Quota and it wasn't even processed.
   2. Another account was created with the Quota plugin enabled. After the Usage job was run once and the Quota was processed for the account, the Quota plugin was disabled and on the second run it was attested that the credit was not decremented. 


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "harikrishna-patnala (via GitHub)" <gi...@apache.org>.
harikrishna-patnala commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3322644874

   > As far as I understand this might be a generic problem, ie, ConfigKey.valueIn(accountId) not returning domain-level value when the config `enable.account.settings.for.domain` is set to true. And a change should be added at the ConfigKey level itself. Also, it will be worth checking if the behaviour has been fixed by [2a4a1f7](https://github.com/apache/cloudstack/commit/2a4a1f73d0459792e8254a47a44fa716c97cc29f) as Domain is considered PArent scope for Account scope now.
   
   if we call valueinscope() method, will it work @shwstppr ?


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2164807495


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Oh, don't worry. I've learned in the process. I guess it's enough if we add the `Domain` scope, because `valueInGlobalOrAvailableParentScope()` is being called inside `valueInScope()`. And if the `ConfigKey` has more than one scope in its `scopes`, the parent scope is considered.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2208646343


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Hmm... I guess there's not, because `findConfigurationValue()` is called only before processing the Quota after the Usage Server's job has been run. Both configurations in question are related to the fact that whether you want the Quota to be processed for that account and if so whether you want to send alert emails to the account.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2137817190


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Sure, I'll report later



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-2932542569

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13585


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2161704880


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Hi, @DaanHoogland .
   
   The method `findConfigurationValue()` is being called only for the `quota.account.enabled` and `quota.enable.emails` global configurations. The method `valueInScope()` searches the configuration in the `ConfigCache` for the scope passed as argument, in this case `Account`. If it doesn't find it, it returns the value in global scope or parent scope. To decide which scope to use, it checks in the `scopes` parameter of `ConfigKey`. Since for both configurations the only scope defined is `Account`,  `valueInScope()` returns the global value.
   
   So because the method always return a value, the `if` related to domain settings is never reached.
   
   I tested the `valueInScope()` with both configurations with a `Admin` account and a `Domain Admin` account in a subdomain.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3409931086

   This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-4875718262

   > if we call valueinscope() method, will it work @shwstppr ?
   
   @harikrishna-patnala @shwstppr  it will not. The issue being addressed here is that this code is also executed by the Usage server, and the Usage server is unable to obtain configurations using `<key>.value()`/`<key>.valueIn(...)` because the `ConfigDepotImpl` bean is not instantiated for it (hence, `s_depot` is null in `ConfigKey` and the default value is always returned).
   
   I will investigate how feasible it is to just inject this bean instead before marking it as ready.


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-4831810056

   > @winterhazel does this look good to you ?
   
   @weizhouapache it needs some adjustments. I will work on this one this week.


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3082017919

   <b>[SF] Trillian test result (tid-13798)</b>
   Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
   Total time taken: 54368 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10892-t13798-kvm-ol8.zip
   Smoke tests completed. 142 look OK, 0 have errors, 0 did not run
   Only failed and skipped tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2205558831


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Hi, @DaanHoogland. I was wrong about this.
   
   The `valueInScope()` method only retrieves the configuration value for the desired scope when there is a `ConfigDepot` defined for the `ConfigKey` in question. That `ConfigDepot` is injected via XML only for the Management Server's `ConfigKey`s.
   
   When the Management Server calls the `quotaUpdate` API, it successfully retrieves the value in desired scope for `quota.enable.emails`. However, when the Usage Server begins to process the quota for the accounts, after running its job, and tries to retrieve the values for both configurations (`quota.account.enabled` and `quota.enable.emails`), `valueInScope()` only returns the global value.
   
   Therefore, I think we should keep using the `account_details` and `domain_details` tables for both configurations.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3077637887

   @blueorangutan test


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "JoaoJandre (via GitHub)" <gi...@apache.org>.
JoaoJandre commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-2932288565

   @blueorangutan package


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2166813519


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Hm... I guess it's not necessary.  My point is that the other parts of the `findConfigurationValue()` are never reached because the first `valueInScope()` (needed to retrieve the value in `Account` scope) always return something, whether the value in the scope used as argument or the value in parent or global scope.
   
   So, once we call `valueInScope()` to retrieve the value in `Account` scope, if it doesn't find it, it will search in `Domain` (if we add it to the `ConfigKey`'s `scopes` in question, of course) by calling `valueInGlobalOrAvailableParentScope()`.
   
   That been said, we could simplify the `findConfigurationValue()` method by just calling `valueInScope()`. We would need to add the `Domain` scope to both configurations' `scopes` and adjust the logs to inform which `scope` will be used. Just calling `valueInGlobalOrAvailableParentScope()` won't work because it won't be able to return the value in `Account` scope.
   
   What do you think?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-4829713446

   @winterhazel 
   does this look good to you ?


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "shwstppr (via GitHub)" <gi...@apache.org>.
shwstppr commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2371298703


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));

Review Comment:
   `key.value()`
   
   What is the difference?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3077032277

   @DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with  KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3077026359

   @blueorangutan package


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3077643077

   @DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2127084568


##########
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:
   That makes sense. Done



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-2893196340

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/10892?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 3.97%. Comparing base [(`0934fb1`)](https://app.codecov.io/gh/apache/cloudstack/commit/0934fb1b53e2af4d75ff33cd4951c56e79b83db1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`a6993ef`)](https://app.codecov.io/gh/apache/cloudstack/commit/a6993efbac84825a8a914137aa1ef9ad4656e78c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 139 commits behind head on main.
   
   > :exclamation:  There is a different number of reports uploaded between BASE (0934fb1) and HEAD (a6993ef). Click for more details.
   > 
   > <details><summary>HEAD has 1 upload less than BASE</summary>
   >
   >| Flag | BASE (0934fb1) | HEAD (a6993ef) |
   >|------|------|------|
   >|unittests|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               main   #10892       +/-   ##
   =============================================
   - Coverage     16.30%    3.97%   -12.34%     
   =============================================
     Files          5675      404     -5271     
     Lines        499249    32834   -466415     
     Branches      60377     5816    -54561     
   =============================================
   - Hits          81425     1306    -80119     
   + Misses       408753    31378   -377375     
   + Partials       9071      150     -8921     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/10892/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/10892/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `3.97% <ø> (-0.02%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/10892/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/cloudstack/pull/10892?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2166889680


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   sounds like a plan.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "winterhazel (via GitHub)" <gi...@apache.org>.
winterhazel commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r3519578345


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));

Review Comment:
   See https://github.com/apache/cloudstack/pull/10892#issuecomment-4875718262



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2161804667


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   ok, sorry @julien-vaz , my question was misleading. I think we should we add the `Domain`-scope and use `valueInGlobalOrAvailableParentScope()` to retrieve the value.



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2166980597


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   I'll work on that then commit here



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2210423142


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   No problem



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "nvazquez (via GitHub)" <gi...@apache.org>.
nvazquez commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-5269513746

   Hi @julien-vaz @winterhazel is this PR still in progress?


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-2932291750

   @JoaoJandre a [SL] Jenkins job has been kicked to build packages. It will be bundled with  KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2135158428


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Is the new `ConfigKey.getValueInScope()` applicable here? It seems to have the same purpose.
   If not, can you comment on its shortcomings?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2209360806


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   ok, let’s go for it like this, thanks for investigating @julien-vaz 



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2206573636


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   that is unfortunate, this means usage server will have to keep switching between the two schemas. 
   And it triggered another thought of which I’m not sure of the consequences; the value retrieved is always the latest. Is there any circumstance you’d want to know the value at another point in time?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#issuecomment-3077349591

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 14203


-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "julien-vaz (via GitHub)" <gi...@apache.org>.
julien-vaz commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2166813519


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   Hum... I guess it's not necessary.  My point is that the other parts of the `findConfigurationValue()` are never reached because the first `valueInScope()` (needed to retrieve the value in `Account` scope) always return something, whether the value in the scope used as argument or the value in parent or global scope.
   
   So, once we call `valueInScope()` to retrieve the value in `Account` scope, if it doesn't find it, it will search in `Domain` (if we add it to the `ConfigKey`'s `scopes` in question, of course) by calling `valueInGlobalOrAvailableParentScope()`.
   
   That been said, we could simplify the `findConfigurationValue()` method by just calling `valueInScope()`. We would need to add the `Domain` scope to both configurations' `scopes` and adjust the logs to inform which `scope` will be used. Just calling `valueInGlobalOrAvailableParentScope()` won't work because it won't be able to return the value in `Account` scope.
   
   What do you think?



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Consider Quota settings during processing [cloudstack]

Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #10892:
URL: https://github.com/apache/cloudstack/pull/10892#discussion_r2166023503


##########
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) {
+        logger.trace("Searching configuration [{}] of account [{}] in its settings.", key.key(), accountVO);
+        AccountDetailVO accountDetail = accountDetailsDao.findDetail(accountVO.getAccountId(), key.key());
+        if (accountDetail != null) {
+            boolean result = Boolean.parseBoolean(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) {
+                boolean result = Boolean.parseBoolean(domainDetail.getValue());
+                logger.trace("Using value [{}] found in domain [{}] settings to configuration [{}].", result, accountVO.getDomainId(), key.key());
+                return result;
+            }
+        }
+        boolean result = Boolean.parseBoolean(getConfigValueOrDefaultValue(key));
+        logger.trace("Using default value [{}] to configuration [{}].", result, key.key());
+        return result;
+    }

Review Comment:
   and you aggree we can simplify this code by calling `valueInGlobalOrAvailableParentScope()` ? (this is a genuine question, I really don’ t know and am just guessing)



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org