-
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
base: main
Are you sure you want to change the base?
Refactor Quota Summary API #10505
Changes from 3 commits
115d303
36fe76e
6897eeb
87feb02
1dcfbbf
6e7eeb5
1cceb81
e723223
2800239
4d3ad22
34fb78b
b4db390
d9984c0
8cdd7fd
37ebd68
75e851e
ba99ec8
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,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); |
| 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; | ||
|
Check warning on line 20 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAccountStateFilter.java
|
||
|
|
||
| public static QuotaAccountStateFilter getValue(String value) { | ||
|
Check warning on line 22 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAccountStateFilter.java
|
||
| for (QuotaAccountStateFilter state : values()) { | ||
| if (state.name().equalsIgnoreCase(value)) { | ||
| return state; | ||
|
Check warning on line 25 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAccountStateFilter.java
|
||
| } | ||
| } | ||
|
|
||
| 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 |
||
| } | ||
|
Check warning on line 30 in framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAccountStateFilter.java
|
||
| } | ||
| 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); | ||
| } |
| 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); | ||
|
Check warning on line 40 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<Pair<List<QuotaSummaryVO>, Integer>>) status -> searchAndCount(searchCriteria, filter)); | ||
| } | ||
|
Check warning on line 43 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| protected SearchCriteria<QuotaSummaryVO> createListQuotaSummariesSearchCriteria(Long accountId, String accountName, Long domainId, String domainPath, | ||
| QuotaAccountStateFilter accountStateFilter) { | ||
| SearchCriteria<QuotaSummaryVO> searchCriteria = createListQuotaSummariesSearchBuilder(accountStateFilter).create(); | ||
|
Check warning on line 47 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| searchCriteria.setParametersIfNotNull("accountId", accountId); | ||
| searchCriteria.setParametersIfNotNull("domainId", domainId); | ||
|
Check warning on line 50 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| if (accountName != null) { | ||
| searchCriteria.setParameters("accountName", "%" + accountName + "%"); | ||
|
Check warning on line 53 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
| } | ||
|
|
||
| if (domainPath != null) { | ||
| searchCriteria.setParameters("domainPath", domainPath + "%"); | ||
|
Check warning on line 57 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
| } | ||
|
|
||
| return searchCriteria; | ||
| } | ||
|
Check warning on line 61 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| protected SearchBuilder<QuotaSummaryVO> createListQuotaSummariesSearchBuilder(QuotaAccountStateFilter accountStateFilter) { | ||
| SearchBuilder<QuotaSummaryVO> searchBuilder = createSearchBuilder(); | ||
|
Check warning on line 64 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| 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); | ||
|
Check warning on line 69 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| if (QuotaAccountStateFilter.REMOVED.equals(accountStateFilter)) { | ||
| searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NNULL); | ||
|
Check warning on line 72 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
| } else if (QuotaAccountStateFilter.ACTIVE.equals(accountStateFilter)) { | ||
| searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NULL); | ||
|
Check warning on line 74 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
| } | ||
|
|
||
| return searchBuilder; | ||
| } | ||
|
Check warning on line 78 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaSummaryDaoImpl.java
|
||
|
|
||
| } | ||
| 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; | ||
|
Check warning on line 43 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| @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; | ||
| } | ||
|
Check warning on line 105 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public BigDecimal getQuotaBalance() { | ||
| return quotaBalance; | ||
| } | ||
|
Check warning on line 109 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getAccountUuid() { | ||
| return accountUuid; | ||
| } | ||
|
Check warning on line 113 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getAccountName() { | ||
| return accountName; | ||
| } | ||
|
Check warning on line 117 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public Date getAccountRemoved() { | ||
| return accountRemoved; | ||
| } | ||
|
Check warning on line 121 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public Account.State getAccountState() { | ||
| return accountState; | ||
| } | ||
|
Check warning on line 125 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public Long getDomainId() { | ||
| return domainId; | ||
| } | ||
|
Check warning on line 129 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getDomainUuid() { | ||
| return domainUuid; | ||
| } | ||
|
Check warning on line 133 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getDomainPath() { | ||
| return domainPath; | ||
| } | ||
|
Check warning on line 137 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public Date getDomainRemoved() { | ||
| return domainRemoved; | ||
| } | ||
|
Check warning on line 141 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getProjectUuid() { | ||
| return projectUuid; | ||
| } | ||
|
Check warning on line 145 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public String getProjectName() { | ||
| return projectName; | ||
| } | ||
|
Check warning on line 149 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.java
|
||
|
|
||
| public Date getProjectRemoved() { | ||
| return projectRemoved; | ||
| } | ||
|
Check warning on line 153 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaSummaryVO.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.
Sorry I'm not clear why should removed domains should be considered?