diff --git a/server/src/main/java/com/cloud/configuration/Config.java b/server/src/main/java/com/cloud/configuration/Config.java index 2f4f7fa8ac5d..c28fc556b7a3 100644 --- a/server/src/main/java/com/cloud/configuration/Config.java +++ b/server/src/main/java/com/cloud/configuration/Config.java @@ -1471,14 +1471,6 @@ public enum Config { "false", "Should be set to true, if there will be multiple NetScaler devices providing EIP service in a zone", null), - SecondaryStorageServiceOffering( - "Advanced", - ManagementServer.class, - String.class, - "secstorage.service.offering", - null, - "Uuid of the service offering used by secondary storage; if NULL - system offering will be used", - null), HaTag("Advanced", ManagementServer.class, String.class, "ha.tag", null, "HA tag defining that the host marked with this tag can be used for HA purposes only", null), ImplicitHostTags( "Advanced", diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java index 4e71d78fcbbd..15193a8be4aa 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManager.java @@ -61,7 +61,8 @@ public interface ConsoleProxyManager extends Manager, ConsoleProxyService { true, ConfigKey.Scope.Zone, null); ConfigKey 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", true, ConfigKey.Scope.Zone, null); + "UUID of the system offering used by console proxy VMs. If not found, ACS will fallback to the default system offering, " + + "or create one using the 'console.ram.size' and 'console.cpu.mhz' settings if it does not exist yet.", true, ConfigKey.Scope.Zone, null); ConfigKey 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); diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 796fa7b48a1a..54e96d173937 100644 --- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -560,7 +560,7 @@ public ConsoleProxyVO assignProxyFromStoppedPool(long dataCenterId) { return null; } - public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationException, ConfigurationException { + public ConsoleProxyVO startNew(long dataCenterId) throws ConcurrentOperationException { if (logger.isDebugEnabled()) { logger.debug("Assign console proxy from a newly started Instance for request from data center : " + dataCenterId); @@ -692,7 +692,7 @@ protected ConsoleProxyVO createOrUpdateConsoleProxy(ConsoleProxyVO proxy, long d return proxy; } - protected Map createProxyInstance(long dataCenterId, List templates) throws ConcurrentOperationException, ConfigurationException { + protected Map createProxyInstance(long dataCenterId, List templates) throws ConcurrentOperationException { long id = consoleProxyDao.getNextInSequence(Long.class, "id"); String name = VirtualMachineName.getConsoleProxyName(id, instance); @@ -844,7 +844,7 @@ private void allocCapacity(long dataCenterId) { if (allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC_IN_SECONDS)) { try { proxy = startNew(dataCenterId); - } catch (ConcurrentOperationException | ConfigurationException e) { + } catch (ConcurrentOperationException e) { logger.warn("Unable to start new console proxy on zone [{}] due to [{}].", zone, e.getMessage(), e); } finally { allocProxyLock.unlock(); @@ -1641,7 +1641,7 @@ private Integer getStandbyCapacity(Long datacenterId) { return Integer.parseInt(ConsoleProxyCapacityStandby.valueIn(datacenterId)); } - private ServiceOfferingVO getConsoleProxyServiceOffering(Long datacenterId) throws ConfigurationException { + private ServiceOfferingVO getConsoleProxyServiceOffering(Long datacenterId) { String configKey = ConsoleProxyServiceOffering.key(); String cpvmSrvcOffIdStr = ConsoleProxyServiceOffering.valueIn(datacenterId); 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); @@ -1650,7 +1650,12 @@ private ServiceOfferingVO getConsoleProxyServiceOffering(Long datacenterId) thro serviceOfferingVO = getServiceOfferingByUuidOrId(cpvmSrvcOffIdStr, warningMessage, configKey); } - if (serviceOfferingVO == null || !serviceOfferingVO.isSystemUse()) { + if (serviceOfferingVO != null && !serviceOfferingVO.isSystemUse()) { + logger.warn("The service offering [{}] set in the configuration [{}] for console proxy VM is not a system offering. The default system offering will be used instead.", cpvmSrvcOffIdStr, configKey); + serviceOfferingVO = null; + } + + if (serviceOfferingVO == null) { logger.debug("Service offering for console proxy VM is not set or not a system service offering. Creating a default service offering."); createServiceOfferingForConsoleProxy(); } @@ -1674,7 +1679,7 @@ private ServiceOfferingVO getServiceOfferingByUuidOrId(String cpvmSrvcOffIdStr, return serviceOfferingVO; } - private void createServiceOfferingForConsoleProxy() throws ConfigurationException { + private void createServiceOfferingForConsoleProxy() { 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 offerings = serviceOfferingDao.createSystemServiceOfferings("System Offering For Console Proxy", @@ -1682,9 +1687,9 @@ private void createServiceOfferingForConsoleProxy() throws ConfigurationExceptio 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?"; + String msg = "Unable to set a service offering for console proxy VM. Verify if it was removed."; logger.error(msg); - throw new ConfigurationException(msg); + throw new CloudRuntimeException(msg); } } } diff --git a/server/src/main/java/com/cloud/storage/secondary/SecondaryStorageVmManager.java b/server/src/main/java/com/cloud/storage/secondary/SecondaryStorageVmManager.java index 599e8c171c51..93b8b0c09c37 100644 --- a/server/src/main/java/com/cloud/storage/secondary/SecondaryStorageVmManager.java +++ b/server/src/main/java/com/cloud/storage/secondary/SecondaryStorageVmManager.java @@ -44,6 +44,10 @@ public interface SecondaryStorageVmManager extends Manager { "The time interval(in millisecond) to scan whether or not system needs more SSVM to ensure minimal standby capacity", false); + ConfigKey SecondaryStorageServiceOffering = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, String.class, "secstorage.service.offering", null, + "UUID of the system offering used by secondary storage VMs. If not found, ACS will fallback to the default system offering, " + + "or create one using the 'ssvm.ram.size' and 'ssvm.cpu.mhz' settings if it does not exist yet.", true, ConfigKey.Scope.Zone); + ConfigKey SecondaryStorageVmUserData = new ConfigKey<>(String.class, "secstorage.vm.userdata", ConfigKey.CATEGORY_ADVANCED, "", "UUID for user data for secondary storage VMs. This works only when systemvm.userdata.enabled is set to true", diff --git a/services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java index e26091f677ec..fdb1d714a01d 100644 --- a/services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java +++ b/services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java @@ -210,8 +210,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar protected SnapshotDao _snapshotDao; private SecondaryStorageListener _listener; - private ServiceOfferingVO _serviceOffering; - @Inject protected ConfigurationDao _configDao; @Inject @@ -685,7 +683,7 @@ protected Map createSecStorageVmInstance(long dataCenterId, Seco throw new CloudRuntimeException(String.format("Unable to find the system Templates or it was not downloaded in %s.", dc)); } - ServiceOfferingVO serviceOffering = _serviceOffering; + ServiceOfferingVO serviceOffering = findSecondaryStorageVmDefaultOffering(dataCenterId); if (serviceOffering == null) { serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId)); } @@ -713,6 +711,47 @@ protected Map createSecStorageVmInstance(long dataCenterId, Seco return context; } + private ServiceOfferingVO findSecondaryStorageVmDefaultOffering(long zoneId) { + ServiceOfferingVO serviceOfferingVO = null; + String configValue = SecondaryStorageServiceOffering.valueIn(zoneId); + String configKey = SecondaryStorageServiceOffering.key(); + if (configValue != null) { + serviceOfferingVO = _offeringDao.findByUuid(configValue); + if (serviceOfferingVO == null) { + try { + logger.debug("Unable to find a service offering by the UUID for secondary storage VM with the value [{}] set in the configuration [{}]. Trying to find by the ID.", configValue, configKey); + serviceOfferingVO = _offeringDao.findById(Long.parseLong(configValue)); + + if (serviceOfferingVO == null) { + logger.warn("Unable to find a service offering by the UUID or ID for secondary storage VM with the value [{}] set in the configuration [{}]", configValue, configKey); + } + } catch (NumberFormatException ex) { + logger.warn("Unable to find a service offering by the ID for secondary storage VM with the value [{}] set in the configuration [{}]. The value is not a valid integer number. Error: [{}].", configValue, configKey, ex.getMessage(), ex); + } + } + } + + if (serviceOfferingVO != null && !serviceOfferingVO.isSystemUse()) { + logger.warn("The service offering [{}] set in the configuration [{}] for secondary storage VM is not a system offering. The default system offering will be used instead.", configValue, configKey); + serviceOfferingVO = null; + } + + if (serviceOfferingVO == null) { + int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE); + int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ); + List offerings = _offeringDao.createSystemServiceOfferings("System Offering For Secondary Storage VM", + ServiceOffering.ssvmDefaultOffUniqueName, 1, ramSize, cpuFreq, null, null, false, null, + Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true); + + if (offerings == null || offerings.size() < 2) { + String msg = "Unable to set a service offering for secondary storage VM. Verify if it was removed."; + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + return serviceOfferingVO; + } + private SecondaryStorageVmAllocator getCurrentAllocator() { if (_ssVmAllocators.size() > 0) { return _ssVmAllocators.get(0); @@ -943,38 +982,6 @@ public boolean configure(String name, Map params) throws Configu _itMgr.registerGuru(VirtualMachine.Type.SecondaryStorageVm, this); - String configKey = Config.SecondaryStorageServiceOffering.key(); - String ssvmSrvcOffIdStr = configs.get(configKey); - if (ssvmSrvcOffIdStr != null) { - _serviceOffering = _offeringDao.findByUuid(ssvmSrvcOffIdStr); - if (_serviceOffering == null) { - try { - logger.debug(String.format("Unable to find a service offering by the UUID for secondary storage VM with the value [%s] set in the configuration [%s]. Trying to find by the ID.", ssvmSrvcOffIdStr, configKey)); - _serviceOffering = _offeringDao.findById(Long.parseLong(ssvmSrvcOffIdStr)); - - if (_serviceOffering == null) { - logger.info(String.format("Unable to find a service offering by the UUID or ID for secondary storage VM with the value [%s] set in the configuration [%s]", ssvmSrvcOffIdStr, configKey)); - } - } catch (NumberFormatException ex) { - logger.warn(String.format("Unable to find a service offering by the ID for secondary storage VM with the value [%s] set in the configuration [%s]. The value is not a valid integer number. Error: [%s].", ssvmSrvcOffIdStr, configKey, ex.getMessage()), ex); - } - } - } - - if (_serviceOffering == null || !_serviceOffering.isSystemUse()) { - int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE); - int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ); - List offerings = _offeringDao.createSystemServiceOfferings("System Offering For Secondary Storage VM", - ServiceOffering.ssvmDefaultOffUniqueName, 1, ramSize, cpuFreq, null, null, false, null, - Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true); - - if (offerings == null || offerings.size() < 2) { - String msg = "Unable to set a service offering for secondary storage VM. Verify if it was removed."; - logger.error(msg); - throw new ConfigurationException(msg); - } - } - if (_useServiceVM) { _loadScanner = new SystemVmLoadScanner<>(this); _loadScanner.initScan(STARTUP_DELAY_IN_MILLISECONDS, SecondaryStorageCapacityScanInterval.value()); @@ -1550,7 +1557,7 @@ public String getConfigComponentName() { @Override public ConfigKey[] getConfigKeys() { return new ConfigKey[] {NTPServerConfig, MaxNumberOfSsvmsForMigration, SecondaryStorageCapacityScanInterval, - SecondaryStorageVmUserData}; + SecondaryStorageServiceOffering, SecondaryStorageVmUserData}; } }