@@ -1156,12 +1156,28 @@ public ResourceCountCheckTask() {
11561156 @ Override
11571157 protected void runInContext () {
11581158 s_logger .info ("Started resource counters recalculation periodic task." );
1159- List <DomainVO > domains = _domainDao .findImmediateChildrenForParent (Domain .ROOT_DOMAIN );
1160- List <AccountVO > accounts = _accountDao .findActiveAccountsForDomain (Domain .ROOT_DOMAIN );
1159+ List <DomainVO > domains ;
1160+ List <AccountVO > accounts ;
1161+ // try/catch task, otherwise it won't be rescheduled in case of exception
1162+ try {
1163+ domains = _domainDao .findImmediateChildrenForParent (Domain .ROOT_DOMAIN );
1164+ } catch (Exception e ) {
1165+ s_logger .warn ("Resource counters recalculation periodic task failed, unable to fetch immediate children for the domain " + Domain .ROOT_DOMAIN , e );
1166+ // initialize domains as empty list to do best effort recalculation
1167+ domains = new ArrayList <>();
1168+ }
1169+ // try/catch task, otherwise it won't be rescheduled in case of exception
1170+ try {
1171+ accounts = _accountDao .findActiveAccountsForDomain (Domain .ROOT_DOMAIN );
1172+ } catch (Exception e ) {
1173+ s_logger .warn ("Resource counters recalculation periodic task failed, unable to fetch active accounts for domain " + Domain .ROOT_DOMAIN , e );
1174+ // initialize accounts as empty list to do best effort recalculation
1175+ accounts = new ArrayList <>();
1176+ }
11611177
11621178 for (ResourceType type : ResourceType .values ()) {
11631179 if (type .supportsOwner (ResourceOwnerType .Domain )) {
1164- recalculateDomainResourceCount (Domain .ROOT_DOMAIN , type );
1180+ recalculateDomainResourceCountInContext (Domain .ROOT_DOMAIN , type );
11651181 for (Domain domain : domains ) {
11661182 recalculateDomainResourceCount (domain .getId (), type );
11671183 }
@@ -1170,10 +1186,25 @@ protected void runInContext() {
11701186 if (type .supportsOwner (ResourceOwnerType .Account )) {
11711187 // run through the accounts in the root domain
11721188 for (AccountVO account : accounts ) {
1173- recalculateAccountResourceCount (account .getId (), type );
1189+ recalculateAccountResourceCountInContext (account .getId (), type );
11741190 }
11751191 }
11761192 }
11771193 }
1194+
1195+ private void recalculateDomainResourceCountInContext (long domainId , ResourceType type ) {
1196+ try {
1197+ recalculateDomainResourceCount (domainId , type );
1198+ } catch (Exception e ) {
1199+ s_logger .warn ("Resource counters recalculation periodic task failed for the domain " + domainId + " and the resource type " + type + " ." , e );
1200+ }
1201+ }
1202+ private void recalculateAccountResourceCountInContext (long accountId , ResourceType type ) {
1203+ try {
1204+ recalculateAccountResourceCount (accountId , type );
1205+ } catch (Exception e ) {
1206+ s_logger .warn ("Resource counters recalculation periodic task failed for the account " + accountId + " and the resource type " + type + " ." , e );
1207+ }
1208+ }
11781209 }
11791210}
0 commit comments