-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor Quota Summary API #10505
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
Open
julien-vaz
wants to merge
17
commits into
apache:main
Choose a base branch
from
scclouds:refactor-quota-summary-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor Quota Summary API #10505
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
115d303
Refactor Quota Summary API
36fe76e
Fixes imports
6897eeb
Fix QuotaServiceImplTest
87feb02
Update plugins/database/quota/src/main/java/org/apache/cloudstack/api…
julien-vaz 1dcfbbf
Fix QuotaSummaryCmd
6e7eeb5
Remove unnecessary imports
1cceb81
Remove unused createQuotaSummaryResponse declarations
e723223
Remove unnecessary imports
2800239
Update plugins/database/quota/src/main/java/org/apache/cloudstack/api…
julien-vaz 4d3ad22
Fix QuotaSummaryCmd
34fb78b
Fix QuotaResponseBuilderImplTest
b4db390
Refactor test
d9984c0
Fix QuotaSummaryCmd
8cdd7fd
Fix projectid behavior
37ebd68
Simplify QuotaSummary and deprecate listall
75e851e
Fix createQuotaSummaryResponse
ba99ec8
Remove unused import
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
48 changes: 48 additions & 0 deletions
48
engine/schema/src/main/resources/META-INF/db/views/cloud_usage.quota_summary_view.sql
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,48 @@ | ||
| -- 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. | ||
|
|
||
| -- cloud_usage.quota_summary_view source | ||
|
|
||
| -- Create view for quota summary | ||
| DROP VIEW IF EXISTS `cloud_usage`.`quota_summary_view`; | ||
| CREATE VIEW `cloud_usage`.`quota_summary_view` AS | ||
| SELECT | ||
| cloud_usage.quota_account.account_id AS account_id, | ||
| cloud_usage.quota_account.quota_balance AS quota_balance, | ||
| cloud_usage.quota_account.quota_balance_date AS quota_balance_date, | ||
| cloud_usage.quota_account.quota_enforce AS quota_enforce, | ||
| cloud_usage.quota_account.quota_min_balance AS quota_min_balance, | ||
| cloud_usage.quota_account.quota_alert_date AS quota_alert_date, | ||
| cloud_usage.quota_account.quota_alert_type AS quota_alert_type, | ||
| cloud_usage.quota_account.last_statement_date AS last_statement_date, | ||
| cloud.account.uuid AS account_uuid, | ||
| cloud.account.account_name AS account_name, | ||
| cloud.account.state AS account_state, | ||
| cloud.account.removed AS account_removed, | ||
| cloud.domain.id AS domain_id, | ||
| cloud.domain.uuid AS domain_uuid, | ||
| cloud.domain.name AS domain_name, | ||
| cloud.domain.path AS domain_path, | ||
| cloud.domain.removed AS domain_removed, | ||
| cloud.projects.uuid AS project_uuid, | ||
| cloud.projects.name AS project_name, | ||
| cloud.projects.removed AS project_removed | ||
| FROM | ||
| cloud_usage.quota_account | ||
| INNER JOIN cloud.account ON (cloud.account.id = cloud_usage.quota_account.account_id) | ||
| INNER JOIN cloud.domain ON (cloud.domain.id = cloud.account.domain_id) | ||
| LEFT JOIN cloud.projects ON (cloud.account.type = 5 AND cloud.account.id = cloud.projects.project_account_id); |
31 changes: 31 additions & 0 deletions
31
framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAccountStateFilter.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; | ||
|
|
||
| public enum QuotaAccountStateFilter { | ||
| ALL, ACTIVE, REMOVED; | ||
|
|
||
| public static QuotaAccountStateFilter getValue(String value) { | ||
| for (QuotaAccountStateFilter state : values()) { | ||
| if (state.name().equalsIgnoreCase(value)) { | ||
| return state; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
|
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. Possibly also add a |
||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDao.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,32 @@ | ||
| // 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.List; | ||
|
|
||
| import org.apache.cloudstack.quota.QuotaAccountStateFilter; | ||
| import org.apache.cloudstack.quota.vo.QuotaSummaryVO; | ||
|
|
||
| import com.cloud.utils.Pair; | ||
| import com.cloud.utils.db.GenericDao; | ||
|
|
||
| public interface QuotaSummaryDao extends GenericDao<QuotaSummaryVO, Long> { | ||
|
|
||
| Pair<List<QuotaSummaryVO>, Integer> listQuotaSummariesForAccountAndOrDomain(Long accountId, String accountName, Long domainId, String domainPath, | ||
| QuotaAccountStateFilter accountStateFilter, Long startIndex, Long pageSize); | ||
| } |
80 changes: 80 additions & 0 deletions
80
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.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,80 @@ | ||
| // 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.List; | ||
|
|
||
| import org.apache.cloudstack.quota.QuotaAccountStateFilter; | ||
| import org.apache.cloudstack.quota.vo.QuotaSummaryVO; | ||
|
|
||
| import com.cloud.utils.Pair; | ||
| import com.cloud.utils.db.Filter; | ||
| import com.cloud.utils.db.GenericDaoBase; | ||
| 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; | ||
|
|
||
| public class QuotaSummaryDaoImpl extends GenericDaoBase<QuotaSummaryVO, Long> implements QuotaSummaryDao { | ||
|
|
||
| @Override | ||
| public Pair<List<QuotaSummaryVO>, Integer> listQuotaSummariesForAccountAndOrDomain(Long accountId, String accountName, Long domainId, String domainPath, | ||
| QuotaAccountStateFilter accountStateFilter, Long startIndex, Long pageSize) { | ||
| SearchCriteria<QuotaSummaryVO> searchCriteria = createListQuotaSummariesSearchCriteria(accountId, accountName, domainId, domainPath, accountStateFilter); | ||
| Filter filter = new Filter(QuotaSummaryVO.class, "accountName", true, startIndex, pageSize); | ||
|
|
||
| return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<Pair<List<QuotaSummaryVO>, Integer>>) status -> searchAndCount(searchCriteria, filter)); | ||
| } | ||
|
|
||
| protected SearchCriteria<QuotaSummaryVO> createListQuotaSummariesSearchCriteria(Long accountId, String accountName, Long domainId, String domainPath, | ||
| QuotaAccountStateFilter accountStateFilter) { | ||
| SearchCriteria<QuotaSummaryVO> searchCriteria = createListQuotaSummariesSearchBuilder(accountStateFilter).create(); | ||
|
|
||
| searchCriteria.setParametersIfNotNull("accountId", accountId); | ||
| searchCriteria.setParametersIfNotNull("domainId", domainId); | ||
|
|
||
| if (accountName != null) { | ||
| searchCriteria.setParameters("accountName", "%" + accountName + "%"); | ||
| } | ||
|
|
||
| if (domainPath != null) { | ||
| searchCriteria.setParameters("domainPath", domainPath + "%"); | ||
| } | ||
|
|
||
| return searchCriteria; | ||
| } | ||
|
|
||
| protected SearchBuilder<QuotaSummaryVO> createListQuotaSummariesSearchBuilder(QuotaAccountStateFilter accountStateFilter) { | ||
| SearchBuilder<QuotaSummaryVO> searchBuilder = createSearchBuilder(); | ||
|
|
||
| searchBuilder.and("accountId", searchBuilder.entity().getAccountId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("accountName", searchBuilder.entity().getAccountName(), SearchCriteria.Op.LIKE); | ||
| searchBuilder.and("domainId", searchBuilder.entity().getDomainId(), SearchCriteria.Op.EQ); | ||
| searchBuilder.and("domainPath", searchBuilder.entity().getDomainPath(), SearchCriteria.Op.LIKE); | ||
|
|
||
| if (QuotaAccountStateFilter.REMOVED.equals(accountStateFilter)) { | ||
| searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NNULL); | ||
| } else if (QuotaAccountStateFilter.ACTIVE.equals(accountStateFilter)) { | ||
| searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NULL); | ||
| } | ||
|
|
||
| return searchBuilder; | ||
| } | ||
|
|
||
| } |
154 changes: 154 additions & 0 deletions
154
framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.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,154 @@ | ||
| // 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 java.util.Date; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.EnumType; | ||
| import javax.persistence.Enumerated; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.Table; | ||
| import javax.persistence.Temporal; | ||
| import javax.persistence.TemporalType; | ||
|
|
||
| import com.cloud.user.Account; | ||
|
|
||
| @Entity | ||
| @Table(name = "quota_summary_view") | ||
| public class QuotaSummaryVO { | ||
|
|
||
| @Id | ||
| @Column(name = "account_id") | ||
| private Long accountId = null; | ||
|
|
||
| @Column(name = "quota_enforce") | ||
| private Integer quotaEnforce = 0; | ||
|
|
||
| @Column(name = "quota_balance") | ||
| private BigDecimal quotaBalance; | ||
|
|
||
| @Column(name = "quota_balance_date") | ||
| @Temporal(value = TemporalType.TIMESTAMP) | ||
| private Date quotaBalanceDate = null; | ||
|
|
||
| @Column(name = "quota_min_balance") | ||
| private BigDecimal quotaMinBalance; | ||
|
|
||
| @Column(name = "quota_alert_type") | ||
| private Integer quotaAlertType = null; | ||
|
|
||
| @Column(name = "quota_alert_date") | ||
| @Temporal(value = TemporalType.TIMESTAMP) | ||
| private Date quotaAlertDate = null; | ||
|
|
||
| @Column(name = "last_statement_date") | ||
| @Temporal(value = TemporalType.TIMESTAMP) | ||
| private Date lastStatementDate = null; | ||
|
|
||
| @Column(name = "account_uuid") | ||
| private String accountUuid; | ||
|
|
||
| @Column(name = "account_name") | ||
| private String accountName; | ||
|
|
||
| @Column(name = "account_state") | ||
| @Enumerated(EnumType.STRING) | ||
| private Account.State accountState; | ||
|
|
||
| @Column(name = "account_removed") | ||
| private Date accountRemoved; | ||
|
|
||
| @Column(name = "domain_id") | ||
| private Long domainId; | ||
|
|
||
| @Column(name = "domain_uuid") | ||
| private String domainUuid; | ||
|
|
||
| @Column(name = "domain_name") | ||
| private String domainName; | ||
|
|
||
| @Column(name = "domain_path") | ||
| private String domainPath; | ||
|
|
||
| @Column(name = "domain_removed") | ||
| private Date domainRemoved; | ||
|
|
||
| @Column(name = "project_uuid") | ||
| private String projectUuid; | ||
|
|
||
| @Column(name = "project_name") | ||
| private String projectName; | ||
|
|
||
| @Column(name = "project_removed") | ||
| private Date projectRemoved; | ||
|
|
||
| public Long getAccountId() { | ||
| return accountId; | ||
| } | ||
|
|
||
| public BigDecimal getQuotaBalance() { | ||
| return quotaBalance; | ||
| } | ||
|
|
||
| public String getAccountUuid() { | ||
| return accountUuid; | ||
| } | ||
|
|
||
| public String getAccountName() { | ||
| return accountName; | ||
| } | ||
|
|
||
| public Date getAccountRemoved() { | ||
| return accountRemoved; | ||
| } | ||
|
|
||
| public Account.State getAccountState() { | ||
| return accountState; | ||
| } | ||
|
|
||
| public Long getDomainId() { | ||
| return domainId; | ||
| } | ||
|
|
||
| public String getDomainUuid() { | ||
| return domainUuid; | ||
| } | ||
|
|
||
| public String getDomainPath() { | ||
| return domainPath; | ||
| } | ||
|
|
||
| public Date getDomainRemoved() { | ||
| return domainRemoved; | ||
| } | ||
|
|
||
| public String getProjectUuid() { | ||
| return projectUuid; | ||
| } | ||
|
|
||
| public String getProjectName() { | ||
| return projectName; | ||
| } | ||
|
|
||
| public Date getProjectRemoved() { | ||
| return projectRemoved; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
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.
Sorry I'm not clear why should removed domains should be considered?