framework/cluster: fix NPE for ms-host status when mgr stops (#10500)

* framework/cluster: fix NPE for ms-host status when mgr stops

This handles an NPE case for when management server host status is not
found in the DB, when stopping the cluster manager.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

* Update framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java

Co-authored-by: dahn <daan.hoogland@gmail.com>

* Update framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java

---------

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
Co-authored-by: dahn <daan.hoogland@gmail.com>
This commit is contained in:
Rohit Yadav 2025-03-27 16:47:12 +05:30 committed by GitHub
parent 7f3f104295
commit f47bd61279
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1107,9 +1107,19 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C
if (_mshostId != null) {
final ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId);
if (mshost != null) {
final ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
mshostStatus.setLastJvmStop(new Date());
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
if (mshostStatus != null) {
mshostStatus.setLastJvmStop(new Date());
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
} else {
logger.warn("Found a management server host [{}] without a status. This should never happen!", mshost);
mshostStatus = new ManagementServerStatusVO();
mshostStatus.setMsId(mshost.getUuid());
mshostStatus.setLastSystemBoot(new Date());
mshostStatus.setLastJvmStart(new Date());
mshostStatus.setUpdated(new Date());
mshostStatusDao.persist(mshostStatus);
}
ManagementServerHost.State msHostState = ManagementServerHost.State.Down;
if (ManagementServerHost.State.Maintenance.equals(mshost.getState()) || ManagementServerHost.State.PreparingForMaintenance.equals(mshost.getState())) {