diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java index d12a41864b05..d32b3c4cfecc 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java @@ -155,7 +155,7 @@ public void setName(String name) { @Override public String getValue() { - if(isEncrypted()) { + if (isEncrypted()) { return DBEncryptionUtil.decrypt(value); } else { return value; @@ -163,7 +163,7 @@ public String getValue() { } public void setValue(String value) { - if(isEncrypted()) { + if (isEncrypted()) { this.value = DBEncryptionUtil.encrypt(value); } else { this.value = value; diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java index 47d1a306e4d9..fd7600a509c8 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java @@ -39,7 +39,6 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService { int DEFAULT_PROXY_VM_RAMSIZE = 1024; // 1G int DEFAULT_PROXY_VM_CPUMHZ = 500; // 500 MHz - int DEFAULT_PROXY_CMD_PORT = 8001; int DEFAULT_PROXY_VNC_PORT = 0; int DEFAULT_PROXY_URL_PORT = 80; int DEFAULT_PROXY_SESSION_TIMEOUT = 300000; // 5 minutes @@ -54,7 +53,8 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService { "If true, noVNC console will be default console for virtual machines", false, ConfigKey.Scope.Zone, null); ConfigKey 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); + "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 NoVncConsoleShowDot = new ConfigKey<>(Boolean.class, "novnc.console.show.dot", ConfigKey.CATEGORY_ADVANCED, "true", "If true, in noVNC console a dot cursor will be shown when the remote server provides no local cursor, or provides a fully-transparent (invisible) cursor.", @@ -87,12 +87,13 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService { ConfigKey ConsoleProxyLaunchMax = new ConfigKey<>(Integer.class, "consoleproxy.launch.max", "Console Proxy", "10", "maximum number of console proxy instances per zone can be launched", false, ConfigKey.Scope.Zone, null); - String consoleProxyManagementStates = Arrays.stream(com.cloud.consoleproxy.ConsoleProxyManagementState.values()).map(Enum::name).collect(Collectors.joining(",")); - ConfigKey ConsoleProxyServiceManagementState = new ConfigKey(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(), - "console proxy service management state", false, ConfigKey.Kind.Select, consoleProxyManagementStates); + String consoleProxyServiceManagementStates = Arrays.stream(com.cloud.consoleproxy.ConsoleProxyManagementState.values()).map(Enum::name).collect(Collectors.joining(",")); - ConfigKey ConsoleProxyManagementLastState = new ConfigKey(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); + ConfigKey ConsoleProxyServiceManagementState = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(), + "console proxy service management state", true, ConfigKey.Kind.Select, consoleProxyServiceManagementStates); + + ConfigKey ConsoleProxyServiceManagementLastState = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state.last", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(), + "last console proxy service management state", true, ConfigKey.Kind.Select, consoleProxyServiceManagementStates); ConfigKey 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 018cead22fe3..d818aa41a18b 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -988,41 +988,43 @@ public boolean stopProxy(long proxyVmId) { @Override @DB - public void setManagementState(final ConsoleProxyManagementState state) { + public void setManagementState(final ConsoleProxyManagementState newState) { try { - final ConsoleProxyManagementState lastState = getManagementState(); - if (lastState == null) { + final ConsoleProxyManagementState currentState = getManagementState(); + if (currentState == null) { return; } - if (lastState != state) { + if (currentState != newState) { + logger.debug("Updating console proxy management state config to new state: {}, it's current state is {} and last management state config to {}.", newState, currentState, currentState); Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - configurationDao.update(ConsoleProxyManagementLastState.key(), ConsoleProxyManagementLastState.category(), lastState.toString()); - configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), state.toString()); + configurationDao.update(ConsoleProxyServiceManagementLastState.key(), ConsoleProxyServiceManagementLastState.category(), currentState.toString()); + configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), newState.toString()); } }); + } else { + logger.debug("Console proxy management state is already set to {}, no need to update.", newState); } } catch (Exception e) { - logger.error(String.format("Unable to set console proxy management state to [%s] due to [%s].", state, e.getMessage()), e); + logger.error("Unable to update console proxy management state to [{}] due to [{}].", newState, e.getMessage(), e); } } @Override public ConsoleProxyManagementState getManagementState() { - String configKey = ConsoleProxyServiceManagementState.key(); - String value = ConsoleProxyServiceManagementState.value(); - - if (value != null) { - ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(value); + String stateConfigKey = ConsoleProxyServiceManagementState.key(); + String stateConfigValue = ConsoleProxyServiceManagementState.value(); + if (stateConfigValue != null) { + ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(stateConfigValue); 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)); + logger.error("Console proxy management state value is null in the global configuration [{}].", stateConfigKey); return null; } @@ -1037,26 +1039,26 @@ public void resumeLastManagementState() { } if (lastState != state) { + logger.debug("Resuming console proxy management state to last state {}, current state is {}.", lastState, state); configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), lastState.toString()); } } catch (Exception e) { - logger.error(String.format("Unable to resume last management state due to [%s].", e.getMessage()), e); + logger.error("Unable to resume last management state due to [{}].", e.getMessage(), e); } } private ConsoleProxyManagementState getLastManagementState() { - String configKey = ConsoleProxyManagementLastState.key(); - String value = ConsoleProxyManagementLastState.value(); + String lastStateConfigKey = ConsoleProxyServiceManagementLastState.key(); + String lastStateConfigValue = ConsoleProxyServiceManagementLastState.value(); - if (value != null) { - ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(value); - - if (state != null) { - return state; + if (lastStateConfigValue != null) { + ConsoleProxyManagementState lastState = ConsoleProxyManagementState.valueOf(lastStateConfigValue); + if (lastState != null) { + return lastState; } } - logger.error(String.format("Value [%s] set in global configuration [%s] is not a valid console proxy management state.", value, configKey)); + logger.error("Console proxy last management state value is null in the global configuration [{}].", lastStateConfigKey); return null; } @@ -1074,7 +1076,7 @@ public boolean rebootProxy(long proxyVmId) { if (answer != null && answer.getResult()) { if (logger.isDebugEnabled()) { - logger.debug("Successfully reboot console proxy " + proxy.getHostName()); + logger.debug("Successfully reboot console proxy {}", proxy.getHostName()); } SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, @@ -1083,7 +1085,7 @@ public boolean rebootProxy(long proxyVmId) { return true; } else { if (logger.isDebugEnabled()) { - logger.debug("failed to reboot console proxy : " + proxy.getHostName()); + logger.debug("Failed to reboot console proxy : {}", proxy.getHostName()); } return false; @@ -1113,7 +1115,7 @@ public boolean destroyProxy(long vmId) { return true; } catch (ResourceUnavailableException e) { - logger.warn(String.format("Unable to destroy console proxy [%s] due to [%s].", proxy, e.getMessage()), e); + logger.warn("Unable to destroy console proxy [{}] due to [{}].", proxy, e.getMessage(), e); return false; } } @@ -1590,7 +1592,7 @@ public String getConfigComponentName() { public ConfigKey[] getConfigKeys() { return new ConfigKey[] {ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled, ConsoleProxyServiceOffering, ConsoleProxyCapacityStandby, ConsoleProxyCapacityScanInterval, ConsoleProxyRestart, ConsoleProxyUrlDomain, ConsoleProxySessionMax, ConsoleProxySessionTimeout, ConsoleProxyDisableRpFilter, ConsoleProxyLaunchMax, - ConsoleProxyManagementLastState, ConsoleProxyServiceManagementState, NoVncConsoleShowDot, + ConsoleProxyServiceManagementLastState, ConsoleProxyServiceManagementState, NoVncConsoleShowDot, ConsoleProxyVmUserData}; } diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index 470c968d0de9..4a3d18c3dad0 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -4975,8 +4975,8 @@ public String uploadCertificate(final UploadCustomCertificateCmd cmd) { if (cmd.getPrivateKey() != null) { _ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, domainSuffix); - // Reboot ssvm here since private key is present - meaning server cert being passed final List alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting); + logger.debug("Reboot SSVMs in Running, Migrating, Starting states since private key is present - meaning server cert being passed"); for (final SecondaryStorageVmVO ssVmVm : alreadyRunning) { _secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId()); }