Skip to content

Commit d32065f

Browse files
backport #10500 framework/cluster: fix NPE for ms-host status when mgr stops (#10653)
1 parent 5d5ac17 commit d32065f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,12 +1052,24 @@ public boolean stop() {
10521052
}
10531053

10541054
if (_mshostId != null) {
1055-
final ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId);
1056-
final ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
1057-
mshost.setState(ManagementServerHost.State.Down);
1058-
mshostStatus.setLastJvmStop(new Date());
1059-
_mshostDao.update(_mshostId, mshost);
1060-
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
1055+
ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId);
1056+
if (mshost != null) {
1057+
ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
1058+
if (mshostStatus != null) {
1059+
mshost.setState(ManagementServerHost.State.Down);
1060+
mshostStatus.setLastJvmStop(new Date());
1061+
_mshostDao.update(_mshostId, mshost);
1062+
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
1063+
} else {
1064+
s_logger.warn(String.format("Found a management server host [%s] without a status. This should never happen!", mshost));
1065+
mshostStatus = new ManagementServerStatusVO();
1066+
mshostStatus.setMsId(mshost.getUuid());
1067+
mshostStatus.setLastSystemBoot(new Date());
1068+
mshostStatus.setLastJvmStart(new Date());
1069+
mshostStatus.setUpdated(new Date());
1070+
mshostStatusDao.persist(mshostStatus);
1071+
}
1072+
}
10611073
}
10621074

10631075
_heartbeatScheduler.shutdownNow();

0 commit comments

Comments
 (0)