Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -71,7 +70,6 @@
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
Expand All @@ -83,6 +81,7 @@
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.snapshot.VMSnapshotManager;
import com.cloud.vm.snapshot.VMSnapshotVO;
import com.cloud.vm.snapshot.dao.VMSnapshotDao;

Expand All @@ -99,8 +98,6 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot
VMSnapshotDao vmSnapshotDao;
int _wait;
@Inject
ConfigurationDao configurationDao;
@Inject
AgentManager agentMgr;
@Inject
VolumeDao volumeDao;
Expand Down Expand Up @@ -129,8 +126,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
String value = configurationDao.getValue("vmsnapshot.create.wait");
_wait = NumbersUtil.parseInt(value, 1800);
_wait = VMSnapshotManager.VMSnapshotCreateWait.value();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.cloud.storage.StoragePool;
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.api.SnapshotGroup;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
Expand All @@ -55,7 +54,6 @@
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
Expand All @@ -66,6 +64,7 @@
import com.cloud.vm.UserVmVO;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.snapshot.VMSnapshotManager;
import com.cloud.vm.snapshot.VMSnapshotDetailsVO;
import com.cloud.vm.snapshot.VMSnapshotVO;
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
Expand All @@ -82,8 +81,6 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot
protected VMSnapshotDetailsDao vmSnapshotDetailsDao;
int _wait;
@Inject
ConfigurationDao configurationDao;
@Inject
VolumeDao volumeDao;
@Inject
DiskOfferingDao diskOfferingDao;
Expand All @@ -96,8 +93,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
String value = configurationDao.getValue("vmsnapshot.create.wait");
_wait = NumbersUtil.parseInt(value, 1800);
_wait = VMSnapshotManager.VMSnapshotCreateWait.value();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.command.ForgetObjectCmd;
import org.apache.cloudstack.storage.command.IntroduceObjectAnswer;
import org.apache.cloudstack.storage.command.IntroduceObjectCmd;
Expand All @@ -51,10 +50,10 @@
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.snapshot.VMSnapshotManager;

