Return-Path: X-Original-To: apmail-cloudstack-dev-archive@www.apache.org Delivered-To: apmail-cloudstack-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9A4AF178E1 for ; Sat, 10 Oct 2015 18:06:46 +0000 (UTC) Received: (qmail 87541 invoked by uid 500); 10 Oct 2015 18:06:46 -0000 Delivered-To: apmail-cloudstack-dev-archive@cloudstack.apache.org Received: (qmail 87487 invoked by uid 500); 10 Oct 2015 18:06:46 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 87472 invoked by uid 99); 10 Oct 2015 18:06:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Oct 2015 18:06:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AB6B6E0243; Sat, 10 Oct 2015 18:06:45 +0000 (UTC) From: bhaisaab To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: Quota Content-Type: text/plain Message-Id: <20151010180645.AB6B6E0243@git1-us-west.apache.org> Date: Sat, 10 Oct 2015 18:06:45 +0000 (UTC) Github user bhaisaab commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/768#discussion_r41699781 --- Diff: framework/quota/src/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java --- @@ -0,0 +1,81 @@ +//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 com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.quota.vo.QuotaUsageVO; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import javax.ejb.Local; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Component +@Local(value = { QuotaUsageDao.class }) +public class QuotaUsageDaoImpl extends GenericDaoBase implements QuotaUsageDao { + private static final Logger s_logger = Logger.getLogger(QuotaUsageDaoImpl.class.getName()); + + @Override + public BigDecimal findTotalQuotaUsage(final Long accountId, final Long domainId, final Integer usageType, final Date startDate, final Date endDate) { + List quotaUsage = findQuotaUsage(accountId, domainId, null, startDate, endDate); + BigDecimal total = new BigDecimal(0); + for (QuotaUsageVO quotaRecord: quotaUsage) { + total = total.add(quotaRecord.getQuotaUsed()); + } + return total; + } + + @SuppressWarnings("deprecation") + @Override + public List findQuotaUsage(final Long accountId, final Long domainId, final Integer usageType, final Date startDate, final Date endDate) { + final short opendb = TransactionLegacy.currentTxn().getDatabaseId(); + List quotaUsageRecords = new ArrayList(); + try (TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB)) { + // TODO instead of max value query with reasonable number and iterate + SearchCriteria sc = createSearchCriteria(); + if (accountId != null) { + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + } + if (domainId != null) { + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + } + if (usageType != null) { + sc.addAnd("usageType", SearchCriteria.Op.EQ, usageType); + } + if ((startDate != null) && (endDate != null) && startDate.before(endDate)) { + sc.addAnd("startDate", SearchCriteria.Op.BETWEEN, startDate, endDate); + sc.addAnd("endDate", SearchCriteria.Op.BETWEEN, startDate, endDate); + } else { + return new ArrayList(); --- End diff -- Fixed. --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---