You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2026/08/15 11:39:47 UTC
(cloudstack) 03/10: move snapshot and usage configuration items from deprecated Config enum to services
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 14271892d9b5e1660d1edb5cf2fde1d71942368d
Author: Daan Hoogland <da...@apache.org>
AuthorDate: Fri Aug 14 09:14:06 2026 +0200
move snapshot and usage configuration items from deprecated Config enum to services
---
.../com/cloud/network/NetworkUsageService.java | 10 ++++
.../org/apache/cloudstack/usage/UsageService.java | 20 +++++++
.../apache/cloudstack/quota/QuotaManagerImpl.java | 3 +-
.../apache/cloudstack/quota/QuotaServiceImpl.java | 4 +-
.../cloudstack/quota/QuotaServiceImplTest.java | 2 -
.../main/java/com/cloud/configuration/Config.java | 64 ----------------------
.../configuration/ConfigurationManagerImpl.java | 3 +-
.../cloud/ha/HighAvailabilityManagerExtImpl.java | 7 +--
.../com/cloud/network/NetworkUsageManagerImpl.java | 22 ++++++--
.../router/VirtualNetworkApplianceManagerImpl.java | 6 +-
.../main/java/com/cloud/server/StatsCollector.java | 6 +-
.../cloud/storage/snapshot/SnapshotManager.java | 3 +
.../storage/snapshot/SnapshotManagerImpl.java | 2 +-
.../storage/snapshot/SnapshotSchedulerImpl.java | 2 +-
.../java/com/cloud/usage/UsageServiceImpl.java | 22 ++++++--
.../main/java/com/cloud/vm/UserVmManagerImpl.java | 4 +-
.../java/com/cloud/usage/UsageManagerImpl.java | 15 ++---
17 files changed, 92 insertions(+), 103 deletions(-)
diff --git a/api/src/main/java/com/cloud/network/NetworkUsageService.java b/api/src/main/java/com/cloud/network/NetworkUsageService.java
index 71a2f49b75f..dbb5ae41053 100644
--- a/api/src/main/java/com/cloud/network/NetworkUsageService.java
+++ b/api/src/main/java/com/cloud/network/NetworkUsageService.java
@@ -21,12 +21,22 @@ import java.util.List;
import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd;
import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficMonitorCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficMonitorsCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
import com.cloud.host.Host;
import com.cloud.utils.component.Manager;
public interface NetworkUsageService extends Manager {
+ ConfigKey<Integer> DirectNetworkStatsInterval = new ConfigKey<>("Usage", Integer.class, "direct.network.stats.interval", "86400",
+ "Interval (in seconds) to collect stats from Traffic Monitor", true);
+
+ ConfigKey<String> TrafficSentinelIncludeZones = new ConfigKey<>("Usage", String.class, "traffic.sentinel.include.zones", "EXTERNAL",
+ "Traffic going into specified list of zones is metered. For metering all traffic leave this parameter empty", true);
+
+ ConfigKey<String> TrafficSentinelExcludeZones = new ConfigKey<>("Usage", String.class, "traffic.sentinel.exclude.zones", "",
+ "Traffic going into specified list of zones is not metered.", true);
+
Host addTrafficMonitor(AddTrafficMonitorCmd cmd);
boolean deleteTrafficMonitor(DeleteTrafficMonitorCmd cmd);
diff --git a/api/src/main/java/org/apache/cloudstack/usage/UsageService.java b/api/src/main/java/org/apache/cloudstack/usage/UsageService.java
index 00e8b431f8f..d4c8ed75631 100644
--- a/api/src/main/java/org/apache/cloudstack/usage/UsageService.java
+++ b/api/src/main/java/org/apache/cloudstack/usage/UsageService.java
@@ -20,11 +20,31 @@ import com.cloud.utils.Pair;
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
import java.util.List;
import java.util.TimeZone;
public interface UsageService {
+
+ ConfigKey<String> UsageAggregationTimezone = new ConfigKey<>("Usage", String.class, "usage.aggregation.timezone", "GMT",
+ "The timezone to use for usage stats aggregation", true);
+
+ ConfigKey<String> UsageExecutionTimezone = new ConfigKey<>("Usage", String.class, "usage.execution.timezone", null,
+ "The timezone to use for usage job execution time", true);
+
+ ConfigKey<Integer> UsageSanityCheckInterval = new ConfigKey<>("Usage", Integer.class, "usage.sanity.check.interval", null,
+ "Interval (in days) to check sanity of usage data. To disable set it to 0 or negative.", true);
+
+ ConfigKey<Integer> UsageStatsJobAggregationRange = new ConfigKey<>("Usage", Integer.class, "usage.stats.job.aggregation.range", "1440",
+ "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.", true);
+
+ ConfigKey<String> UsageStatsJobExecTime = new ConfigKey<>("Usage", String.class, "usage.stats.job.exec.time", "00:15",
+ "The time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am.", true);
+
+ ConfigKey<Boolean> EnableUsageServer = new ConfigKey<>("Usage", Boolean.class, "enable.usage.server", "true",
+ "Flag for enabling usage", true);
+
/**
* Generate Billing Records from the last time it was generated to the
* time specified.
diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java
index 5afef8bc95b..1b8280d805e 100644
--- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java
+++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java
@@ -54,6 +54,7 @@ import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
import org.apache.cloudstack.quota.vo.QuotaTariffUsageVO;
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.usage.UsageUnitTypes;
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter;
@@ -123,7 +124,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
mergeConfigs(configs, params);
}
- String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(configs.get("usage.aggregation.timezone"), "GMT");
+ String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(UsageService.UsageAggregationTimezone.value(), "GMT");
usageAggregationTimeZone = TimeZone.getTimeZone(usageAggregationTimeZoneStr);
return true;
diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java
index a788f0c8b01..7a0ff05138b 100644
--- a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java
+++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java
@@ -59,11 +59,11 @@ import org.apache.cloudstack.quota.dao.QuotaUsageJoinDao;
import org.apache.cloudstack.quota.vo.QuotaAccountVO;
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
import org.apache.cloudstack.quota.vo.QuotaUsageJoinVO;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;
-import com.cloud.configuration.Config;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.user.Account;
@@ -103,7 +103,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
- String timeZoneStr = ObjectUtils.defaultIfNull(_configDao.getValue(Config.UsageAggregationTimezone.toString()), "GMT");
+ String timeZoneStr = ObjectUtils.defaultIfNull(UsageService.UsageAggregationTimezone.value(), "GMT");
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
return true;
diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java
index c0ee6c5fc3f..9126c36a203 100644
--- a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java
+++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java
@@ -16,7 +16,6 @@
// under the License.
package org.apache.cloudstack.quota;
-import com.cloud.configuration.Config;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.user.AccountVO;
@@ -109,7 +108,6 @@ public class QuotaServiceImplTest extends TestCase {
QuotaResponseBuilderField.setAccessible(true);
QuotaResponseBuilderField.set(quotaServiceImplSpy, respBldr);
- Mockito.when(configDao.getValue(Mockito.eq(Config.UsageAggregationTimezone.toString()))).thenReturn("IST");
quotaServiceImplSpy.configure("randomName", null);
}
diff --git a/server/src/main/java/com/cloud/configuration/Config.java b/server/src/main/java/com/cloud/configuration/Config.java
index f017741e3c5..911457d67bb 100644
--- a/server/src/main/java/com/cloud/configuration/Config.java
+++ b/server/src/main/java/com/cloud/configuration/Config.java
@@ -241,17 +241,6 @@ public enum Config {
"service monitoring in router enable/disable option, default false", null),
- // Snapshots
-
- SnapshotPollInterval(
- "Snapshots",
- SnapshotManager.class,
- Integer.class,
- "snapshot.poll.interval",
- "300",
- "The time interval in seconds when the management server polls for snapshots to be scheduled.",
- null),
-
// Advanced
EventPurgeInterval(
"Advanced",
@@ -937,59 +926,6 @@ public enum Config {
"Specify the virtual switch on host for private network",
null),
- // Usage
- UsageExecutionTimezone("Usage", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null),
- UsageStatsJobAggregationRange(
- "Usage",
- ManagementServer.class,
- Integer.class,
- "usage.stats.job.aggregation.range",
- "1440",
- "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.",
- null),
- UsageStatsJobExecTime(
- "Usage",
- ManagementServer.class,
- String.class,
- "usage.stats.job.exec.time",
- "00:15",
- "The time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am.",
- null),
- EnableUsageServer("Usage", ManagementServer.class, Boolean.class, "enable.usage.server", "true", "Flag for enabling usage", null),
- DirectNetworkStatsInterval(
- "Usage",
- ManagementServer.class,
- Integer.class,
- "direct.network.stats.interval",
- "86400",
- "Interval (in seconds) to collect stats from Traffic Monitor",
- null),
- UsageSanityCheckInterval(
- "Usage",
- ManagementServer.class,
- Integer.class,
- "usage.sanity.check.interval",
- null,
- "Interval (in days) to check sanity of usage data. To disable set it to 0 or negative.",
- null),
- UsageAggregationTimezone("Usage", ManagementServer.class, String.class, "usage.aggregation.timezone", "GMT", "The timezone to use for usage stats aggregation", null),
- TrafficSentinelIncludeZones(
- "Usage",
- ManagementServer.class,
- String.class,
- "traffic.sentinel.include.zones",
- "EXTERNAL",
- "Traffic going into specified list of zones is metered. For metering all traffic leave this parameter empty",
- null),
- TrafficSentinelExcludeZones(
- "Usage",
- ManagementServer.class,
- String.class,
- "traffic.sentinel.exclude.zones",
- "",
- "Traffic going into specified list of zones is not metered.",
- null),
-
// Hidden
UseSecondaryStorageVm(
"Hidden",
diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
index ca942ff34ad..4873d96d79a 100644
--- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -294,6 +294,7 @@ import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.storage.dao.VolumeDao;
+import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.test.IPRangeConfig;
import com.cloud.user.Account;
import com.cloud.user.AccountDetailVO;
@@ -606,7 +607,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
configValuesForValidation.add("host.stats.interval");
configValuesForValidation.add("network.gc.interval");
configValuesForValidation.add("ping.interval");
- configValuesForValidation.add("snapshot.poll.interval");
+ configValuesForValidation.add(SnapshotManager.SnapshotPollInterval.key());
configValuesForValidation.add("storage.stats.interval");
configValuesForValidation.add("storage.cleanup.interval");
configValuesForValidation.add("wait");
diff --git a/server/src/main/java/com/cloud/ha/HighAvailabilityManagerExtImpl.java b/server/src/main/java/com/cloud/ha/HighAvailabilityManagerExtImpl.java
index 6765992ec27..56bcdd33870 100644
--- a/server/src/main/java/com/cloud/ha/HighAvailabilityManagerExtImpl.java
+++ b/server/src/main/java/com/cloud/ha/HighAvailabilityManagerExtImpl.java
@@ -23,8 +23,8 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.usage.UsageService;
import com.cloud.alert.AlertManager;
import com.cloud.usage.dao.UsageJobDao;
@@ -35,9 +35,6 @@ public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl
@Inject
UsageJobDao _usageJobDao;
- @Inject
- ConfigurationDao configDao;
-
@Override
public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
super.configure(name, xmlParams);
@@ -48,7 +45,7 @@ public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl
public boolean start() {
super.start();
- boolean enableUsage = new Boolean(configDao.getValue("enable.usage.server"));
+ boolean enableUsage = UsageService.EnableUsageServer.value();
//By default, usage is enabled for production
//Devs might override this value to disable usage in their setup
diff --git a/server/src/main/java/com/cloud/network/NetworkUsageManagerImpl.java b/server/src/main/java/com/cloud/network/NetworkUsageManagerImpl.java
index 0aee5f23496..81da8cf1da4 100644
--- a/server/src/main/java/com/cloud/network/NetworkUsageManagerImpl.java
+++ b/server/src/main/java/com/cloud/network/NetworkUsageManagerImpl.java
@@ -33,6 +33,8 @@ import org.springframework.stereotype.Component;
import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd;
import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficMonitorCmd;
import org.apache.cloudstack.api.command.admin.usage.ListTrafficMonitorsCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.agent.AgentManager;
@@ -47,7 +49,6 @@ import com.cloud.agent.api.RecurringNetworkUsageCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupTrafficMonitorCommand;
import com.cloud.agent.manager.Commands;
-import com.cloud.configuration.Config;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.event.EventTypes;
@@ -76,7 +77,6 @@ import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.UserStatisticsVO;
import com.cloud.user.dao.UserStatisticsDao;
-import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
@@ -91,7 +91,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.MacAddress;
@Component
-public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsageService, NetworkUsageManager, ResourceStateAdapter {
+public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsageService, NetworkUsageManager, ResourceStateAdapter, Configurable {
public enum NetworkUsageResourceName {
TrafficSentinel;
}
@@ -220,9 +220,9 @@ public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsage
AllocatedIpSearch.join("network", networkJoin, AllocatedIpSearch.entity().getSourceNetworkId(), networkJoin.entity().getId(), JoinBuilder.JoinType.INNER);
AllocatedIpSearch.done();
- _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()), 86400);
- _TSinclZones = _configDao.getValue(Config.TrafficSentinelIncludeZones.key());
- _TSexclZones = _configDao.getValue(Config.TrafficSentinelExcludeZones.key());
+ _networkStatsInterval = DirectNetworkStatsInterval.value();
+ _TSinclZones = TrafficSentinelIncludeZones.value();
+ _TSexclZones = TrafficSentinelExcludeZones.value();
_agentMgr.registerForHostEvents(new DirectNetworkStatsListener(_networkStatsInterval), true, false, false);
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
return true;
@@ -562,4 +562,14 @@ public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsage
}
+ @Override
+ public String getConfigComponentName() {
+ return NetworkUsageService.class.getSimpleName();
+ }
+
+ @Override
+ public ConfigKey<?>[] getConfigKeys() {
+ return new ConfigKey<?>[] {DirectNetworkStatsInterval, TrafficSentinelIncludeZones, TrafficSentinelExcludeZones};
+ }
+
}
diff --git a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index a166e894be1..53c44e16d0b 100644
--- a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -74,6 +74,7 @@ import org.apache.cloudstack.network.BgpPeer;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.cloudstack.network.topology.NetworkTopology;
import org.apache.cloudstack.network.topology.NetworkTopologyContext;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.userdata.UserDataManager;
import org.apache.cloudstack.utils.CloudStackVersion;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
@@ -599,9 +600,8 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM
NetworkHelperImpl.setSystemAccount(_accountMgr.getSystemAccount());
- final String aggregationRange = configs.get("usage.stats.job.aggregation.range");
- _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
- _usageTimeZone = configs.get("usage.aggregation.timezone");
+ _usageAggregationRange = UsageService.UsageStatsJobAggregationRange.value();
+ _usageTimeZone = UsageService.UsageAggregationTimezone.value();
if (_usageTimeZone == null) {
_usageTimeZone = "GMT";
}
diff --git a/server/src/main/java/com/cloud/server/StatsCollector.java b/server/src/main/java/com/cloud/server/StatsCollector.java
index 2e53bd1c017..9147adb7490 100644
--- a/server/src/main/java/com/cloud/server/StatsCollector.java
+++ b/server/src/main/java/com/cloud/server/StatsCollector.java
@@ -59,6 +59,7 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
import org.apache.cloudstack.utils.graphite.GraphiteClient;
import org.apache.cloudstack.utils.graphite.GraphiteException;
@@ -548,9 +549,8 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
//Schedule disk stats update task
_diskStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DiskStatsUpdater"));
- String aggregationRange = configs.get("usage.stats.job.aggregation.range");
- _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
- _usageTimeZone = configs.get("usage.aggregation.timezone");
+ _usageAggregationRange = UsageService.UsageStatsJobAggregationRange.value();
+ _usageTimeZone = UsageService.UsageAggregationTimezone.value();
if (_usageTimeZone == null) {
_usageTimeZone = "GMT";
}
diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManager.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManager.java
index 0e802be3371..7eece969403 100644
--- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManager.java
+++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManager.java
@@ -78,6 +78,9 @@ public interface SnapshotManager extends Configurable {
ConfigKey<Integer> TotalRetries = new ConfigKey<>("Storage", Integer.class, "total.retries", "4",
"The number of times each command sent to a host should be retried in case of failure.", true);
+ ConfigKey<Integer> SnapshotPollInterval = new ConfigKey<>("Snapshots", Integer.class, "snapshot.poll.interval", "300",
+ "The time interval in seconds when the management server polls for snapshots to be scheduled.", true);
+
void deletePoliciesForVolume(Long volumeId);
/**
diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index fe3f9add5a0..8775c2edb37 100755
--- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -311,7 +311,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {BackupRetryAttempts, BackupRetryInterval, SnapshotHourlyMax, SnapshotDailyMax, SnapshotMonthlyMax, SnapshotWeeklyMax, usageSnapshotSelection,
SnapshotInfo.BackupSnapshotAfterTakingSnapshot, VmStorageSnapshotKvm, kvmIncrementalSnapshot, snapshotDeltaMax, snapshotShowChainSize, UseStorageReplication, KVMSnapshotEnabled,
- BackupSnapshotWait, TotalRetries};
+ BackupSnapshotWait, TotalRetries, SnapshotPollInterval};
}
@Override
diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index ddaa96100bd..4c0064bc84e 100644
--- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@ -446,7 +446,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
- _snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
+ _snapshotPollInterval = SnapshotManager.SnapshotPollInterval.value();
final boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
if (snapshotsRecurringTest) {
// look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code)
diff --git a/server/src/main/java/com/cloud/usage/UsageServiceImpl.java b/server/src/main/java/com/cloud/usage/UsageServiceImpl.java
index de8d4633d22..9bc91f5704f 100644
--- a/server/src/main/java/com/cloud/usage/UsageServiceImpl.java
+++ b/server/src/main/java/com/cloud/usage/UsageServiceImpl.java
@@ -30,6 +30,8 @@ import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.usage.Usage;
import org.apache.cloudstack.usage.UsageService;
@@ -40,7 +42,6 @@ import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
-import com.cloud.configuration.Config;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
@@ -85,7 +86,7 @@ import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.VMInstanceDao;
@Component
-public class UsageServiceImpl extends ManagerBase implements UsageService, Manager {
+public class UsageServiceImpl extends ManagerBase implements UsageService, Manager, Configurable {
//ToDo: Move implementation to ManagaerImpl
@@ -138,10 +139,10 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
- String timeZoneStr = ObjectUtils.defaultIfNull(_configDao.getValue(Config.UsageAggregationTimezone.toString()), "GMT");
+ String timeZoneStr = ObjectUtils.defaultIfNull(UsageAggregationTimezone.value(), "GMT");
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
- String executionTimeZone = _configDao.getValue(Config.UsageExecutionTimezone.toString());
+ String executionTimeZone = UsageExecutionTimezone.value();
if (executionTimeZone != null) {
usageExecutionTimeZone = TimeZone.getTimeZone(executionTimeZone);
}
@@ -480,7 +481,7 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
throw new InvalidParameterValueException("Interval should be greater than 0.");
}
- String jobExecTime = _configDao.getValue(Config.UsageStatsJobExecTime.toString());
+ String jobExecTime = UsageStatsJobExecTime.value();
Date previousJobExecTime = UsageUtils.getPreviousJobExecutionTime(usageExecutionTimeZone, jobExecTime);
Date nextJobExecTime = UsageUtils.getNextJobExecutionTime(usageExecutionTimeZone, jobExecTime);
if (ObjectUtils.allNotNull(previousJobExecTime, nextJobExecTime)) {
@@ -500,4 +501,15 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
_usageDao.expungeAllOlderThan(interval, ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());
return true;
}
+
+ @Override
+ public String getConfigComponentName() {
+ return UsageService.class.getSimpleName();
+ }
+
+ @Override
+ public ConfigKey<?>[] getConfigKeys() {
+ return new ConfigKey<?>[] {UsageAggregationTimezone, UsageExecutionTimezone, UsageSanityCheckInterval,
+ UsageStatsJobAggregationRange, UsageStatsJobExecTime, EnableUsageServer};
+ }
}
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index b3bc69835ff..05c5336f649 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -160,6 +160,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
import org.apache.cloudstack.storage.template.VnfTemplateManager;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.userdata.UserDataManager;
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
import org.apache.cloudstack.utils.security.ParserUtils;
@@ -2604,8 +2605,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
_vmIpFetchExecutor = Executors.newScheduledThreadPool(vmipwrks, new NamedThreadFactory("UserVm-ipfetch"));
- String aggregationRange = configs.get("usage.stats.job.aggregation.range");
- int _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
+ int _usageAggregationRange = UsageService.UsageStatsJobAggregationRange.value();
int HOURLY_TIME = 60;
final int DAILY_TIME = 60 * 24;
if (_usageAggregationRange == DAILY_TIME) {
diff --git a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
index eab371ab353..46b7a554d16 100644
--- a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
@@ -47,6 +47,7 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.quota.QuotaAlertManager;
import org.apache.cloudstack.quota.QuotaManager;
import org.apache.cloudstack.quota.QuotaStatement;
+import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.usage.UsageTypes;
import org.apache.cloudstack.utils.usage.UsageUtils;
import org.apache.commons.collections.CollectionUtils;
@@ -229,16 +230,16 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
throw new CloudRuntimeException("Unhandled configuration exception", e);
}
- String execTime = configs.get("usage.stats.job.exec.time");
- String aggregationRange = configs.get("usage.stats.job.aggregation.range");
- String execTimeZone = configs.get("usage.execution.timezone");
- String aggregationTimeZone = configs.get("usage.aggregation.timezone");
- String sanityCheckInterval = configs.get("usage.sanity.check.interval");
+ String execTime = UsageService.UsageStatsJobExecTime.value();
+ Integer aggregationRange = UsageService.UsageStatsJobAggregationRange.value();
+ String execTimeZone = UsageService.UsageExecutionTimezone.value();
+ String aggregationTimeZone = UsageService.UsageAggregationTimezone.value();
+ Integer sanityCheckInterval = UsageService.UsageSanityCheckInterval.value();
String quotaEnable = configs.get("quota.enable.service");
_runQuota = Boolean.valueOf(quotaEnable == null ? "false" : quotaEnable );
usageSnapshotSelection = Boolean.valueOf(configs.get("usage.snapshot.virtualsize.select"));
if (sanityCheckInterval != null) {
- _sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
+ _sanityCheckInterval = sanityCheckInterval;
}
if (aggregationTimeZone != null && !aggregationTimeZone.isEmpty()) {
@@ -268,7 +269,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
usageExecutionTimeZone.getID(), execTime, aggregationRange, DateUtil.displayDateInTimezone(usageExecutionTimeZone, new Date()),
DateUtil.displayDateInTimezone(usageExecutionTimeZone, _jobExecTime.getTime()), usageAggregationTimeZone.getID());
- _aggregationDuration = Integer.parseInt(aggregationRange);
+ _aggregationDuration = aggregationRange;
if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) {
logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN);
_aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN;