This is an automated email from the ASF dual-hosted git repository. DaanHoogland pushed a commit to branch ghi10752-configCleanup in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit beffd75738fe716e4df9d3ede5537eaf55f03acc Author: Daan Hoogland <[email protected]> AuthorDate: Thu Aug 13 13:03:44 2026 +0200 move alert manager configurations out of the deprecated Config enum --- .../main/java/com/cloud/alert/AlertManager.java | 53 +++++++++++++++ .../java/com/cloud/alert/AlertManagerImpl.java | 49 +++++--------- .../main/java/com/cloud/configuration/Config.java | 78 ---------------------- .../configuration/ConfigurationManagerImpl.java | 12 ++-- .../ConfigurationManagerImplTest.java | 2 +- .../com/cloud/usage/UsageAlertManagerImpl.java | 4 +- 6 files changed, 77 insertions(+), 121 deletions(-) diff --git a/engine/components-api/src/main/java/com/cloud/alert/AlertManager.java b/engine/components-api/src/main/java/com/cloud/alert/AlertManager.java index 46993b066a4..aece878d93f 100644 --- a/engine/components-api/src/main/java/com/cloud/alert/AlertManager.java +++ b/engine/components-api/src/main/java/com/cloud/alert/AlertManager.java @@ -53,6 +53,59 @@ public interface AlertManager extends Manager, AlertService { "alert.allowed.repetitive.types", "", "Comma-separated list of alert types (by name) that can be sent multiple times", true); + ConfigKey<String> AlertEmailAddresses = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, String.class, + "alert.email.addresses", null, + "Comma separated list of email addresses which are going to receive alert emails.", true, + ConfigKey.Kind.CSV, null); + + ConfigKey<String> AlertEmailSender = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, String.class, + "alert.email.sender", null, + "Sender of alert email (will be in the From header of the email).", true); + + ConfigKey<String> AlertSMTPHost = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, String.class, + "alert.smtp.host", null, + "SMTP hostname used for sending out email alerts.", true); + + ConfigKey<Integer> AlertSMTPPort = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Integer.class, + "alert.smtp.port", "465", + "Port the SMTP server is listening on.", true); + + ConfigKey<String> AlertSMTPUsername = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, String.class, + "alert.smtp.username", null, + "Username for SMTP authentication (applies only if alert.smtp.useAuth is true).", true); + + ConfigKey<String> AlertSMTPPassword = new ConfigKey<>("Secure", String.class, + "alert.smtp.password", null, + "Password for SMTP authentication (applies only if alert.smtp.useAuth is true).", true); + + ConfigKey<Integer> CapacityCheckPeriod = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Integer.class, + "capacity.check.period", "300000", + "The interval in milliseconds between capacity checks", true); + + ConfigKey<Double> PublicIpCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "zone.virtualnetwork.publicip.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent.", true); + + ConfigKey<Double> PrivateIpCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "pod.privateip.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent.", true); + + ConfigKey<Double> SecondaryStorageCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "zone.secstorage.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of secondary storage utilization above which alerts will be sent about low storage available.", true); + + ConfigKey<Double> VlanCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "zone.vlan.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.", true); + + ConfigKey<Double> DirectNetworkPublicIpCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "zone.directnetwork.publicip.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", true); + + ConfigKey<Double> LocalStorageCapacityThreshold = new ConfigKey<>(ConfigKey.CATEGORY_ALERT, Double.class, + "cluster.localStorage.capacity.notificationthreshold", "0.75", + "Percentage (as a value between 0 and 1) of local storage utilization above which alerts will be sent about low local storage available.", true); + void clearAlert(AlertType alertType, long dataCenterId, long podId); void recalculateCapacity(); diff --git a/server/src/main/java/com/cloud/alert/AlertManagerImpl.java b/server/src/main/java/com/cloud/alert/AlertManagerImpl.java index 27b445ba376..ee890cb6398 100644 --- a/server/src/main/java/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/main/java/com/cloud/alert/AlertManagerImpl.java @@ -64,7 +64,6 @@ import com.cloud.capacity.CapacityState; import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity; -import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; @@ -174,12 +173,12 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi Map<String, String> configs = _configDao.getConfiguration("management-server", params); // set up the email system for alerts - String emailAddressList = configs.get("alert.email.addresses"); + String emailAddressList = AlertEmailAddresses.value(); if (emailAddressList != null) { recipients = emailAddressList.split(","); } - senderAddress = configs.get("alert.email.sender"); + senderAddress = AlertEmailSender.value(); String namespace = "alert.smtp"; String timeoutConfig = String.format("%s.timeout", namespace); @@ -193,33 +192,15 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi mailSender = new SMTPMailSender(configs, namespace); - String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key()); - String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key()); - String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key()); - String vlanCapacityThreshold = _configDao.getValue(Config.VlanCapacityThreshold.key()); - String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key()); - String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key()); + _publicIPCapacityThreshold = PublicIpCapacityThreshold.value(); + _privateIPCapacityThreshold = PrivateIpCapacityThreshold.value(); + _secondaryStorageCapacityThreshold = SecondaryStorageCapacityThreshold.value(); + _vlanCapacityThreshold = VlanCapacityThreshold.value(); + _directNetworkPublicIpCapacityThreshold = DirectNetworkPublicIpCapacityThreshold.value(); + _localStorageCapacityThreshold = LocalStorageCapacityThreshold.value(); String backupStorageCapacityThreshold = _configDao.getValue(BackupManager.BackupStorageCapacityThreshold.key()); String objectStorageCapacityThreshold = _configDao.getValue(_storageMgr.ObjectStorageCapacityThreshold.key()); - if (publicIPCapacityThreshold != null) { - _publicIPCapacityThreshold = Double.parseDouble(publicIPCapacityThreshold); - } - if (privateIPCapacityThreshold != null) { - _privateIPCapacityThreshold = Double.parseDouble(privateIPCapacityThreshold); - } - if (secondaryStorageCapacityThreshold != null) { - _secondaryStorageCapacityThreshold = Double.parseDouble(secondaryStorageCapacityThreshold); - } - if (vlanCapacityThreshold != null) { - _vlanCapacityThreshold = Double.parseDouble(vlanCapacityThreshold); - } - if (directNetworkPublicIpCapacityThreshold != null) { - _directNetworkPublicIpCapacityThreshold = Double.parseDouble(directNetworkPublicIpCapacityThreshold); - } - if (localStorageCapacityThreshold != null) { - _localStorageCapacityThreshold = Double.parseDouble(localStorageCapacityThreshold); - } if (backupStorageCapacityThreshold != null) { _backupStorageCapacityThreshold = Double.parseDouble(backupStorageCapacityThreshold); } @@ -237,12 +218,9 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_BACKUP_STORAGE, _backupStorageCapacityThreshold); _capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_OBJECT_STORAGE, _objectStorageCapacityThreshold); - String capacityCheckPeriodStr = configs.get("capacity.check.period"); - if (capacityCheckPeriodStr != null) { - _capacityCheckPeriod = Long.parseLong(capacityCheckPeriodStr); - if (_capacityCheckPeriod <= 0) { - _capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue()); - } + _capacityCheckPeriod = CapacityCheckPeriod.value(); + if (_capacityCheckPeriod <= 0) { + _capacityCheckPeriod = Long.parseLong(CapacityCheckPeriod.defaultValue()); } initMessageBusListener(); setupRepetitiveAlertTypes(); @@ -893,7 +871,10 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi @Override public ConfigKey<?>[] getConfigKeys() { return new ConfigKey<?>[] {CPUCapacityThreshold, MemoryCapacityThreshold, StorageAllocatedCapacityThreshold, StorageCapacityThreshold, AlertSmtpEnabledSecurityProtocols, - AlertSmtpUseStartTLS, Ipv6SubnetCapacityThreshold, AlertSmtpUseAuth, AllowedRepetitiveAlertTypes}; + AlertSmtpUseStartTLS, Ipv6SubnetCapacityThreshold, AlertSmtpUseAuth, AllowedRepetitiveAlertTypes, + AlertEmailAddresses, AlertEmailSender, AlertSMTPHost, AlertSMTPPort, AlertSMTPUsername, AlertSMTPPassword, CapacityCheckPeriod, + PublicIpCapacityThreshold, PrivateIpCapacityThreshold, SecondaryStorageCapacityThreshold, VlanCapacityThreshold, + DirectNetworkPublicIpCapacityThreshold, LocalStorageCapacityThreshold}; } @Override diff --git a/server/src/main/java/com/cloud/configuration/Config.java b/server/src/main/java/com/cloud/configuration/Config.java index 2f4f7fa8ac5..af9133ae4d3 100644 --- a/server/src/main/java/com/cloud/configuration/Config.java +++ b/server/src/main/java/com/cloud/configuration/Config.java @@ -45,27 +45,6 @@ public enum Config { // Alert - AlertEmailAddresses( - "Alert", - ManagementServer.class, - String.class, - "alert.email.addresses", - null, - "Comma separated list of email addresses which are going to receive alert emails.", - null, - ConfigKey.Kind.CSV, - null), - AlertEmailSender("Alert", ManagementServer.class, String.class, "alert.email.sender", null, "Sender of alert email (will be in the From header of the email).", null), - AlertSMTPHost("Alert", ManagementServer.class, String.class, "alert.smtp.host", null, "SMTP hostname used for sending out email alerts.", null), - AlertSMTPPassword( - "Secure", - ManagementServer.class, - String.class, - "alert.smtp.password", - null, - "Password for SMTP authentication (applies only if alert.smtp.useAuth is true).", - null), - AlertSMTPPort("Alert", ManagementServer.class, Integer.class, "alert.smtp.port", "465", "Port the SMTP server is listening on.", null), AlertSMTPConnectionTimeout("Alert", ManagementServer.class, Integer.class, "alert.smtp.connectiontimeout", "30000", "Socket connection timeout value in milliseconds. -1 for infinite timeout.", null), AlertSMTPTimeout( @@ -76,63 +55,6 @@ public enum Config { "30000", "Socket I/O timeout value in milliseconds. -1 for infinite timeout.", null), - AlertSMTPUsername( - "Alert", - ManagementServer.class, - String.class, - "alert.smtp.username", - null, - "Username for SMTP authentication (applies only if alert.smtp.useAuth is true).", - null), - CapacityCheckPeriod("Alert", ManagementServer.class, Integer.class, "capacity.check.period", "300000", "The interval in milliseconds between capacity checks", null), - PublicIpCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "zone.virtualnetwork.publicip.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent.", - null), - PrivateIpCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "pod.privateip.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent.", - null), - SecondaryStorageCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "zone.secstorage.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of secondary storage utilization above which alerts will be sent about low storage available.", - null), - VlanCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "zone.vlan.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.", - null), - DirectNetworkPublicIpCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "zone.directnetwork.publicip.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", - null), - LocalStorageCapacityThreshold( - "Alert", - ManagementServer.class, - Float.class, - "cluster.localStorage.capacity.notificationthreshold", - "0.75", - "Percentage (as a value between 0 and 1) of local storage utilization above which alerts will be sent about low local storage available.", - null), // Storage diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index 837254ed8b3..ca942ff34ad 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -637,12 +637,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati weightBasedParametersForValidation.add(AlertManager.StorageAllocatedCapacityThreshold.key()); weightBasedParametersForValidation.add(AlertManager.StorageCapacityThreshold.key()); weightBasedParametersForValidation.add(AlertManager.MemoryCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.PublicIpCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.PrivateIpCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.SecondaryStorageCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.VlanCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.DirectNetworkPublicIpCapacityThreshold.key()); - weightBasedParametersForValidation.add(Config.LocalStorageCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.PublicIpCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.PrivateIpCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.SecondaryStorageCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.VlanCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.DirectNetworkPublicIpCapacityThreshold.key()); + weightBasedParametersForValidation.add(AlertManager.LocalStorageCapacityThreshold.key()); weightBasedParametersForValidation.add(CapacityManager.StorageAllocatedCapacityDisableThreshold.key()); weightBasedParametersForValidation.add(CapacityManager.StorageCapacityDisableThreshold.key()); weightBasedParametersForValidation.add(CapacityManager.StorageAllocatedCapacityDisableThresholdForVolumeSize.key()); diff --git a/server/src/test/java/com/cloud/configuration/ConfigurationManagerImplTest.java b/server/src/test/java/com/cloud/configuration/ConfigurationManagerImplTest.java index 9a0b150780e..360e9ef1077 100644 --- a/server/src/test/java/com/cloud/configuration/ConfigurationManagerImplTest.java +++ b/server/src/test/java/com/cloud/configuration/ConfigurationManagerImplTest.java @@ -957,7 +957,7 @@ public class ConfigurationManagerImplTest { @Test public void getConfigurationTypeWrapperClassTestReturnsConfigType() { - Config configuration = Config.AlertEmailAddresses; + Config configuration = Config.AlertSMTPConnectionTimeout; Assert.assertEquals(configuration.getType(), configurationManagerImplSpy.getConfigurationTypeWrapperClass(configuration.key())); } diff --git a/usage/src/main/java/com/cloud/usage/UsageAlertManagerImpl.java b/usage/src/main/java/com/cloud/usage/UsageAlertManagerImpl.java index 675118ddfab..3ddfe66e3d2 100644 --- a/usage/src/main/java/com/cloud/usage/UsageAlertManagerImpl.java +++ b/usage/src/main/java/com/cloud/usage/UsageAlertManagerImpl.java @@ -55,8 +55,8 @@ public class UsageAlertManagerImpl extends ManagerBase implements AlertManager { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { Map<String, String> configs = _configDao.getConfiguration("management-server", params); - senderAddress = configs.get("alert.email.sender"); - String emailAddressList = configs.get("alert.email.addresses"); + senderAddress = AlertEmailSender.value(); + String emailAddressList = AlertEmailAddresses.value(); recipients = null; if (emailAddressList != null) { recipients = emailAddressList.split(",");
