-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Merged
Merged
Improve Quota Statement #10506
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9617344
Improve Quota Statement
e702bb3
Removes unused import
0a996dc
Fix QuotaUsageJoinDao, QuotaResponseBuilderImpl, QuotaServiceImpl e Q…
7d06715
Reorganize imports
58c0b5c
Updates QuotaStatementCmd responseBuilder scope to default
412a4bd
Fix log4j syntax
bb32371
Address reviews + other improvements
winterhazel f5c8d84
Merge remote-tracking branch 'upstream/main' into improve-quota-state…
winterhazel d05ab01
Add missing SQL scripts and injections
winterhazel fdeb202
Change accountid and domainid logic + add unit tests
winterhazel ce5d96a
Merge remote-tracking branch 'upstream/main' into improve-quota-state…
winterhazel 31966d7
Rename QuotaUsageDetail to QuotaTariffUsage
winterhazel 1f39686
Fix out of bounds exception
winterhazel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDao.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| } |
56 changes: 56 additions & 0 deletions
56
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| @Override | ||
| public void persistQuotaUsageDetail(final QuotaUsageDetailVO quotaUsageDetail) { | ||
| logger.trace("Persisting quota usage detail [{}].", quotaUsageDetail); | ||
| Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaUsageDetailVO>) status -> persist(quotaUsageDetail)); | ||
| } | ||
|
|
||
| @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)); | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDao.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| } |
94 changes: 94 additions & 0 deletions
94
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
|
||
| 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(); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| @Override | ||
| public List<QuotaUsageJoinVO> findQuotaUsage(Long accountId, Long domainId, Integer usageType, Long resourceId, Long networkId, Long offeringId, Date startDate, Date endDate, Long tariffId) { | ||
| 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); | ||
|
|
||
| if (ObjectUtils.allNotNull(startDate, endDate)) { | ||
| sc.setParameters("startDate", startDate, endDate); | ||
| sc.setParameters("endDate", startDate, endDate); | ||
| } | ||
|
|
||
| sc.setJoinParametersIfNotNull("searchQuotaUsageDetails", "tariffId", tariffId); | ||
|
|
||
| return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<List<QuotaUsageJoinVO>>) status -> listBy(sc)); | ||
| } | ||
|
|
||
| } |
86 changes: 86 additions & 0 deletions
86
framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
|
winterhazel marked this conversation as resolved.
Outdated
|
||
| 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); | ||
| } | ||
|
|
||
| @Override | ||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Long getTariffId() { | ||
| return tariffId; | ||
| } | ||
|
|
||
| public Long getQuotaUsageId() { | ||
| return quotaUsageId; | ||
| } | ||
|
|
||
| public BigDecimal getQuotaUsed() { | ||
| return quotaUsed; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public void setTariffId(Long tariffId) { | ||
| this.tariffId = tariffId; | ||
| } | ||
|
|
||
| public void setQuotaUsageId(Long quotaUsageId) { | ||
| this.quotaUsageId = quotaUsageId; | ||
| } | ||
|
|
||
| public void setQuotaUsed(BigDecimal quotaUsed) { | ||
| this.quotaUsed = quotaUsed; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).toString(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.