This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new f47bd61279c framework/cluster: fix NPE for ms-host status when mgr 
stops (#10500)
f47bd61279c is described below

commit f47bd61279cb3d8320d5eae48e55ac5fd969de26
Author: Rohit Yadav <[email protected]>
AuthorDate: Thu Mar 27 16:47:12 2025 +0530

    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]>
---
 .../main/java/com/cloud/cluster/ClusterManagerImpl.java  | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 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 1b45910b88a..d2c85b498f2 100644
--- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java
+++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java
@@ -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())) {

Reply via email to