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 {
@@ -290,8 +294,13 @@ protected void recalculateHostCapacities() {
290294 Math .min (CapacityManager .CapacityCalculateWorkers .value (), hostIds .size ())));
291295 for (Long hostId : hostIds ) {
292296 futures .put (hostId , executorService .submit (() -> {
293- final HostVO host = hostDao .findById (hostId );
294- _capacityMgr .updateCapacityForHost (host );
297+ Transaction .execute (new TransactionCallbackNoReturn () {
298+ @ Override
299+ public void doInTransactionWithoutResult (TransactionStatus status ) {
300+ final HostVO host = hostDao .findById (hostId );
301+ _capacityMgr .updateCapacityForHost (host );
302+ }
303+ });
295304 return null ;
296305 }));
297306 }
@@ -316,13 +325,18 @@ protected void recalculateStorageCapacities() {
316325 Math .min (CapacityManager .CapacityCalculateWorkers .value (), storagePoolIds .size ())));
317326 for (Long poolId : storagePoolIds ) {
318327 futures .put (poolId , executorService .submit (() -> {
319- final StoragePoolVO pool = _storagePoolDao .findById (poolId );
320- long disk = _capacityMgr .getAllocatedPoolCapacity (pool , null );
321- if (pool .isShared ()) {
322- _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , disk );
323- } else {
324- _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_LOCAL_STORAGE , disk );
325- }
328+ Transaction .execute (new TransactionCallbackNoReturn () {
329+ @ Override
330+ public void doInTransactionWithoutResult (TransactionStatus status ) {
331+ final StoragePoolVO pool = _storagePoolDao .findById (poolId );
332+ long disk = _capacityMgr .getAllocatedPoolCapacity (pool , null );
333+ if (pool .isShared ()) {
334+ _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , disk );
335+ } else {
336+ _storageMgr .createCapacityEntry (pool , Capacity .CAPACITY_TYPE_LOCAL_STORAGE , disk );
337+ }
338+ }
339+ });
326340 return null ;
327341 }));
328342 }
0 commit comments