4242import javax .naming .ConfigurationException ;
4343import javax .persistence .EntityExistsException ;
4444
45+ import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
4546import org .apache .cloudstack .managed .context .ManagedContextRunnable ;
4647import org .apache .cloudstack .quota .QuotaAlertManager ;
4748import org .apache .cloudstack .quota .QuotaManager ;
9293import com .cloud .utils .db .QueryBuilder ;
9394import com .cloud .utils .db .SearchCriteria ;
9495import com .cloud .utils .db .TransactionLegacy ;
96+ import com .cloud .utils .exception .CloudRuntimeException ;
9597
9698@ Component
9799public 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