mirror of https://github.com/apache/cloudstack.git
extract code and make few configs dynamic
This commit is contained in:
parent
a99b4ee509
commit
bdb3ce7ea8
|
|
@ -20,6 +20,7 @@ package com.cloud.consoleproxy;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.cloudstack.consoleproxy.ConsoleAccessManager;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
|
@ -214,7 +215,9 @@ public abstract class AgentHookBase implements AgentHook {
|
|||
|
||||
HostVO consoleProxyHost = findConsoleProxyHost(startupCmd);
|
||||
|
||||
assert (consoleProxyHost != null);
|
||||
if (Objects.isNull(consoleProxyHost)) {
|
||||
throw new IllegalStateException("Console proxy host is null");
|
||||
}
|
||||
|
||||
Long datacenterId = consoleProxyHost.getDataCenterId();
|
||||
String consoleProxyUrlDomain = ConsoleProxyManager.ConsoleProxyUrlDomain.valueIn(datacenterId);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
|
|||
"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);
|
||||
"Uuid of the service offering used by console proxy; if NULL - system offering will be used", true, 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);
|
||||
|
|
@ -69,7 +69,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
|
|||
"Console proxy command port that is used to communicate with management server", false, ConfigKey.Scope.Zone, null);
|
||||
|
||||
ConfigKey<Boolean> ConsoleProxyRestart = new ConfigKey<>(Boolean.class, "consoleproxy.restart", "Console Proxy", "true",
|
||||
"Console proxy restart flag, defaults to true", false, ConfigKey.Scope.Zone, null);
|
||||
"Console proxy restart flag, defaults to true", true, ConfigKey.Scope.Zone, null);
|
||||
|
||||
ConfigKey<String> ConsoleProxyUrlDomain = new ConfigKey<>(String.class, "consoleproxy.url.domain", "Console Proxy", "",
|
||||
"Console proxy url domain - domainName,privateip", false, ConfigKey.Scope.Zone, null);
|
||||
|
|
@ -81,7 +81,7 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
|
|||
"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);
|
||||
|
||||
ConfigKey<Boolean> ConsoleProxyDisableRpFilter = new ConfigKey<>(Boolean.class, "consoleproxy.disable.rpfilter", "Console Proxy", "true",
|
||||
"disable rp_filter on console proxy VM public interface", false, ConfigKey.Scope.Zone, null);
|
||||
"disable rp_filter on console proxy VM public interface", true, ConfigKey.Scope.Zone, null);
|
||||
|
||||
ConfigKey<Integer> 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);
|
||||
|
|
|
|||
|
|
@ -1627,33 +1627,44 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
|
|||
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);
|
||||
}
|
||||
serviceOfferingVO = getServiceOfferingByUuidOrId(cpvmSrvcOffIdStr, warningMessage, 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);
|
||||
}
|
||||
logger.debug("Service offering for console proxy VM is not set or not a system service offering. Creating a default service offering.");
|
||||
createServiceOfferingForConsoleProxy();
|
||||
}
|
||||
return serviceOfferingVO;
|
||||
}
|
||||
|
||||
private ServiceOfferingVO getServiceOfferingByUuidOrId(String cpvmSrvcOffIdStr, String warningMessage, String configKey) {
|
||||
ServiceOfferingVO 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);
|
||||
}
|
||||
|
||||
return serviceOfferingVO;
|
||||
}
|
||||
|
||||
private void createServiceOfferingForConsoleProxy() throws ConfigurationException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue