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

pearl11594 pushed a commit to branch change-cp-settings-to-zonelevel
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to 
refs/heads/change-cp-settings-to-zonelevel by this push:
     new b8c2c3b2e52 move consoleproxy service offering to zone level
b8c2c3b2e52 is described below

commit b8c2c3b2e52620a1d9db69d056aca7cff04f8c6a
Author: Pearl Dsilva <[email protected]>
AuthorDate: Thu Aug 7 18:14:23 2025 -0400

    move consoleproxy service offering to zone level
---
 .../main/java/com/cloud/configuration/Config.java  | 11 ---
 .../cloud/consoleproxy/ConsoleProxyManager.java    |  3 +
 .../consoleproxy/ConsoleProxyManagerImpl.java      | 80 +++++++++++-----------
 3 files changed, 43 insertions(+), 51 deletions(-)

diff --git a/server/src/main/java/com/cloud/configuration/Config.java 
b/server/src/main/java/com/cloud/configuration/Config.java
index ebf777ee640..6a05ce227a7 100644
--- a/server/src/main/java/com/cloud/configuration/Config.java
+++ b/server/src/main/java/com/cloud/configuration/Config.java
@@ -403,9 +403,6 @@ public enum Config {
             "service monitoring in router enable/disable option, default 
false", null),
 
 
-    // Console Proxy
-
-
     // Snapshots
 
     SnapshotPollInterval(
@@ -1499,14 +1496,6 @@ public enum Config {
             "false",
             "Should be set to true, if there will be multiple NetScaler 
devices providing EIP service in a zone",
             null),
-    ConsoleProxyServiceOffering(
-            "Advanced",
-            ManagementServer.class,
-            String.class,
-            "consoleproxy.service.offering",
-            null,
-            "Uuid of the service offering used by console proxy; if NULL - 
system offering will be used",
-            null),
     SecondaryStorageServiceOffering(
             "Advanced",
             ManagementServer.class,
diff --git 
a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java 
b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
index f804f99253d..801d62d1f96 100644
--- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
+++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java
@@ -56,6 +56,9 @@ public interface ConsoleProxyManager extends Manager, 
ConsoleProxyService {
     ConfigKey<Boolean> NoVncConsoleSourceIpCheckEnabled = new 
ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, 
"novnc.console.sourceip.check.enabled", "false",
         "If true, The source IP to access novnc console must be same as the IP 
in request to management server for console URL. Needs to reconnect CPVM to 
management server when this changes (via restart CPVM, or management server, or 
cloud service in CPVM)", false);
 
+    ConfigKey<String> ConsoleProxyServiceOffering = new 
ConfigKey<>(String.class, "consoleproxy.service.offering", "Console Proxy", 
null,
+            "Uuid of the service offering used by console proxy; if NULL - 
system offering will be used", false, ConfigKey.Scope.Zone, null);
+
     ConfigKey<String> ConsoleProxyCapacityStandby = new 
ConfigKey<>(String.class, "consoleproxy.capacity.standby", "Console Proxy", 
String.valueOf(DEFAULT_STANDBY_CAPACITY),
             "The minimal number of console proxy viewer sessions that system 
is able to serve immediately(standby capacity)", false, ConfigKey.Scope.Zone, 
null);
 
diff --git 
a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java 
b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index fbf72d074b2..e19204f8f47 100644
--- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -230,8 +230,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
 
     private ConsoleProxyListener consoleProxyListener;
 
-    private ServiceOfferingVO serviceOfferingVO;
-
     private long capacityScanInterval = 
DEFAULT_CAPACITY_SCAN_INTERVAL_IN_MILLISECONDS;
 
     private boolean useStorageVm;
@@ -557,7 +555,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         return null;
     }
 
-    public ConsoleProxyVO startNew(long dataCenterId) throws 
ConcurrentOperationException {
+    public ConsoleProxyVO startNew(long dataCenterId) throws 
ConcurrentOperationException, ConfigurationException {
 
         if (logger.isDebugEnabled()) {
             logger.debug("Assign console proxy from a newly started instance 
for request from data center : " + dataCenterId);
@@ -689,7 +687,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         return proxy;
     }
 
-    protected Map<String, Object> createProxyInstance(long dataCenterId, 
List<VMTemplateVO> templates) throws ConcurrentOperationException {
+    protected Map<String, Object> createProxyInstance(long dataCenterId, 
List<VMTemplateVO> templates) throws ConcurrentOperationException, 
ConfigurationException {
 
         long id = consoleProxyDao.getNextInSequence(Long.class, "id");
         String name = VirtualMachineName.getConsoleProxyName(id, instance);
@@ -714,7 +712,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
             networks.put(networkOrchestrationService.setupNetwork(systemAcct, 
offering, plan, null, null, false).get(0), new ArrayList<>());
         }
 
-        ServiceOfferingVO serviceOffering = serviceOfferingVO;
+        ServiceOfferingVO serviceOffering = 
getConsoleProxyServiceOffering(dataCenterId);
         if (serviceOffering == null) {
             serviceOffering = 
serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.consoleProxyDefaultOffUniqueName,
 ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
         }
@@ -841,7 +839,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
                 if 
(allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC_IN_SECONDS)) {
                     try {
                         proxy = startNew(dataCenterId);
-                    } catch (ConcurrentOperationException e) {
+                    } catch (ConcurrentOperationException | 
ConfigurationException e) {
                         logger.warn("Unable to start new console proxy on zone 
[{}] due to [{}].", zone, e.getMessage(), e);
                     } finally {
                         allocProxyLock.unlock();
@@ -1131,9 +1129,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
         }
 
         Map<String, String> configs = 
configurationDao.getConfiguration("management-server", params);
-        for (Map.Entry<String, String> entry : configs.entrySet()) {
-            logger.info("PEARL - Configure console proxy manager : " + 
entry.getKey() + " = " + entry.getValue());
-        }
 
         String value = ConsoleProxyCapacityScanInterval.value();
         capacityScanInterval = NumbersUtil.parseLong(value, 
DEFAULT_CAPACITY_SCAN_INTERVAL_IN_MILLISECONDS);
@@ -1164,37 +1159,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
 
         virtualMachineManager.registerGuru(VirtualMachine.Type.ConsoleProxy, 
this);
 
-        String configKey = Config.ConsoleProxyServiceOffering.key();
-        String cpvmSrvcOffIdStr = configs.get(configKey);
-        if (cpvmSrvcOffIdStr != null) {
-            serviceOfferingVO = 
serviceOfferingDao.findByUuid(cpvmSrvcOffIdStr);
-            if (serviceOfferingVO == null) {
-                try {
-                     logger.debug(String.format("Unable to find a service 
offering by the UUID for console proxy VM with the value [%s] set in the 
configuration [%s]. Trying to find by the ID.", cpvmSrvcOffIdStr, configKey));
-                    serviceOfferingVO = 
serviceOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr));
-                } catch (NumberFormatException ex) {
-                    logger.warn(String.format("Unable to find a service 
offering by the ID for console proxy VM with the value [%s] set in the 
configuration [%s]. The value is not a valid integer number. Error: [%s].", 
cpvmSrvcOffIdStr, configKey, ex.getMessage()), ex);
-                }
-            }
-            if (serviceOfferingVO == null) {
-                logger.warn(String.format("Unable to find a service offering 
by the UUID or ID for console proxy VM with the value [%s] set in the 
configuration [%s]", cpvmSrvcOffIdStr, configKey));
-            }
-        }
-
-        if (serviceOfferingVO == null || !serviceOfferingVO.isSystemUse()) {
-            int ramSize = 
NumbersUtil.parseInt(configurationDao.getValue("console.ram.size"), 
DEFAULT_PROXY_VM_RAMSIZE);
-            int cpuFreq = 
NumbersUtil.parseInt(configurationDao.getValue("console.cpu.mhz"), 
DEFAULT_PROXY_VM_CPUMHZ);
-            List<ServiceOfferingVO> offerings = 
serviceOfferingDao.createSystemServiceOfferings("System Offering For Console 
Proxy",
-                    ServiceOffering.consoleProxyDefaultOffUniqueName, 1, 
ramSize, cpuFreq, 0, 0, false, null,
-                    Storage.ProvisioningType.THIN, true, null, true, 
VirtualMachine.Type.ConsoleProxy, true);
-
-            if (offerings == null || offerings.size() < 2) {
-                String msg = "Data integrity problem : System Offering For 
Console Proxy has been removed?";
-                logger.error(msg);
-                throw new ConfigurationException(msg);
-            }
-        }
-
         loadScanner = new SystemVmLoadScanner<>(this);
         loadScanner.initScan(STARTUP_DELAY_IN_MILLISECONDS, 
capacityScanInterval);
         
resourceManager.registerResourceStateAdapter(this.getClass().getSimpleName(), 
this);
@@ -1656,4 +1620,40 @@ public class ConsoleProxyManagerImpl extends ManagerBase 
implements ConsoleProxy
     private Integer getStandbyCapacity(Long datacenterId) {
         return 
Integer.parseInt(ConsoleProxyCapacityStandby.valueIn(datacenterId));
     }
+
+    private ServiceOfferingVO getConsoleProxyServiceOffering(Long 
datacenterId) throws ConfigurationException {
+        String configKey = ConsoleProxyServiceOffering.key();
+        String cpvmSrvcOffIdStr = 
ConsoleProxyServiceOffering.valueIn(datacenterId);
+        String warningMessage = String.format("Unable to find a service 
offering by the UUID or ID for console proxy VM with the value [%s] set in the 
configuration [%s]", cpvmSrvcOffIdStr, configKey);
+        ServiceOfferingVO serviceOfferingVO = null;
+        if (cpvmSrvcOffIdStr != null) {
+            serviceOfferingVO = 
serviceOfferingDao.findByUuid(cpvmSrvcOffIdStr);
+            if (serviceOfferingVO == null) {
+                try {
+                    logger.debug(warningMessage);
+                    serviceOfferingVO = 
serviceOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr));
+                } catch (NumberFormatException ex) {
+                    logger.warn(String.format("Unable to find a service 
offering by the ID for console proxy VM with the value [%s] set in the 
configuration [%s]. The value is not a valid integer number. Error: [%s].", 
cpvmSrvcOffIdStr, configKey, ex.getMessage()), ex);
+                }
+            }
+            if (serviceOfferingVO == null) {
+                logger.warn(warningMessage);
+            }
+        }
+
+        if (serviceOfferingVO == null || !serviceOfferingVO.isSystemUse()) {
+            int ramSize = 
NumbersUtil.parseInt(configurationDao.getValue("console.ram.size"), 
DEFAULT_PROXY_VM_RAMSIZE);
+            int cpuFreq = 
NumbersUtil.parseInt(configurationDao.getValue("console.cpu.mhz"), 
DEFAULT_PROXY_VM_CPUMHZ);
+            List<ServiceOfferingVO> offerings = 
serviceOfferingDao.createSystemServiceOfferings("System Offering For Console 
Proxy",
+                    ServiceOffering.consoleProxyDefaultOffUniqueName, 1, 
ramSize, cpuFreq, 0, 0, false, null,
+                    Storage.ProvisioningType.THIN, true, null, true, 
VirtualMachine.Type.ConsoleProxy, true);
+
+            if (offerings == null || offerings.size() < 2) {
+                String msg = "Data integrity problem : System Offering For 
Console Proxy has been removed?";
+                logger.error(msg);
+                throw new ConfigurationException(msg);
+            }
+        }
+        return serviceOfferingVO;
+    }
 }

Reply via email to