8989import com .cloud .utils .component .ManagerBase ;
9090import com .cloud .utils .concurrency .NamedThreadFactory ;
9191import com .cloud .utils .db .SearchCriteria ;
92+ import com .cloud .utils .db .Transaction ;
93+ import com .cloud .utils .db .TransactionCallbackNoReturn ;
94+ import com .cloud .utils .db .TransactionStatus ;
95+
9296import org .jetbrains .annotations .Nullable ;
9397
9498public class AlertManagerImpl extends ManagerBase implements AlertManager , Configurable {
@@ -303,8 +307,13 @@ protected void recalculateHostCapacities() {
303307 Math .min (CapacityManager .CapacityCalculateWorkers .value (), hostIds .size ())));
304308 for (Long hostId : hostIds ) {
305309 futures .put (hostId , executorService .submit (() -> {
306- final HostVO host = hostDao .findById (hostId );
307- _capacityMgr .updateCapacityForHost (host );
310+ Transaction .execute (new TransactionCallbackNoReturn () {
311+ @ Override
312+ public void doInTransactionWithoutResult (TransactionStatus status ) {
313+ final HostVO host = hostDao .findById (hostId );
314+ _capacityMgr .updateCapacityForHost (host );
315+ }
316+ });
308317 return null ;
309318 }));
310319 }
@@ -329,13 +338,18 @@ protected void recalculateStorageCapacities() {
329338 Math .min (CapacityManager .CapacityCalculateWorkers .value (), storagePoolIds .size ())));
330339 for (Long poolId : storagePoolIds ) {
331340 futures .put (poolId , executorService .submit (() -> {
332- final StoragePoolVO pool = _storagePoolDao .findById (poolId );
333- long disk = _capacityMgr .getAllocatedPoolCapacity (pool , null );
334- if (pool .isShared ()) {
335- _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , disk );
336- } else {
337- _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_LOCAL_STORAGE , disk );
338- }
341+ Transaction .execute (new TransactionCallbackNoReturn () {
342+ @ Override
343+ public void doInTransactionWithoutResult (TransactionStatus status ) {
344+ final StoragePoolVO pool = _storagePoolDao .findById (poolId );
345+ long disk = _capacityMgr .getAllocatedPoolCapacity (pool , null );
346+ if (pool .isShared ()) {
347+ _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , disk );
348+ } else {
349+ _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_LOCAL_STORAGE , disk );
350+ }
351+ }
352+ });
339353 return null ;
340354 }));
341355 }
0 commit comments