Skip to content

Commit f3feda5

Browse files
Daan Hooglandclaude
andcommitted
read usage server settings from the DB, not ConfigKey.value()
The usage server has no ConfigDepot, so ConfigKey.value() only returns the built-in defaults there. Also drop an unused import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 759c73c commit f3feda5

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

‎framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
125125
mergeConfigs(configs, params);
126126
}
127127

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

131132
return true;

‎server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@
277277
import com.cloud.projects.Project;
278278
import com.cloud.projects.ProjectManager;
279279
import com.cloud.resourcelimit.CheckedReservation;
280-
import com.cloud.server.ManagementServer;
281280
import com.cloud.server.ManagementService;
282281
import com.cloud.service.ServiceOfferingDetailsVO;
283282
import com.cloud.service.ServiceOfferingVO;

‎usage/src/main/java/com/cloud/usage/UsageManagerImpl.java‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import javax.naming.ConfigurationException;
4343
import javax.persistence.EntityExistsException;
4444

45+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4546
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
4647
import org.apache.cloudstack.quota.QuotaAlertManager;
4748
import org.apache.cloudstack.quota.QuotaManager;
@@ -92,6 +93,7 @@
9293
import com.cloud.utils.db.QueryBuilder;
9394
import com.cloud.utils.db.SearchCriteria;
9495
import com.cloud.utils.db.TransactionLegacy;
96+
import com.cloud.utils.exception.CloudRuntimeException;
9597

9698
@Component
9799
public class UsageManagerImpl extends ManagerBase implements UsageManager, Runnable {
@@ -143,6 +145,8 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
143145
@Inject
144146
protected UsageEventDetailsDao _usageEventDetailsDao;
145147
@Inject
148+
ConfigurationDao _configDao;
149+
@Inject
146150
private UsageVMSnapshotDao _usageVMSnapshotDao;
147151
@Inject
148152
private UsageVMSnapshotOnPrimaryDao _usageSnapshotOnPrimaryDao;
@@ -192,6 +196,12 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
192196
public UsageManagerImpl() {
193197
}
194198

199+
private void mergeConfigs(Map<String, String> dbParams, Map<String, Object> xmlParams) {
200+
for (Map.Entry<String, Object> param : xmlParams.entrySet()) {
201+
dbParams.put(param.getKey(), (String)param.getValue());
202+
}
203+
}
204+
195205
@Override
196206
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
197207
final String run = "usage.vmops.pid";
@@ -208,15 +218,30 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
208218
logger.info("Implementation Version is " + _version);
209219
}
210220

211-
String execTime = UsageService.UsageStatsJobExecTime.value();
212-
Integer aggregationRange = UsageService.UsageStatsJobAggregationRange.value();
213-
String execTimeZone = UsageService.UsageExecutionTimezone.value();
214-
String aggregationTimeZone = UsageService.UsageAggregationTimezone.value();
215-
Integer sanityCheckInterval = UsageService.UsageSanityCheckInterval.value();
216-
_runQuota = QuotaConfig.QuotaPluginEnabled.value();
217-
usageSnapshotSelection = UsageService.UsageSnapshotVirtualSizeSelect.value();
221+
// the usage server has no ConfigDepot, so ConfigKey.value() would only return the defaults here
222+
Map<String, String> configs;
223+
try {
224+
configs = _configDao.getConfiguration(params);
225+
226+
if (params != null) {
227+
mergeConfigs(configs, params);
228+
logger.info("configs = " + configs);
229+
}
230+
} catch (CloudRuntimeException e) {
231+
logger.error("Unhandled configuration exception: " + e.getMessage());
232+
throw new CloudRuntimeException("Unhandled configuration exception", e);
233+
}
234+
235+
String execTime = configs.get(UsageService.UsageStatsJobExecTime.key());
236+
String aggregationRange = configs.get(UsageService.UsageStatsJobAggregationRange.key());
237+
String execTimeZone = configs.get(UsageService.UsageExecutionTimezone.key());
238+
String aggregationTimeZone = configs.get(UsageService.UsageAggregationTimezone.key());
239+
String sanityCheckInterval = configs.get(UsageService.UsageSanityCheckInterval.key());
240+
String quotaEnable = configs.get(QuotaConfig.QuotaPluginEnabled.key());
241+
_runQuota = Boolean.valueOf(quotaEnable == null ? "false" : quotaEnable );
242+
usageSnapshotSelection = Boolean.valueOf(configs.get(UsageService.UsageSnapshotVirtualSizeSelect.key()));
218243
if (sanityCheckInterval != null) {
219-
_sanityCheckInterval = sanityCheckInterval;
244+
_sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
220245
}
221246

222247
if (aggregationTimeZone != null && !aggregationTimeZone.isEmpty()) {
@@ -246,7 +271,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
246271
usageExecutionTimeZone.getID(), execTime, aggregationRange, DateUtil.displayDateInTimezone(usageExecutionTimeZone, new Date()),
247272
DateUtil.displayDateInTimezone(usageExecutionTimeZone, _jobExecTime.getTime()), usageAggregationTimeZone.getID());
248273

249-
_aggregationDuration = aggregationRange;
274+
_aggregationDuration = Integer.parseInt(aggregationRange);
250275
if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) {
251276
logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN);
252277
_aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN;

0 commit comments

Comments
 (0)