Skip to content

Commit ccdc671

Browse files
committed
change
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 9f61383 commit ccdc671

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,17 @@ public void updateCapacityForHost(final Host host) {
823823
cpuCoreCap.setUsedCapacity(usedCpuCore);
824824
}
825825
}
826-
try {
827-
_capacityDao.update(cpuCoreCap.getId(), cpuCoreCap);
828-
} catch (Exception e) {
829-
logger.error("Caught exception while updating cpucore capacity for the host {}", host, e);
830-
}
826+
final CapacityVO cpuCoreCapFinal = cpuCoreCap;
827+
Transaction.execute(new TransactionCallbackNoReturn() {
828+
@Override
829+
public void doInTransactionWithoutResult(TransactionStatus status) {
830+
try {
831+
_capacityDao.update(cpuCoreCapFinal.getId(), cpuCoreCapFinal);
832+
} catch (Exception e) {
833+
logger.error("Caught exception while updating cpucore capacity for the host {}", host, e);
834+
}
835+
}
836+
});
831837
} else {
832838
final long usedCpuCoreFinal = usedCpuCore;
833839
final long reservedCpuCoreFinal = reservedCpuCore;
@@ -903,12 +909,19 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
903909
}
904910
}
905911

906-
try {
907-
_capacityDao.update(cpuCap.getId(), cpuCap);
908-
_capacityDao.update(memCap.getId(), memCap);
909-
} catch (Exception e) {
910-
logger.error("Caught exception while updating cpu/memory capacity for the host {}", host, e);
911-
}
912+
final CapacityVO cpuCapFinal = cpuCap;
913+
final CapacityVO memCapFinal = memCap;
914+
Transaction.execute(new TransactionCallbackNoReturn() {
915+
@Override
916+
public void doInTransactionWithoutResult(TransactionStatus status) {
917+
try {
918+
_capacityDao.update(cpuCapFinal.getId(), cpuCapFinal);
919+
_capacityDao.update(memCapFinal.getId(), memCapFinal);
920+
} catch (Exception e) {
921+
logger.error("Caught exception while updating cpu/memory capacity for the host {}", host, e);
922+
}
923+
}
924+
});
912925
} else {
913926
final long usedMemoryFinal = usedMemory;
914927
final long reservedMemoryFinal = reservedMemory;

0 commit comments

Comments
 (0)