Skip to content

Commit aac7a56

Browse files
Change configs 'consoleproxy.management.state' and 'consoleproxy.management.state.last' to dynamic and some improvements in Console Proxy Manager
1 parent 35ac91e commit aac7a56

4 files changed

Lines changed: 39 additions & 36 deletions

File tree

framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ public void setName(String name) {
155155

156156
@Override
157157
public String getValue() {
158-
if(isEncrypted()) {
158+
if (isEncrypted()) {
159159
return DBEncryptionUtil.decrypt(value);
160160
} else {
161161
return value;
162162
}
163163
}
164164

165165
public void setValue(String value) {
166-
if(isEncrypted()) {
166+
if (isEncrypted()) {
167167
this.value = DBEncryptionUtil.encrypt(value);
168168
} else {
169169
this.value = value;

server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
3939
int DEFAULT_PROXY_VM_RAMSIZE = 1024; // 1G
4040
int DEFAULT_PROXY_VM_CPUMHZ = 500; // 500 MHz
4141

42-
int DEFAULT_PROXY_CMD_PORT = 8001;
4342
int DEFAULT_PROXY_VNC_PORT = 0;
4443
int DEFAULT_PROXY_URL_PORT = 80;
4544
int DEFAULT_PROXY_SESSION_TIMEOUT = 300000; // 5 minutes
@@ -54,7 +53,8 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
5453
"If true, noVNC console will be default console for virtual machines", false, ConfigKey.Scope.Zone, null);
5554

5655
ConfigKey<Boolean> NoVncConsoleSourceIpCheckEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "novnc.console.sourceip.check.enabled", "false",
57-
"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);
56+
"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" +
57+
" when this changes (via restart CPVM, or management server, or cloud service in CPVM)", false);
5858

5959
ConfigKey<Boolean> NoVncConsoleShowDot = new ConfigKey<>(Boolean.class, "novnc.console.show.dot", ConfigKey.CATEGORY_ADVANCED, "true",
6060
"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 {
8787
ConfigKey<Integer> ConsoleProxyLaunchMax = new ConfigKey<>(Integer.class, "consoleproxy.launch.max", "Console Proxy", "10",
8888
"maximum number of console proxy instances per zone can be launched", false, ConfigKey.Scope.Zone, null);
8989

90-
String consoleProxyManagementStates = Arrays.stream(com.cloud.consoleproxy.ConsoleProxyManagementState.values()).map(Enum::name).collect(Collectors.joining(","));
91-
ConfigKey<String> ConsoleProxyServiceManagementState = new ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
92-
"console proxy service management state", false, ConfigKey.Kind.Select, consoleProxyManagementStates);
90+
String consoleProxyServiceManagementStates = Arrays.stream(com.cloud.consoleproxy.ConsoleProxyManagementState.values()).map(Enum::name).collect(Collectors.joining(","));
9391

94-
ConfigKey<String> ConsoleProxyManagementLastState = new ConfigKey<String>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state.last", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
95-
"last console proxy service management state", false, ConfigKey.Kind.Select, consoleProxyManagementStates);
92+
ConfigKey<String> ConsoleProxyServiceManagementState = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
93+
"console proxy service management state", true, ConfigKey.Kind.Select, consoleProxyServiceManagementStates);
94+
95+
ConfigKey<String> ConsoleProxyServiceManagementLastState = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class, "consoleproxy.management.state.last", com.cloud.consoleproxy.ConsoleProxyManagementState.Auto.toString(),
96+
"last console proxy service management state", true, ConfigKey.Kind.Select, consoleProxyServiceManagementStates);
9697

9798
ConfigKey<String> ConsoleProxyVmUserData = new ConfigKey<>(String.class, "console.proxy.vm.userdata",
9899
ConfigKey.CATEGORY_ADVANCED, "",

server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -988,41 +988,43 @@ public boolean stopProxy(long proxyVmId) {
988988

989989
@Override
990990
@DB
991-
public void setManagementState(final ConsoleProxyManagementState state) {
991+
public void setManagementState(final ConsoleProxyManagementState newState) {
992992
try {
993-
final ConsoleProxyManagementState lastState = getManagementState();
994-
if (lastState == null) {
993+
final ConsoleProxyManagementState currentState = getManagementState();
994+
if (currentState == null) {
995995
return;
996996
}
997997

998-
if (lastState != state) {
998+
if (currentState != newState) {
999+
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);
9991000
Transaction.execute(new TransactionCallbackNoReturn() {
10001001
@Override
10011002
public void doInTransactionWithoutResult(TransactionStatus status) {
1002-
configurationDao.update(ConsoleProxyManagementLastState.key(), ConsoleProxyManagementLastState.category(), lastState.toString());
1003-
configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), state.toString());
1003+
configurationDao.update(ConsoleProxyServiceManagementLastState.key(), ConsoleProxyServiceManagementLastState.category(), currentState.toString());
1004+
configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), newState.toString());
10041005
}
10051006
});
1007+
} else {
1008+
logger.debug("Console proxy management state is already set to {}, no need to update.", newState);
10061009
}
10071010
} catch (Exception e) {
1008-
logger.error(String.format("Unable to set console proxy management state to [%s] due to [%s].", state, e.getMessage()), e);
1011+
logger.error("Unable to update console proxy management state to [{}] due to [{}].", newState, e.getMessage(), e);
10091012
}
10101013
}
10111014

