Skip to content

Commit 317696f

Browse files
committed
move most console proxy setting to zone level
1 parent 8a0b090 commit 317696f

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public boolean destroyProxy(long proxyVmId) {
191191
}
192192

193193
@Override
194-
public int getVncPort() {
194+
public int getVncPort(Long dataCenterId) {
195195
return _consoleProxyPort;
196196
}
197197

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
5656
ConfigKey<Boolean> NoVncConsoleSourceIpCheckEnabled = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "novnc.console.sourceip.check.enabled", "false",
5757
"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);
5858

59-
ConfigKey<String> ConsoleProxyCapacityStandby = new ConfigKey<>(String.class, "consoleproxy.capacity.standby", "Console Proxy", "10",
59+
ConfigKey<String> ConsoleProxyCapacityStandby = new ConfigKey<>(String.class, "consoleproxy.capacity.standby", "Console Proxy", String.valueOf(DEFAULT_STANDBY_CAPACITY),
6060
"The minimal number of console proxy viewer sessions that system is able to serve immediately(standby capacity)", false, ConfigKey.Scope.Zone, null);
6161

6262
ConfigKey<String> ConsoleProxyCapacityScanInterval = new ConfigKey<>(String.class, "consoleproxy.capacityscan.interval", "Console Proxy", "30000",
63-
"The time interval(in millisecond) to scan whether or not system needs more console proxy to ensure minimal standby capacity", false, ConfigKey.Scope.Zone, null);
63+
"The time interval(in millisecond) to scan whether or not system needs more console proxy to ensure minimal standby capacity", false, null);
6464

6565
ConfigKey<Integer> ConsoleProxyCmdPort = new ConfigKey<>(Integer.class, "consoleproxy.cmd.port", "Console Proxy", String.valueOf(DEFAULT_PROXY_CMD_PORT),
6666
"Console proxy command port that is used to communicate with management server", false, ConfigKey.Scope.Zone, null);
@@ -74,7 +74,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
7474
ConfigKey<Integer> ConsoleProxySessionMax = new ConfigKey<>(Integer.class, "consoleproxy.session.max", "Console Proxy", String.valueOf(DEFAULT_PROXY_CAPACITY),
7575
"The max number of viewer sessions console proxy is configured to serve for", false, ConfigKey.Scope.Zone, null);
7676

77-
ConfigKey<Integer> ConsoleProxySessionTimeout = new ConfigKey<>(Integer.class, "consoleproxy.session.timeout", "Console Proxy", "300000",
77+
ConfigKey<Integer> ConsoleProxySessionTimeout = new ConfigKey<>(Integer.class, "consoleproxy.session.timeout", "Console Proxy", String.valueOf(DEFAULT_PROXY_SESSION_TIMEOUT),
7878
"Timeout(in milliseconds) that console proxy tries to maintain a viewer session before it times out the session for no activity", false, ConfigKey.Scope.Zone, null);
7979

8080
ConfigKey<Boolean> ConsoleProxyDisableRpFilter = new ConfigKey<>(Boolean.class, "consoleproxy.disable.rpfilter", "Console Proxy", "true",
@@ -108,6 +108,6 @@ void startProxyForHA(VirtualMachine vm, Map<VirtualMachineProfile.Param, Object>
108108

109109
boolean destroyProxy(long proxyVmId);
110110

111-
int getVncPort();
111+
int getVncPort(Long dataCenterId);
112112

113113
}

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

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,10 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
233233
private ServiceOfferingVO serviceOfferingVO;
234234

235235
private long capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL_IN_MILLISECONDS;
236-
private int capacityPerProxy = ConsoleProxyManager.DEFAULT_PROXY_CAPACITY;
237-
private int standbyCapacity = ConsoleProxyManager.DEFAULT_STANDBY_CAPACITY;
238236

239237
private boolean useStorageVm;
240-
private boolean disableRpFilter = false;
241238
private String instance;
242239

243-
private int proxySessionTimeoutValue = DEFAULT_PROXY_SESSION_TIMEOUT;
244-
private boolean sslEnabled = false;
245-
private String consoleProxyUrlDomain;
246-
247240
private SystemVmLoadScanner<Long> loadScanner;
248241
private Map<Long, ZoneHostInfo> zoneHostInfoMap;
249242
private Map<Long, ConsoleProxyLoadInfo> zoneProxyCountMap;
@@ -342,7 +335,7 @@ public ConsoleProxyInfo assignProxy(final long dataCenterId, final VMInstanceVO
342335
logger.warn(String.format("SSL is enabled for console proxy [%s] but no server certificate found in database.", proxy.toString()));
343336
}
344337

345-
consoleProxyUrlDomain = ConsoleProxyUrlDomain.valueIn(dataCenterId);
338+
String consoleProxyUrlDomain = ConsoleProxyUrlDomain.valueIn(dataCenterId);
346339
ConsoleProxyInfo info;
347340
if (staticPublicIp == null) {
348341
info = new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), consoleProxyPort, proxy.getPort(), consoleProxyUrlDomain);
@@ -375,6 +368,7 @@ public ConsoleProxyVO doAssignProxy(long dataCenterId, VMInstanceVO vm) {
375368
}
376369
proxy = null;
377370
} else {
371+
long capacityPerProxy = ConsoleProxySessionMax.valueIn(dataCenterId);
378372
if (consoleProxyDao.getProxyActiveLoad(proxy.getId()) < capacityPerProxy || hasPreviousSession(proxy, vm)) {
379373
if (logger.isDebugEnabled()) {
380374
logger.debug("Assign previous allocated console proxy for user vm: {}", vm);
@@ -409,7 +403,7 @@ public ConsoleProxyVO doAssignProxy(long dataCenterId, VMInstanceVO vm) {
409403
if (vm.getProxyId() == null || vm.getProxyId() != proxy.getId()) {
410404
vmInstanceDao.updateProxyId(vm.getId(), proxy.getId(), DateUtil.currentGMTTime());
411405
}
412-
406+
boolean sslEnabled = isSslEnabled(dataCenterId);
413407
proxy.setSslEnabled(sslEnabled);
414408
if (sslEnabled) {
415409
proxy.setPort(443);
@@ -452,6 +446,7 @@ private boolean hasPreviousSession(ConsoleProxyVO proxy, VMInstanceVO vm) {
452446
}
453447
}
454448

449+
Integer proxySessionTimeoutValue = ConsoleProxySessionTimeout.valueIn(proxy.getDataCenterId());
455450
return DateUtil.currentGMTTime().getTime() - vm.getProxyAssignTime().getTime() < proxySessionTimeoutValue;
456451
} else {
457452
logger.warn(String.format("Unable to retrieve load info from proxy [%s] on an overloaded proxy.", proxy.toString()));
@@ -501,6 +496,8 @@ public ConsoleProxyVO assignProxyFromRunningPool(long dataCenterId) {
501496
logger.debug("Assign console proxy from running pool for request from data center: {}", zone);
502497
}
503498

499+
long capacityPerProxy = ConsoleProxySessionMax.valueIn(dataCenterId);
500+
504501
ConsoleProxyAllocator allocator = getCurrentAllocator();
505502
assert (allocator != null);
506503
List<ConsoleProxyVO> runningList = consoleProxyDao.getProxyListInStates(dataCenterId, State.Running);
@@ -820,8 +817,9 @@ private boolean allowToLaunchNew(long dcId) {
820817
return l.size() < launchLimit;
821818
}
822819

823-
private boolean checkCapacity(ConsoleProxyLoadInfo proxyCountInfo, ConsoleProxyLoadInfo vmCountInfo) {
824-
return proxyCountInfo.getCount() * capacityPerProxy - vmCountInfo.getCount() > standbyCapacity;
820+
private boolean checkCapacity(ConsoleProxyLoadInfo proxyCountInfo, ConsoleProxyLoadInfo vmCountInfo, long dataCenterId) {
821+
long capacityPerProxy = ConsoleProxySessionMax.valueIn(dataCenterId);
822+
return proxyCountInfo.getCount() * capacityPerProxy - vmCountInfo.getCount() > getStandbyCapacity(dataCenterId);
825823
}
826824

827825
private void allocCapacity(long dataCenterId) {
@@ -1118,8 +1116,8 @@ public boolean destroyProxy(long vmId) {
11181116
}
11191117

11201118
@Override
1121-
public int getVncPort() {
1122-
return sslEnabled && _ksDao.findByName(ConsoleProxyManager.CERTIFICATE_NAME) != null ? 8443 : 8080;
1119+
public int getVncPort(Long dataCenterId) {
1120+
return isSslEnabled(dataCenterId) && _ksDao.findByName(ConsoleProxyManager.CERTIFICATE_NAME) != null ? 8443 : 8080;
11231121
}
11241122

11251123
private String getAllocProxyLockName() {
@@ -1136,44 +1134,20 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
11361134
for (Map.Entry<String, String> entry : configs.entrySet()) {
11371135
logger.info("PEARL - Configure console proxy manager : " + entry.getKey() + " = " + entry.getValue());
11381136
}
1139-
String value = configs.get(ConsoleProxySslEnabled.key());
1140-
if (value != null && value.equalsIgnoreCase("true")) {
1141-
sslEnabled = true;
1142-
}
11431137

1144-
consoleProxyUrlDomain = ConsoleProxyUrlDomain.value();
1145-
if( sslEnabled && (consoleProxyUrlDomain == null || consoleProxyUrlDomain.isEmpty())) {
1146-
logger.warn("Empty console proxy domain, explicitly disabling SSL");
1147-
sslEnabled = false;
1148-
}
1149-
1150-
value = ConsoleProxyCapacityScanInterval.value();
1138+
String value = ConsoleProxyCapacityScanInterval.value();
11511139
capacityScanInterval = NumbersUtil.parseLong(value, DEFAULT_CAPACITY_SCAN_INTERVAL_IN_MILLISECONDS);
11521140

1153-
capacityPerProxy = NumbersUtil.parseInt(configs.get("consoleproxy.session.max"), DEFAULT_PROXY_CAPACITY);
1154-
standbyCapacity = NumbersUtil.parseInt(ConsoleProxyCapacityStandby.value(), DEFAULT_STANDBY_CAPACITY);
1155-
proxySessionTimeoutValue = NumbersUtil.parseInt(configs.get("consoleproxy.session.timeout"), DEFAULT_PROXY_SESSION_TIMEOUT);
1156-
11571141
value = configs.get("consoleproxy.port");
11581142
if (value != null) {
11591143
consoleProxyPort = NumbersUtil.parseInt(value, ConsoleProxyManager.DEFAULT_PROXY_VNC_PORT);
11601144
}
11611145

1162-
Boolean rpFilterDisabled = ConsoleProxyDisableRpFilter.value();
1163-
if (Boolean.TRUE.equals(rpFilterDisabled)) {
1164-
disableRpFilter = true;
1165-
}
1166-
11671146
value = configs.get("secondary.storage.vm");
11681147
if (value != null && value.equalsIgnoreCase("true")) {
11691148
useStorageVm = true;
11701149
}
11711150

1172-
if (logger.isInfoEnabled()) {
1173-
logger.info("Console proxy max session soft limit : " + capacityPerProxy);
1174-
logger.info("Console proxy standby capacity : " + standbyCapacity);
1175-
}
1176-
11771151
instance = configs.get("instance.name");
11781152
if (instance == null) {
11791153
instance = "DEFAULT";
@@ -1255,16 +1229,16 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
12551229
buf.append(" host=").append(StringUtils.toCSVList(indirectAgentLB.getManagementServerList(dest.getHost().getId(), dest.getDataCenter().getId(), null)));
12561230
buf.append(" port=").append(managementPort);
12571231
buf.append(" name=").append(profile.getVirtualMachine().getHostName());
1258-
if (sslEnabled) {
1232+
if (isSslEnabled(dest.getDataCenter().getId())) {
12591233
buf.append(" premium=true");
12601234
}
12611235
Long datacenterId = dest.getDataCenter().getId();
12621236
buf.append(" zone=").append(datacenterId);
12631237
buf.append(" pod=").append(dest.getPod().getId());
12641238
buf.append(" guid=Proxy.").append(profile.getId());
12651239
buf.append(" proxy_vm=").append(profile.getId());
1266-
disableRpFilter = ConsoleProxyDisableRpFilter.valueIn(datacenterId);
1267-
if (disableRpFilter) {
1240+
Boolean disableRpFilter = ConsoleProxyDisableRpFilter.valueIn(datacenterId);
1241+
if (Boolean.TRUE.equals(disableRpFilter)) {
12681242
buf.append(" disable_rp_filter=true");
12691243
}
12701244

@@ -1324,7 +1298,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
13241298
buf.append(" dns2=").append(dc.getDns2());
13251299
}
13261300
if (VirtualMachine.Type.ConsoleProxy == profile.getVirtualMachine().getType()) {
1327-
buf.append(" vncport=").append(getVncPort());
1301+
buf.append(" vncport=").append(getVncPort(datacenterId));
13281302
}
13291303
buf.append(" keystore_password=").append(VirtualMachineGuru.getEncodedString(PasswordGenerator.generateRandomPassword(16)));
13301304
String bootArgs = buf.toString();
@@ -1557,7 +1531,7 @@ public Pair<AfterScanAction, Object> scanPool(Long dataCenterId) {
15571531
vmInfo = new ConsoleProxyLoadInfo();
15581532
}
15591533

1560-
if (!checkCapacity(proxyInfo, vmInfo)) {
1534+
if (!checkCapacity(proxyInfo, vmInfo, dataCenterId)) {
15611535
if (logger.isDebugEnabled()) {
15621536
logger.debug("Expand console proxy standby capacity for zone " + proxyInfo.getName());
15631537
}
@@ -1632,7 +1606,9 @@ public String getConfigComponentName() {
16321606

16331607
@Override
16341608
public ConfigKey<?>[] getConfigKeys() {
1635-
return new ConfigKey<?>[] { ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled };
1609+
return new ConfigKey<?>[] { ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled,
1610+
ConsoleProxyCapacityStandby, ConsoleProxyCapacityScanInterval, ConsoleProxyCmdPort, ConsoleProxyRestart, ConsoleProxyUrlDomain, ConsoleProxySessionMax, ConsoleProxySessionTimeout, ConsoleProxyDisableRpFilter, ConsoleProxyLaunchMax,
1611+
ConsoleProxyManagementLastState, ConsoleProxyServiceManagementState };
16361612
}
16371613

16381614
protected ConsoleProxyStatus parseJsonToConsoleProxyStatus(String json) throws JsonParseException {
@@ -1666,4 +1642,18 @@ protected void updateConsoleProxyStatus(String statusInfo, Long proxyVmId) {
16661642

16671643
consoleProxyDao.update(proxyVmId, count, DateUtil.currentGMTTime(), details);
16681644
}
1645+
1646+
private boolean isSslEnabled(Long dataCenterId) {
1647+
boolean sslEnabled = ConsoleProxySslEnabled.valueIn(dataCenterId);
1648+
String consoleProxyUrlDomain = ConsoleProxyUrlDomain.valueIn(dataCenterId);
1649+
if( sslEnabled && (consoleProxyUrlDomain == null || consoleProxyUrlDomain.isEmpty())) {
1650+
logger.warn("Empty console proxy domain, explicitly disabling SSL");
1651+
sslEnabled = false;
1652+
}
1653+
return sslEnabled;
1654+
}
1655+
1656+
private Integer getStandbyCapacity(Long datacenterId) {
1657+
return Integer.parseInt(ConsoleProxyCapacityStandby.valueIn(datacenterId));
1658+
}
16691659
}

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private ConsoleEndpoint composeConsoleAccessEndpoint(String rootUrl, VirtualMach
476476
ConsoleProxyClientParam param = generateConsoleProxyClientParam(parsedHostInfo, port, sid, tag, ticket,
477477
sessionUuid, addr, extraSecurityToken, vm, hostVo, details, portInfo, host, displayName);
478478
String token = encryptor.encryptObject(ConsoleProxyClientParam.class, param);
479-
int vncPort = consoleProxyManager.getVncPort();
479+
int vncPort = consoleProxyManager.getVncPort(vm.getDataCenterId());
480480

481481
String url = generateConsoleAccessUrl(rootUrl, param, token, vncPort, vm, hostVo, details);
482482

0 commit comments

Comments
 (0)