If ResourceCountCheckTask throws an exception the scheduled task is not going to run again until the management servers are restarted. (#7670)

Co-authored-by: Maxim Prokopchuk <mprokopchuk@apple.com>
This commit is contained in:
mprokopchuk 2023-07-03 23:45:15 -07:00 committed by GitHub
parent 3c5fdeafdc
commit 70d5470f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 4 deletions

View File

@ -1156,12 +1156,28 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
@Override
protected void runInContext() {
s_logger.info("Started resource counters recalculation periodic task.");
List<DomainVO> domains = _domainDao.findImmediateChildrenForParent(Domain.ROOT_DOMAIN);
List<AccountVO> accounts = _accountDao.findActiveAccountsForDomain(Domain.ROOT_DOMAIN);
List<DomainVO> domains;
List<AccountVO> accounts;
// try/catch task, otherwise it won't be rescheduled in case of exception
try {
domains = _domainDao.findImmediateChildrenForParent(Domain.ROOT_DOMAIN);
} catch (Exception e) {
s_logger.warn("Resource counters recalculation periodic task failed, unable to fetch immediate children for the domain " + Domain.ROOT_DOMAIN, e);
// initialize domains as empty list to do best effort recalculation
domains = new ArrayList<>();
}
// try/catch task, otherwise it won't be rescheduled in case of exception
try {
accounts = _accountDao.findActiveAccountsForDomain(Domain.ROOT_DOMAIN);
} catch (Exception e) {
s_logger.warn("Resource counters recalculation periodic task failed, unable to fetch active accounts for domain " + Domain.ROOT_DOMAIN, e);
// initialize accounts as empty list to do best effort recalculation
accounts = new ArrayList<>();
}
for (ResourceType type : ResourceType.values()) {
if (type.supportsOwner(ResourceOwnerType.Domain)) {
recalculateDomainResourceCount(Domain.ROOT_DOMAIN, type);
recalculateDomainResourceCountInContext(Domain.ROOT_DOMAIN, type);
for (Domain domain : domains) {
recalculateDomainResourceCount(domain.getId(), type);
}
@ -1170,10 +1186,25 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
if (type.supportsOwner(ResourceOwnerType.Account)) {
// run through the accounts in the root domain
for (AccountVO account : accounts) {
recalculateAccountResourceCount(account.getId(), type);
recalculateAccountResourceCountInContext(account.getId(), type);
}
}
}
}
private void recalculateDomainResourceCountInContext(long domainId, ResourceType type) {
try {
recalculateDomainResourceCount(domainId, type);
} catch (Exception e) {
s_logger.warn("Resource counters recalculation periodic task failed for the domain " + domainId + " and the resource type " + type + " .", e);
}
}
private void recalculateAccountResourceCountInContext(long accountId, ResourceType type) {
try {
recalculateAccountResourceCount(accountId, type);
} catch (Exception e) {
s_logger.warn("Resource counters recalculation periodic task failed for the account " + accountId + " and the resource type " + type + " .", e);
}
}
}
}