abh1sar commented on code in PR #14310:
URL: https://github.com/apache/cloudstack/pull/14310#discussion_r4335465532


##########
engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupUsageMetricDaoImpl.java:
##########
@@ -0,0 +1,54 @@
+// 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.backup.dao;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.cloudstack.backup.BackupUsageMetricVO;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+public class BackupUsageMetricDaoImpl extends 
GenericDaoBase<BackupUsageMetricVO, Long> implements BackupUsageMetricDao {
+    private SearchBuilder<BackupUsageMetricVO> vmAndOfferingSearch;
+
+    @PostConstruct
+    protected void init() {
+        vmAndOfferingSearch = createSearchBuilder();
+        vmAndOfferingSearch.and("vmId", 
vmAndOfferingSearch.entity().getVmId(), SearchCriteria.Op.EQ);
+        vmAndOfferingSearch.and("backupOfferingId", 
vmAndOfferingSearch.entity().getBackupOfferingId(), SearchCriteria.Op.EQ);
+        vmAndOfferingSearch.done();
+    }
+
+    private SearchCriteria<BackupUsageMetricVO> 
createVmAndOfferingCriteria(long vmId, long backupOfferingId) {
+        SearchCriteria<BackupUsageMetricVO> sc = vmAndOfferingSearch.create();
+        sc.setParameters("vmId", vmId);
+        sc.setParameters("backupOfferingId", backupOfferingId);
+        return sc;
+    }
+
+    @Override
+    public BackupUsageMetricVO findByVmAndOffering(long vmId, long 
backupOfferingId) {
+        return findOneBy(createVmAndOfferingCriteria(vmId, backupOfferingId));
+    }
+
+    @Override
+    public int removeByVmAndOffering(long vmId, long backupOfferingId) {
+        return remove(createVmAndOfferingCriteria(vmId, backupOfferingId));

Review Comment:
   @harikrishna-patnala I would avoid adding a removed column. The 
backup_usage_metrics table is an intermediate table to make sure that backup 
metrics usage doesn't get logged repeatedly with the same value.
   Keeping older deleted backup_usage_metrics column is not useful as the  
cloud_usage table already contains the recorded usage history.
   We also enforce the vm_id, backup_offering_id unique key constraint which 
won't be possible with the removed column.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to