Skip to content

Commit bdb3ce7

Browse files
committed
extract code and make few configs dynamic
1 parent a99b4ee commit bdb3ce7

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.security.NoSuchAlgorithmException;
2121
import java.security.SecureRandom;
2222
import java.util.Date;
23+
import java.util.Objects;
2324

2425
import org.apache.cloudstack.consoleproxy.ConsoleAccessManager;
2526
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -214,7 +215,9 @@ public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
214215

215216
HostVO consoleProxyHost = findConsoleProxyHost(startupCmd);
216217

217-
assert (consoleProxyHost != null);
218+
if (Objects.isNull(consoleProxyHost)) {
219+
throw new IllegalStateException("Console proxy host is null");
220+
}
218221

219222
Long datacenterId = consoleProxyHost.getDataCenterId();
220223
String consoleProxyUrlDomain = ConsoleProxyManager.ConsoleProxyUrlDomain.valueIn(datacenterId);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
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

5959
ConfigKey<String> ConsoleProxyServiceOffering = new ConfigKey<>(String.class, "consoleproxy.service.offering", "Console Proxy", null,
60-
"Uuid of the service offering used by console proxy; if NULL - system offering will be used", false, ConfigKey.Scope.Zone, null);
60+
"Uuid of the service offering used by console proxy; if NULL - system offering will be used", true, ConfigKey.Scope.Zone, null);
6161

6262
ConfigKey<String> ConsoleProxyCapacityStandby = new ConfigKey<>(String.class, "consoleproxy.capacity.standby", "Console Proxy", String.valueOf(DEFAULT_STANDBY_CAPACITY),
6363
"The minimal number of console proxy viewer sessions that system is able to serve immediately(standby capacity)", false, ConfigKey.Scope.Zone, null);
@@ -69,7 +69,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
6969
"Console proxy command port that is used to communicate with management server", false, ConfigKey.Scope.Zone, null);
7070

7171
ConfigKey<Boolean> ConsoleProxyRestart = new ConfigKey<>(Boolean.class, "consoleproxy.restart", "Console Proxy", "true",
72-
"Console proxy restart flag, defaults to true", false, ConfigKey.Scope.Zone, null);
72+
"Console proxy restart flag, defaults to true", true, ConfigKey.Scope.Zone, null);
7373

7474
ConfigKey<String> ConsoleProxyUrlDomain = new ConfigKey<>(String.class, "consoleproxy.url.domain", "Console Proxy", "",
7575
"Console proxy url domain - domainName,privateip", false, ConfigKey.Scope.Zone, null);
@@ -81,7 +81,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
8181
"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);
8282

8383
ConfigKey<Boolean> ConsoleProxyDisableRpFilter = new ConfigKey<>(Boolean.class, "consoleproxy.disable.rpfilter", "Console Proxy", "true",
84-
"disable rp_filter on console proxy VM public interface", false, ConfigKey.Scope.Zone, null);
84+
"disable rp_filter on console proxy VM public interface", true, ConfigKey.Scope.Zone, null);
8585

8686
ConfigKey<Integer> ConsoleProxyLaunchMax = new ConfigKey<>(Integer.class, "consoleproxy.launch.max", "Console Proxy", "10",
8787
"maximum number of console proxy instances per zone can be launched", false, ConfigKey.Scope.Zone, null);

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,33 +1627,44 @@ private ServiceOfferingVO getConsoleProxyServiceOffering(Long datacenterId) thro
16271627
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);
16281628
ServiceOfferingVO serviceOfferingVO = null;
16291629
if (cpvmSrvcOffIdStr != null) {
1630-
serviceOfferingVO = serviceOfferingDao.findByUuid(cpvmSrvcOffIdStr);
1631-
if (serviceOfferingVO == null) {
1632-
try {
1633-
logger.debug(warningMessage);
1634-
serviceOfferingVO = serviceOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr));
1635-
} catch (NumberFormatException ex) {
1636-
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);
1637-
}
1638-
}
1639-
if (serviceOfferingVO == null) {
1640-
logger.warn(warningMessage);
1641-
}
1630+
serviceOfferingVO = getServiceOfferingByUuidOrId(cpvmSrvcOffIdStr, warningMessage, configKey);
16421631
}
16431632

16441633
if (serviceOfferingVO == null || !serviceOfferingVO.isSystemUse()) {
1645-
int ramSize = NumbersUtil.parseInt(configurationDao.getValue("console.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
1646-
int cpuFreq = NumbersUtil.parseInt(configurationDao.getValue("console.cpu.mhz"), DEFAULT_PROXY_VM_CPUMHZ);
1647-
List<ServiceOfferingVO> offerings = serviceOfferingDao.createSystemServiceOfferings("System Offering For Console Proxy",
1648-
ServiceOffering.consoleProxyDefaultOffUniqueName, 1, ramSize, cpuFreq, 0, 0, false, null,
1649-
Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.ConsoleProxy, true);
1650-
1651-
if (offerings == null || offerings.size() < 2) {
1652-
String msg = "Data integrity problem : System Offering For Console Proxy has been removed?";
1653-
logger.error(msg);
1654-
throw new ConfigurationException(msg);
1634+
logger.debug("Service offering for console proxy VM is not set or not a system service offering. Creating a default service offering.");
1635+
createServiceOfferingForConsoleProxy();
1636+
}
1637+
return serviceOfferingVO;
1638+
}
1639+
1640+
private ServiceOfferingVO getServiceOfferingByUuidOrId(String cpvmSrvcOffIdStr, String warningMessage, String configKey) {
1641+
ServiceOfferingVO serviceOfferingVO = serviceOfferingDao.findByUuid(cpvmSrvcOffIdStr);
1642+
if (serviceOfferingVO == null) {
1643+
try {
1644+
logger.debug(warningMessage);
1645+
serviceOfferingVO = serviceOfferingDao.findById(Long.parseLong(cpvmSrvcOffIdStr));
1646+
} catch (NumberFormatException ex) {
1647+
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);
16551648
}
16561649
}
1650+
if (serviceOfferingVO == null) {
1651+
logger.warn(warningMessage);
1652+
}
1653+
16571654
return serviceOfferingVO;
16581655
}
1656+
1657+
private void createServiceOfferingForConsoleProxy() throws ConfigurationException {
1658+
int ramSize = NumbersUtil.parseInt(configurationDao.getValue("console.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
1659+
int cpuFreq = NumbersUtil.parseInt(configurationDao.getValue("console.cpu.mhz"), DEFAULT_PROXY_VM_CPUMHZ);
1660+
List<ServiceOfferingVO> offerings = serviceOfferingDao.createSystemServiceOfferings("System Offering For Console Proxy",
1661+
ServiceOffering.consoleProxyDefaultOffUniqueName, 1, ramSize, cpuFreq, 0, 0, false, null,
1662+
Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.ConsoleProxy, true);
1663+
1664+
if (offerings == null || offerings.size() < 2) {
1665+
String msg = "Data integrity problem : System Offering For Console Proxy has been removed?";
1666+
logger.error(msg);
1667+
throw new ConfigurationException(msg);
1668+
}
1669+
}
16591670
}

0 commit comments

Comments
 (0)