10121015
@Override
10131016
public ConsoleProxyManagementState getManagementState() {
1014-
String configKey = ConsoleProxyServiceManagementState.key();
1015-
String value = ConsoleProxyServiceManagementState.value();
1016-
1017-
if (value != null) {
1018-
ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(value);
1017+
String stateConfigKey = ConsoleProxyServiceManagementState.key();
1018+
String stateConfigValue = ConsoleProxyServiceManagementState.value();
10191019

1020+
if (stateConfigValue != null) {
1021+
ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(stateConfigValue);
10201022
if (state != null) {
10211023
return state;
10221024
}
10231025
}
10241026

1025-
logger.error(String.format("Value [%s] set in global configuration [%s] is not a valid console proxy management state.", value, configKey));
1027+
logger.error("Console proxy management state value is null in the global configuration [{}].", stateConfigKey);
10261028
return null;
10271029
}
10281030

@@ -1037,26 +1039,26 @@ public void resumeLastManagementState() {
10371039
}
10381040

10391041
if (lastState != state) {
1042+
logger.debug("Resuming console proxy management state to last state {}, current state is {}.", lastState, state);
10401043
configurationDao.update(ConsoleProxyServiceManagementState.key(), ConsoleProxyServiceManagementState.category(), lastState.toString());
10411044
}
10421045
} catch (Exception e) {
1043-
logger.error(String.format("Unable to resume last management state due to [%s].", e.getMessage()), e);
1046+
logger.error("Unable to resume last management state due to [{}].", e.getMessage(), e);
10441047
}
10451048
}
10461049

10471050
private ConsoleProxyManagementState getLastManagementState() {
1048-
String configKey = ConsoleProxyManagementLastState.key();
1049-
String value = ConsoleProxyManagementLastState.value();
1051+
String lastStateConfigKey = ConsoleProxyServiceManagementLastState.key();
1052+
String lastStateConfigValue = ConsoleProxyServiceManagementLastState.value();
10501053

1051-
if (value != null) {
1052-
ConsoleProxyManagementState state = ConsoleProxyManagementState.valueOf(value);
1053-
1054-
if (state != null) {
1055-
return state;
1054+
if (lastStateConfigValue != null) {
1055+
ConsoleProxyManagementState lastState = ConsoleProxyManagementState.valueOf(lastStateConfigValue);
1056+
if (lastState != null) {
1057+
return lastState;
10561058
}
10571059
}
10581060

1059-
logger.error(String.format("Value [%s] set in global configuration [%s] is not a valid console proxy management state.", value, configKey));
1061+
logger.error("Console proxy last management state value is null in the global configuration [{}].", lastStateConfigKey);
10601062
return null;
10611063
}
10621064

@@ -1074,7 +1076,7 @@ public boolean rebootProxy(long proxyVmId) {
10741076

10751077
if (answer != null && answer.getResult()) {
10761078
if (logger.isDebugEnabled()) {
1077-
logger.debug("Successfully reboot console proxy " + proxy.getHostName());
1079+
logger.debug("Successfully reboot console proxy {}", proxy.getHostName());
10781080
}
10791081

10801082
SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this,
@@ -1083,7 +1085,7 @@ public boolean rebootProxy(long proxyVmId) {
10831085
return true;
10841086
} else {
10851087
if (logger.isDebugEnabled()) {
1086-
logger.debug("failed to reboot console proxy : " + proxy.getHostName());
1088+
logger.debug("Failed to reboot console proxy : {}", proxy.getHostName());
10871089
}
10881090

10891091
return false;
@@ -1113,7 +1115,7 @@ public boolean destroyProxy(long vmId) {
11131115

11141116
return true;
11151117
} catch (ResourceUnavailableException e) {
1116-
logger.warn(String.format("Unable to destroy console proxy [%s] due to [%s].", proxy, e.getMessage()), e);
1118+
logger.warn("Unable to destroy console proxy [{}] due to [{}].", proxy, e.getMessage(), e);
11171119
return false;
11181120
}
11191121
}
@@ -1590,7 +1592,7 @@ public String getConfigComponentName() {
15901592
public ConfigKey<?>[] getConfigKeys() {
15911593
return new ConfigKey<?>[] {ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled, ConsoleProxyServiceOffering,
15921594
ConsoleProxyCapacityStandby, ConsoleProxyCapacityScanInterval, ConsoleProxyRestart, ConsoleProxyUrlDomain, ConsoleProxySessionMax, ConsoleProxySessionTimeout, ConsoleProxyDisableRpFilter, ConsoleProxyLaunchMax,
1593-
ConsoleProxyManagementLastState, ConsoleProxyServiceManagementState, NoVncConsoleShowDot,
1595+
ConsoleProxyServiceManagementLastState, ConsoleProxyServiceManagementState, NoVncConsoleShowDot,
15941596
ConsoleProxyVmUserData};
15951597
}
15961598

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4975,8 +4975,8 @@ public String uploadCertificate(final UploadCustomCertificateCmd cmd) {
49754975
if (cmd.getPrivateKey() != null) {
49764976
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, domainSuffix);
49774977

4978-
// Reboot ssvm here since private key is present - meaning server cert being passed
49794978
final List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting);
4979+
logger.debug("Reboot SSVMs in Running, Migrating, Starting states since private key is present - meaning server cert being passed");
49804980
for (final SecondaryStorageVmVO ssVmVm : alreadyRunning) {
49814981
_secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId());
49824982
}

0 commit comments

Comments
 (0)