public class HypervisorHelperImpl implements HypervisorHelper {
protected Logger logger = LogManager.getLogger(getClass());
Expand All @@ -67,8 +66,6 @@ public class HypervisorHelperImpl implements HypervisorHelper {
@Inject
GuestOSHypervisorDao guestOsHypervisorDao;
@Inject
ConfigurationDao configurationDao;
@Inject
AgentManager agentMgr;
@Inject
HostDao hostDao;
Expand Down Expand Up @@ -117,8 +114,7 @@ public boolean forgetObject(DataTO object, Scope scope, Long storeId) {

@Override
public VMSnapshotTO quiesceVm(VirtualMachine virtualMachine) {
String value = configurationDao.getValue("vmsnapshot.create.wait");
int wait = NumbersUtil.parseInt(value, 1800);
int wait = VMSnapshotManager.VMSnapshotCreateWait.value();
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(1L, UUID.randomUUID().toString(), VMSnapshot.Type.Disk, null, null, false,
null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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.UsageTypes;
import org.apache.cloudstack.usage.UsageUnitTypes;
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
Expand Down Expand Up @@ -124,7 +125,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
mergeConfigs(configs, params);
}

String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(configs.get("usage.aggregation.timezone"), "GMT");
// also runs in the usage server, which has no ConfigDepot: read the value from the DB map
String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(configs.get(UsageService.UsageAggregationTimezone.key()), "GMT");
usageAggregationTimeZone = TimeZone.getTimeZone(usageAggregationTimeZoneStr);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
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;
Expand Down Expand Up @@ -103,7 +103,7 @@ public QuotaServiceImpl() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +108,6 @@ public void setup() throws IllegalAccessException, NoSuchFieldException, Configu
QuotaResponseBuilderField.setAccessible(true);
QuotaResponseBuilderField.set(quotaServiceImplSpy, respBldr);

Mockito.when(configDao.getValue(Mockito.eq(Config.UsageAggregationTimezone.toString()))).thenReturn("IST");
quotaServiceImplSpy.configure("randomName", null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
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;
Expand Down Expand Up @@ -606,7 +607,7 @@ protected void populateConfigValuesForValidationSet() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
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;
Expand All @@ -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);
Expand All @@ -48,7 +45,7 @@ public boolean configure(final String name, final Map<String, Object> xmlParams)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
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;
Expand Down Expand Up @@ -78,7 +77,6 @@
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;
Expand Down Expand Up @@ -222,9 +220,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
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;
Expand Down Expand Up @@ -599,9 +600,8 @@ public boolean configure(final String name, final Map<String, Object> params) th

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";
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/java/com/cloud/server/StatsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.apache.cloudstack.network.RoutedIpv4Manager;
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;
Expand Down Expand Up @@ -562,9 +563,8 @@ protected void init(Map<String, String> configs) {
//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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao;
Expand Down Expand Up @@ -58,7 +58,6 @@
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.DateUtil.IntervalType;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.TestClock;
Expand All @@ -85,9 +84,23 @@
@Inject
protected VolumeDao _volsDao;
@Inject
protected ConfigurationDao _configDao;
@Inject
protected ApiDispatcher _dispatcher;

// QA-only test hook: lets snapshots be scheduled on an accelerated, admin-configured clock instead of a real calendar.
private static final ConfigKey<Boolean> SnapshotRecurringTest = new ConfigKey<>("Advanced", Boolean.class, "snapshot.recurring.test", "false",

Check failure on line 90 in server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "Advanced" 7 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaFkGaXDzix1cTpEzMbR&open=AaFkGaXDzix1cTpEzMbR&pullRequest=14470
"Enable accelerated snapshot recurrence for testing purposes.", true);
private static final ConfigKey<Integer> SnapshotTestMinutesPerHour = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.minutes.per.hour", "60",
"Minutes per simulated hour when snapshot.recurring.test is enabled.", true);
private static final ConfigKey<Integer> SnapshotTestHoursPerDay = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.hours.per.day", "24",
"Hours per simulated day when snapshot.recurring.test is enabled.", true);
private static final ConfigKey<Integer> SnapshotTestDaysPerWeek = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.days.per.week", "7",
"Days per simulated week when snapshot.recurring.test is enabled.", true);
private static final ConfigKey<Integer> SnapshotTestDaysPerMonth = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.days.per.month", "30",
"Days per simulated month when snapshot.recurring.test is enabled.", true);
private static final ConfigKey<Integer> SnapshotTestWeeksPerMonth = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.weeks.per.month", "4",
"Weeks per simulated month when snapshot.recurring.test is enabled.", true);
private static final ConfigKey<Integer> SnapshotTestMonthsPerYear = new ConfigKey<>("Advanced", Integer.class, "snapshot.test.months.per.year", "12",
"Months per simulated year when snapshot.recurring.test is enabled.", true);
@Inject
protected AccountDao _acctDao;
@Inject
Expand Down Expand Up @@ -446,16 +459,16 @@
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {

_snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
final boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
_snapshotPollInterval = SnapshotManager.SnapshotPollInterval.value();
final boolean snapshotsRecurringTest = SnapshotRecurringTest.value();
if (snapshotsRecurringTest) {
// look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code)
final int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
final int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
final int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
final int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
final int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
final int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
final int minutesPerHour = SnapshotTestMinutesPerHour.value();
final int hoursPerDay = SnapshotTestHoursPerDay.value();
final int daysPerWeek = SnapshotTestDaysPerWeek.value();
final int daysPerMonth = SnapshotTestDaysPerMonth.value();
final int weeksPerMonth = SnapshotTestWeeksPerMonth.value();
final int monthsPerYear = SnapshotTestMonthsPerYear.value();

_testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear);
}
Expand Down
Loading
Loading