Skip to content

Commit f47bd61

Browse files
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 <[email protected]> * Update framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java Co-authored-by: dahn <[email protected]> * Update framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java --------- Signed-off-by: Rohit Yadav <[email protected]> Co-authored-by: dahn <[email protected]>
1 parent 7f3f104 commit f47bd61

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,19 @@ public boolean stop() {
11071107
if (_mshostId != null) {
11081108
final ManagementServerHostVO mshost = _mshostDao.findByMsid(_msId);
11091109
if (mshost != null) {
1110-
final ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
1111-
mshostStatus.setLastJvmStop(new Date());
1112-
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
1110+
ManagementServerStatusVO mshostStatus = mshostStatusDao.findByMsId(mshost.getUuid());
1111+
if (mshostStatus != null) {
1112+
mshostStatus.setLastJvmStop(new Date());
1113+
mshostStatusDao.update(mshostStatus.getId(), mshostStatus);
1114+
} else {
1115+
logger.warn("Found a management server host [{}] without a status. This should never happen!", mshost);
1116+
mshostStatus = new ManagementServerStatusVO();
1117+
mshostStatus.setMsId(mshost.getUuid());
1118+
mshostStatus.setLastSystemBoot(new Date());
1119+
mshostStatus.setLastJvmStart(new Date());
1120+
mshostStatus.setUpdated(new Date());
1121+
mshostStatusDao.persist(mshostStatus);
1122+
}
11131123

11141124
ManagementServerHost.State msHostState = ManagementServerHost.State.Down;
11151125
if (ManagementServerHost.State.Maintenance.equals(mshost.getState()) || ManagementServerHost.State.PreparingForMaintenance.equals(mshost.getState())) {

0 commit comments

Comments
 (0)