Github user jburwell commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/768#discussion_r39470029
--- Diff:
framework/quota/src/org/apache/cloudstack/quota/dao/ServiceOfferingDaoImpl.java
---
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.quota.dao;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.ServiceOfferingVO;
+
+import com.cloud.event.UsageEventVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value = { ServiceOfferingDao.class })
+@DB()
+public class ServiceOfferingDaoImpl extends
GenericDaoBase<ServiceOfferingVO, Long> implements ServiceOfferingDao {
+ protected static final Logger s_logger =
Logger.getLogger(ServiceOfferingDaoImpl.class);
+
+ @Inject
+ UserVmDetailsDao userVmDetailsDao;
+
+ @Override
+ public ServiceOfferingVO findServiceOffering(final Long vmId, final
long serviceOfferingId) {
+ final short opendb =
TransactionLegacy.currentTxn().getDatabaseId();
+ ServiceOfferingVO result = null;
+ try (TransactionLegacy txn =
TransactionLegacy.open(TransactionLegacy.CLOUD_DB)) {
+ result = findById(vmId, serviceOfferingId);
+ } catch (Exception e) {
+ s_logger.error("Quota
ServiceOfferingDaoImpl::findServiceOffering() failed due to: " +
e.getMessage());
+ throw new CloudRuntimeException("Unable to find service
offering for quota calculations");
+ } finally {
+ TransactionLegacy.open(opendb).close();
+ }
+ return result;
+ }
+
+ private ServiceOfferingVO findById(Long vmId, long serviceOfferingId) {
+ ServiceOfferingVO offering = super.findById(serviceOfferingId);
+ if (offering.isDynamic()) {
+ if (vmId == null) {
+ throw new CloudRuntimeException("missing argument vmId");
+ }
+ offering.setDynamicFlag(true);
+ Map<String, String> dynamicOffering =
userVmDetailsDao.listDetailsKeyPairs(vmId);
+ return getcomputeOffering(offering, dynamicOffering);
+ }
+ return offering;
+ }
+
+ private ServiceOfferingVO getcomputeOffering(ServiceOfferingVO
serviceOffering, Map<String, String> customParameters) {
--- End diff --
Why isn't the type of ``customParameters``
``Map<UsageEventVO.DynamicParameters, String>? This would allow key lookups on
this Map to use the enumeration values without having to invoke the ``name()``
method -- improving type safety and simplifying the code.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---