From d32065fd38a2b9216efa28a6890ae6dfc504daca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernardo=20De=20Marco=20Gon=C3=A7alves?= Date: Wed, 9 Apr 2025 09:20:51 -0300 Subject: [PATCH] backport #10500 framework/cluster: fix NPE for ms-host status when mgr stops (#10653) --- .../com/cloud/cluster/ClusterManagerImpl.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java index d601c094ca7..e684f6fd42f 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java @@ -1052,12 +1052,24 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } if (_mshostId != null) { - final ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId); - final ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid()); - mshost.setState(ManagementServerHost.State.Down); - mshostStatus.setLastJvmStop(new Date()); - _mshostDao.update(_mshostId, mshost); - mshostStatusDao.update(mshostStatus.getId(), mshostStatus); + ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId); + if (mshost != null) { + ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid()); + if (mshostStatus != null) { + mshost.setState(ManagementServerHost.State.Down); + mshostStatus.setLastJvmStop(new Date()); + _mshostDao.update(_mshostId, mshost); + mshostStatusDao.update(mshostStatus.getId(), mshostStatus); + } else { + s_logger.warn(String.format("Found a management server host [%s] 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); + } + } } _heartbeatScheduler.shutdownNow();