-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve Quota Statement #10506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Improve Quota Statement #10506
Changes from 3 commits
9617344
e702bb3
0a996dc
7d06715
58c0b5c
412a4bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //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.GenericDao; | ||
| import org.apache.cloudstack.quota.vo.QuotaUsageDetailVO; | ||
| import java.util.List; | ||
|
|
||
| public interface QuotaUsageDetailDao extends GenericDao<QuotaUsageDetailVO, Long> { | ||
|
|
||
| void persistQuotaUsageDetail(QuotaUsageDetailVO quotaUsageDetail); | ||
|
|
||
| List<QuotaUsageDetailVO> listQuotaUsageDetails(Long quotaUsageId); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| //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.SearchBuilder; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
| import org.apache.cloudstack.quota.vo.QuotaUsageDetailVO; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.cloud.utils.db.GenericDaoBase; | ||
| import com.cloud.utils.db.Transaction; | ||
| import com.cloud.utils.db.TransactionCallback; | ||
| import com.cloud.utils.db.TransactionLegacy; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| public class QuotaUsageDetailDaoImpl extends GenericDaoBase<QuotaUsageDetailVO, Long> implements QuotaUsageDetailDao { | ||
| private SearchBuilder<QuotaUsageDetailVO> searchQuotaUsageDetails; | ||
|
|
||
| @PostConstruct | ||
| public void init() { | ||
| searchQuotaUsageDetails = createSearchBuilder(); | ||
| searchQuotaUsageDetails.and("quotaUsageId", searchQuotaUsageDetails.entity().getQuotaUsageId(), SearchCriteria.Op.EQ); | ||
| searchQuotaUsageDetails.done(); | ||
| } | ||
|
Check warning on line 41 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java
|
||
|
|
||
| @Override | ||
| public void persistQuotaUsageDetail(final QuotaUsageDetailVO quotaUsageDetail) { | ||
| logger.trace("Persisting quota usage detail [{}].", quotaUsageDetail); | ||
| Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaUsageDetailVO>) status -> persist(quotaUsageDetail)); | ||
| } | ||
|
Check warning on line 47 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java
|
||
|
|
||
| @Override | ||
| public List<QuotaUsageDetailVO> listQuotaUsageDetails(Long quotaUsageId) { | ||
| SearchCriteria<QuotaUsageDetailVO> sc = searchQuotaUsageDetails.create(); | ||
| sc.setParameters("quotaUsageId", quotaUsageId); | ||
| return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<List<QuotaUsageDetailVO>>) status -> listBy(sc)); | ||
| } | ||
|
Check warning on line 54 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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.GenericDao; | ||
| import org.apache.cloudstack.quota.vo.QuotaUsageJoinVO; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| public interface QuotaUsageJoinDao extends GenericDao<QuotaUsageJoinVO, Long> { | ||
|
|
||
| List<QuotaUsageJoinVO> findQuotaUsage(Long accountId, Long domainId, Integer usageType, Long resourceId, Long networkId, Long offeringId, Date startDate, Date endDate, Long tariffId); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // 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.JoinBuilder; | ||
| import com.cloud.utils.db.SearchBuilder; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
| import com.cloud.utils.db.Transaction; | ||
| import com.cloud.utils.db.TransactionCallback; | ||
| import com.cloud.utils.db.TransactionLegacy; | ||
| import org.apache.cloudstack.quota.vo.QuotaUsageDetailVO; | ||
| import org.apache.cloudstack.quota.vo.QuotaUsageJoinVO; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
| import javax.inject.Inject; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| public class QuotaUsageJoinDaoImpl extends GenericDaoBase<QuotaUsageJoinVO, Long> implements QuotaUsageJoinDao { | ||
|
|
||
| private SearchBuilder<QuotaUsageJoinVO> searchQuotaUsages; | ||
|
|
||
| private SearchBuilder<QuotaUsageJoinVO> searchQuotaUsagesJoinDetails; | ||
|
|
||
| @Inject | ||
| private QuotaUsageDetailDao quotaUsageDetailDao; | ||
|
|
||
| @PostConstruct | ||
| public void init() { | ||
| searchQuotaUsages = createSearchBuilder(); | ||
| prepareQuotaUsageSearchBuilder(searchQuotaUsages); | ||
| searchQuotaUsages.done(); | ||
|
Check warning on line 51 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| SearchBuilder<QuotaUsageDetailVO> searchQuotaUsageDetails = quotaUsageDetailDao.createSearchBuilder(); | ||
| searchQuotaUsageDetails.and("tariffId", searchQuotaUsageDetails.entity().getTariffId(), SearchCriteria.Op.EQ); | ||
| searchQuotaUsagesJoinDetails = createSearchBuilder(); | ||
| prepareQuotaUsageSearchBuilder(searchQuotaUsagesJoinDetails); | ||
| searchQuotaUsagesJoinDetails.join("searchQuotaUsageDetails", searchQuotaUsageDetails, searchQuotaUsagesJoinDetails.entity().getId(), | ||
| searchQuotaUsageDetails.entity().getQuotaUsageId(), JoinBuilder.JoinType.INNER); | ||
| searchQuotaUsagesJoinDetails.done(); | ||
| } | ||
|
Check warning on line 60 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| private void prepareQuotaUsageSearchBuilder(SearchBuilder<QuotaUsageJoinVO> searchBuilder) { | ||
| searchBuilder.and("accountId", searchBuilder.entity().getAccountId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("domainId", searchBuilder.entity().getDomainId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("usageType", searchBuilder.entity().getUsageType(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("resourceId", searchBuilder.entity().getResourceId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("networkId", searchBuilder.entity().getNetworkId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("offeringId", searchBuilder.entity().getOfferingId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("startDate", searchBuilder.entity().getStartDate(), SearchCriteria.Op.BETWEEN); | ||
| searchBuilder.and("endDate", searchBuilder.entity().getEndDate(), SearchCriteria.Op.BETWEEN); | ||
| } | ||
|
Check warning on line 71 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| @Override | ||
| public List<QuotaUsageJoinVO> findQuotaUsage(Long accountId, Long domainId, Integer usageType, Long resourceId, Long networkId, Long offeringId, Date startDate, Date endDate, Long tariffId) { | ||
|
Check warning on line 74 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
| SearchCriteria<QuotaUsageJoinVO> sc = tariffId == null ? searchQuotaUsages.create() : searchQuotaUsagesJoinDetails.create(); | ||
|
|
||
| sc.setParametersIfNotNull("accountId", accountId); | ||
| sc.setParametersIfNotNull("domainId", domainId); | ||
| sc.setParametersIfNotNull("usageType", usageType); | ||
| sc.setParametersIfNotNull("resourceId", resourceId); | ||
| sc.setParametersIfNotNull("networkId", networkId); | ||
| sc.setParametersIfNotNull("offeringId", offeringId); | ||
|
Check warning on line 82 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| if (ObjectUtils.allNotNull(startDate, endDate)) { | ||
| sc.setParameters("startDate", startDate, endDate); | ||
| sc.setParameters("endDate", startDate, endDate); | ||
|
Check warning on line 86 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
| } | ||
|
|
||
| sc.setJoinParametersIfNotNull("searchQuotaUsageDetails", "tariffId", tariffId); | ||
|
Check warning on line 89 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<List<QuotaUsageJoinVO>>) status -> listBy(sc)); | ||
| } | ||
|
Check warning on line 92 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.vo; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.Table; | ||
| import org.apache.cloudstack.api.InternalIdentity; | ||
| import org.apache.commons.lang3.builder.ReflectionToStringBuilder; | ||
| import org.apache.commons.lang3.builder.ToStringStyle; | ||
|
|
||
| @Entity | ||
| @Table(name = "quota_usage_detail") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel table should be named differently as CLoudStack uses |
||
| public class QuotaUsageDetailVO implements InternalIdentity { | ||
| @Id | ||
| @Column(name = "id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "tariff_id") | ||
| private Long tariffId; | ||
|
|
||
| @Column(name = "quota_usage_id") | ||
| private Long quotaUsageId; | ||
|
|
||
| @Column(name = "quota_used") | ||
| private BigDecimal quotaUsed; | ||
|
|
||
| public QuotaUsageDetailVO() { | ||
| quotaUsed = new BigDecimal(0); | ||
| } | ||
|
Check warning on line 47 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| @Override | ||
| public long getId() { | ||
| return id; | ||
| } | ||
|
Check warning on line 52 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public Long getTariffId() { | ||
| return tariffId; | ||
| } | ||
|
Check warning on line 56 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public Long getQuotaUsageId() { | ||
| return quotaUsageId; | ||
| } | ||
|
Check warning on line 60 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public BigDecimal getQuotaUsed() { | ||
| return quotaUsed; | ||
| } | ||
|
Check warning on line 64 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
Check warning on line 68 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public void setTariffId(Long tariffId) { | ||
| this.tariffId = tariffId; | ||
| } | ||
|
Check warning on line 72 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public void setQuotaUsageId(Long quotaUsageId) { | ||
| this.quotaUsageId = quotaUsageId; | ||
| } | ||
|
Check warning on line 76 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| public void setQuotaUsed(BigDecimal quotaUsed) { | ||
| this.quotaUsed = quotaUsed; | ||
| } | ||
|
Check warning on line 80 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
|
|
||
| @Override | ||
| public String toString() { | ||
| return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).toString(); | ||
| } | ||
|
Check warning on line 85 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as
findAccountIncludingRemoved