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

Pearl1594 pushed a commit to branch prevent-cpvm-stop-multims
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 05089c6347eb7ddf22619c584bf6d3b56a35e99a
Author: Pearl1594 <[email protected]>
AuthorDate: Tue Oct 13 13:55:13 2026 -0400

    CPVM: Read console proxy management state from DB
---
 .../cloud/consoleproxy/ConsoleProxyManager.java    |  4 +--
 .../consoleproxy/ConsoleProxyManagerImpl.java      | 31 +++++++-------------
 .../consoleproxy/ConsoleProxyManagerImplTest.java  | 34 ++++++++++++++++++++++
 3 files changed, 47 insertions(+), 22 deletions(-)

diff --git 
a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java 
b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
index 4e71d78fcbb..af971d7c8ba 100644
--- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
+++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
@@ -92,10 +92,10 @@ public interface ConsoleProxyManager extends Manager, 
ConsoleProxyService {
 
     String consoleProxyManagementStates = 
Arrays.stream(com.cloud.consoleproxy.ConsoleProxyManagementState.values()).map(Enum::name).collect(Collectors.joining(","));
     ConfigKey<String> ConsoleProxyServiceManagementState = new 
ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, 
"consoleproxy.management.state", 
com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
-            "console proxy service management state", false, 
ConfigKey.Kind.Select, consoleProxyManagementStates);
+            "console proxy service management state", true, 
ConfigKey.Kind.Select, consoleProxyManagementStates);
 
     ConfigKey<String> ConsoleProxyManagementLastState = new 
ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, 
"consoleproxy.management.state.last", 
com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
-            "last console proxy service management state", false, 
ConfigKey.Kind.Select, consoleProxyManagementStates);
+            "last console proxy service management state", true, 
ConfigKey.Kind.Select, consoleProxyManagementStates);
 
     ConfigKey<String> ConsoleProxyVmUserData = new ConfigKey<>(String.class, 
"console.proxy.vm.userdata",
             ConfigKey.CATEGORY_ADVANCED, "",
diff --git 
a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java 
b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 796fa7b48a1..5a8a0644a06 100644
--- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -1011,18 +1011,21 @@ public class ConsoleProxyManagerImpl extends 
ManagerBase implements ConsoleProxy
 
     @Override
     public ConsoleProxyManagementState getManagementState() {
-        String configKey = ConsoleProxyServiceManagementState.key();
-        String value = ConsoleProxyServiceManagementState.value();
+        return readManagementState(ConsoleProxyServiceManagementState);
+    }
 
-        if (value != null) {
-            ConsoleProxyManagementState state = 
ConsoleProxyManagementState.valueOf(value);
+    private ConsoleProxyManagementState readManagementState(ConfigKey<String> 
configKey) {
+        String value = configurationDao.getValue(configKey.key());
 
-            if (state != null) {
-                return state;
+        if (value != null) {
+            try {
+                return ConsoleProxyManagementState.valueOf(value);
+            } catch (IllegalArgumentException e) {
+                logger.debug("Unable to parse console proxy management state 
[{}]", value, e);
             }
         }
 
-        logger.error(String.format("Value [%s] set in global configuration 
[%s] is not a valid console proxy management state.", value, configKey));
+        logger.error("Value [{}] set in global configuration [{}] is not a 
valid console proxy management state.", value, configKey.key());
         return null;
     }
 
@@ -1045,19 +1048,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
     }
 
     private ConsoleProxyManagementState getLastManagementState() {
-        String configKey = ConsoleProxyManagementLastState.key();
-        String value = ConsoleProxyManagementLastState.value();
-
-        if (value != null) {
-            ConsoleProxyManagementState state = 
ConsoleProxyManagementState.valueOf(value);
-
-            if (state != null) {
-                return state;
-            }
-        }
-
-        logger.error(String.format("Value [%s] set in global configuration 
[%s] is not a valid console proxy management state.", value, configKey));
-        return null;
+        return readManagementState(ConsoleProxyManagementLastState);
     }
 
     @Override
diff --git 
a/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerImplTest.java 
b/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerImplTest.java
index 1feced5f464..28e0b4a9d5d 100644
--- 
a/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerImplTest.java
+++ 
b/server/src/test/java/com/cloud/consoleproxy/ConsoleProxyManagerImplTest.java
@@ -18,10 +18,12 @@ package com.cloud.consoleproxy;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -49,6 +51,9 @@ public class ConsoleProxyManagerImplTest {
     @Mock
     private AccountManager accountManager;
 
+    @Mock
+    private ConfigurationDao configurationDao;
+
     @Mock
     private ServiceOffering serviceOffering;
     @Mock
@@ -104,4 +109,33 @@ public class ConsoleProxyManagerImplTest {
         assertEquals(template.getGuestOSId(), result.getGuestOSId());
         assertEquals(template.isDynamicallyScalable(), 
result.isDynamicallyScalable());
     }
+
+    @Test
+    public void testGetManagementStateReadsCurrentValueFromDb() {
+        
when(configurationDao.getValue(ConsoleProxyManager.ConsoleProxyServiceManagementState.key()))
+                
.thenReturn(ConsoleProxyManagementState.ResetSuspending.toString(), 
ConsoleProxyManagementState.Auto.toString());
+
+        assertEquals(ConsoleProxyManagementState.ResetSuspending, 
consoleProxyManager.getManagementState());
+        assertEquals(ConsoleProxyManagementState.Auto, 
consoleProxyManager.getManagementState());
+    }
+
+    @Test
+    public void testGetManagementStateInvalidValueReturnsNull() {
+        
when(configurationDao.getValue(ConsoleProxyManager.ConsoleProxyServiceManagementState.key())).thenReturn("Bogus");
+
+        assertNull(consoleProxyManager.getManagementState());
+    }
+
+    @Test
+    public void testResumeLastManagementStateUpdatesDb() {
+        
when(configurationDao.getValue(ConsoleProxyManager.ConsoleProxyServiceManagementState.key()))
+                
.thenReturn(ConsoleProxyManagementState.ResetSuspending.toString());
+        
when(configurationDao.getValue(ConsoleProxyManager.ConsoleProxyManagementLastState.key()))
+                .thenReturn(ConsoleProxyManagementState.Auto.toString());
+
+        consoleProxyManager.resumeLastManagementState();
+
+        
verify(configurationDao).update(ConsoleProxyManager.ConsoleProxyServiceManagementState.key(),
+                
ConsoleProxyManager.ConsoleProxyServiceManagementState.category(), 
ConsoleProxyManagementState.Auto.toString());
+    }
 }

Reply via email to