Skip to content

Commit 115d303

Browse files
author
Julien Hervot de Mattos Vaz
committed
Refactor Quota Summary API
1 parent 3a28a87 commit 115d303

File tree

16 files changed

+888
-157
lines changed

16 files changed

+888
-157
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
public class ApiConstants {
2020
public static final String ACCOUNT = "account";
2121
public static final String ACCOUNTS = "accounts";
22+
public static final String ACCOUNT_STATE_TO_SHOW = "accountstatetoshow";
2223
public static final String ACCOUNT_TYPE = "accounttype";
2324
public static final String ACCOUNT_ID = "accountid";
2425
public static final String ACCOUNT_IDS = "accountids";

engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public boolean isChildDomain(Long parentId, Long childId) {
262262
SearchCriteria<DomainVO> sc = DomainPairSearch.create();
263263
sc.setParameters("id", parentId, childId);
264264

265-
List<DomainVO> domainPair = listBy(sc);
265+
List<DomainVO> domainPair = listIncludingRemovedBy(sc);
266266

267267
if ((domainPair != null) && (domainPair.size() == 2)) {
268268
DomainVO d1 = domainPair.get(0);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- cloud_usage.quota_summary_view source
19+
20+
-- Create view for quota summary
21+
DROP VIEW IF EXISTS `cloud_usage`.`quota_summary_view`;
22+
CREATE VIEW `cloud_usage`.`quota_summary_view` AS
23+
SELECT
24+
cloud_usage.quota_account.account_id AS account_id,
25+
cloud_usage.quota_account.quota_balance AS quota_balance,
26+
cloud_usage.quota_account.quota_balance_date AS quota_balance_date,
27+
cloud_usage.quota_account.quota_enforce AS quota_enforce,
28+
cloud_usage.quota_account.quota_min_balance AS quota_min_balance,
29+
cloud_usage.quota_account.quota_alert_date AS quota_alert_date,
30+
cloud_usage.quota_account.quota_alert_type AS quota_alert_type,
31+
cloud_usage.quota_account.last_statement_date AS last_statement_date,
32+
cloud.account.uuid AS account_uuid,
33+
cloud.account.account_name AS account_name,
34+
cloud.account.state AS account_state,
35+
cloud.account.removed AS account_removed,
36+
cloud.domain.id AS domain_id,
37+
cloud.domain.uuid AS domain_uuid,
38+
cloud.domain.name AS domain_name,
39+
cloud.domain.path AS domain_path,
40+
cloud.domain.removed AS domain_removed,
41+
cloud.projects.uuid AS project_uuid,
42+
cloud.projects.name AS project_name,
43+
cloud.projects.removed AS project_removed
44+
FROM
45+
cloud_usage.quota_account
46+
INNER JOIN cloud.account ON (cloud.account.id = cloud_usage.quota_account.account_id)
47+
INNER JOIN cloud.domain ON (cloud.domain.id = cloud.account.domain_id)
48+
LEFT JOIN cloud.projects ON (cloud.account.type = 5 AND cloud.account.id = cloud.projects.project_account_id);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.quota;
18+
19+
public enum QuotaAccountStateFilter {
20+
ALL, ACTIVE, REMOVED;
21+
22+
public static QuotaAccountStateFilter getValue(String value) {
23+
for (QuotaAccountStateFilter state : values()) {
24+
if (state.name().equalsIgnoreCase(value)) {
25+
return state;
26+
}
27+
}
28+
29+
return null;
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.quota.dao;
19+
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.quota.QuotaAccountStateFilter;
23+
import org.apache.cloudstack.quota.vo.QuotaSummaryVO;
24+
25+
import com.cloud.utils.Pair;
26+
import com.cloud.utils.db.GenericDao;
27+
28+
public interface QuotaSummaryDao extends GenericDao<QuotaSummaryVO, Long> {
29+
30+
Pair<List<QuotaSummaryVO>, Integer> listQuotaSummariesForAccountAndOrDomain(Long accountId, String accountName, Long domainId, String domainPath,
31+
QuotaAccountStateFilter accountStateFilter, Long startIndex, Long pageSize);
32+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.quota.dao;
19+
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.quota.QuotaAccountStateFilter;
23+
import org.apache.cloudstack.quota.vo.QuotaSummaryVO;
24+
25+
import com.cloud.utils.Pair;
26+
import com.cloud.utils.db.Filter;
27+
import com.cloud.utils.db.GenericDaoBase;
28+
import com.cloud.utils.db.SearchBuilder;
29+
import com.cloud.utils.db.SearchCriteria;
30+
import com.cloud.utils.db.Transaction;
31+
import com.cloud.utils.db.TransactionCallback;
32+
import com.cloud.utils.db.TransactionLegacy;
33+
34+
public class QuotaSummaryDaoImpl extends GenericDaoBase<QuotaSummaryVO, Long> implements QuotaSummaryDao {
35+
36+
@Override
37+
public Pair<List<QuotaSummaryVO>, Integer> listQuotaSummariesForAccountAndOrDomain(Long accountId, String accountName, Long domainId, String domainPath,
38+
QuotaAccountStateFilter accountStateFilter, Long startIndex, Long pageSize) {
39+
SearchCriteria<QuotaSummaryVO> searchCriteria = createListQuotaSummariesSearchCriteria(accountId, accountName, domainId, domainPath, accountStateFilter);
40+
Filter filter = new Filter(QuotaSummaryVO.class, "accountName", true, startIndex, pageSize);
41+
42+
return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<Pair<List<QuotaSummaryVO>, Integer>>) status -> searchAndCount(searchCriteria, filter));
43+
}
44+
45+
protected SearchCriteria<QuotaSummaryVO> createListQuotaSummariesSearchCriteria(Long accountId, String accountName, Long domainId, String domainPath,
46+
QuotaAccountStateFilter accountStateFilter) {
47+
SearchCriteria<QuotaSummaryVO> searchCriteria = createListQuotaSummariesSearchBuilder(accountStateFilter).create();
48+
49+
searchCriteria.setParametersIfNotNull("accountId", accountId);
50+
searchCriteria.setParametersIfNotNull("domainId", domainId);
51+
52+
if (accountName != null) {
53+
searchCriteria.setParameters("accountName", "%" + accountName + "%");
54+
}
55+
56+
if (domainPath != null) {
57+
searchCriteria.setParameters("domainPath", domainPath + "%");
58+
}
59+
60+
return searchCriteria;
61+
}
62+
63+
protected SearchBuilder<QuotaSummaryVO> createListQuotaSummariesSearchBuilder(QuotaAccountStateFilter accountStateFilter) {
64+
SearchBuilder<QuotaSummaryVO> searchBuilder = createSearchBuilder();
65+
66+
searchBuilder.and("accountId", searchBuilder.entity().getAccountId(), SearchCriteria.Op.EQ);
67+
searchBuilder.and("accountName", searchBuilder.entity().getAccountName(), SearchCriteria.Op.LIKE);
68+
searchBuilder.and("domainId", searchBuilder.entity().getDomainId(), SearchCriteria.Op.EQ);
69+
searchBuilder.and("domainPath", searchBuilder.entity().getDomainPath(), SearchCriteria.Op.LIKE);
70+
71+
if (QuotaAccountStateFilter.REMOVED.equals(accountStateFilter)) {
72+
searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NNULL);
73+
} else if (QuotaAccountStateFilter.ACTIVE.equals(accountStateFilter)) {
74+
searchBuilder.and("accountRemoved", searchBuilder.entity().getAccountRemoved(), SearchCriteria.Op.NULL);
75+
}
76+
77+
return searchBuilder;
78+
}
79+
80+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.quota.vo;
19+
20+
import java.math.BigDecimal;
21+
import java.util.Date;
22+
23+
import javax.persistence.Column;
24+
import javax.persistence.Entity;
25+
import javax.persistence.EnumType;
26+
import javax.persistence.Enumerated;
27+
import javax.persistence.Id;
28+
import javax.persistence.Table;
29+
import javax.persistence.Temporal;
30+
import javax.persistence.TemporalType;
31+
32+
import com.cloud.user.Account;
33+
34+
@Entity
35+
@Table(name = "quota_summary_view")
36+
public class QuotaSummaryVO {
37+
38+
@Id
39+
@Column(name = "account_id")
40+
private Long accountId = null;
41+
42+
@Column(name = "quota_enforce")
43+
private Integer quotaEnforce = 0;
44+
45+
@Column(name = "quota_balance")
46+
private BigDecimal quotaBalance;
47+
48+
@Column(name = "quota_balance_date")
49+
@Temporal(value = TemporalType.TIMESTAMP)
50+
private Date quotaBalanceDate = null;
51+
52+
@Column(name = "quota_min_balance")
53+
private BigDecimal quotaMinBalance;
54+
55+
@Column(name = "quota_alert_type")
56+
private Integer quotaAlertType = null;
57+
58+
@Column(name = "quota_alert_date")
59+
@Temporal(value = TemporalType.TIMESTAMP)
60+
private Date quotaAlertDate = null;
61+
62+
@Column(name = "last_statement_date")
63+
@Temporal(value = TemporalType.TIMESTAMP)
64+
private Date lastStatementDate = null;
65+
66+
@Column(name = "account_uuid")
67+
private String accountUuid;
68+
69+
@Column(name = "account_name")
70+
private String accountName;
71+
72+
@Column(name = "account_state")
73+
@Enumerated(EnumType.STRING)
74+
private Account.State accountState;
75+
76+
@Column(name = "account_removed")
77+
private Date accountRemoved;
78+
79+
@Column(name = "domain_id")
80+
private Long domainId;
81+
82+
@Column(name = "domain_uuid")
83+
private String domainUuid;
84+
85+
@Column(name = "domain_name")
86+
private String domainName;
87+
88+
@Column(name = "domain_path")
89+
private String domainPath;
90+
91+
@Column(name = "domain_removed")
92+
private Date domainRemoved;
93+
94+
@Column(name = "project_uuid")
95+
private String projectUuid;
96+
97+
@Column(name = "project_name")
98+
private String projectName;
99+
100+
@Column(name = "project_removed")
101+
private Date projectRemoved;
102+
103+
public Long getAccountId() {
104+
return accountId;
105+
}
106+
107+
public BigDecimal getQuotaBalance() {
108+
return quotaBalance;
109+
}
110+
111+
public String getAccountUuid() {
112+
return accountUuid;
113+
}
114+
115+
public String getAccountName() {
116+
return accountName;
117+
}
118+
119+
public Date getAccountRemoved() {
120+
return accountRemoved;
121+
}
122+
123+
public Account.State getAccountState() {
124+
return accountState;
125+
}
126+
127+
public Long getDomainId() {
128+
return domainId;
129+
}
130+
131+
public String getDomainUuid() {
132+
return domainUuid;
133+
}
134+
135+
public String getDomainPath() {
136+
return domainPath;
137+
}
138+
139+
public Date getDomainRemoved() {
140+
return domainRemoved;
141+
}
142+
143+
public String getProjectUuid() {
144+
return projectUuid;
145+
}
146+
147+
public String getProjectName() {
148+
return projectName;
149+
}
150+
151+
public Date getProjectRemoved() {
152+
return projectRemoved;
153+
}
154+
}

framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
<bean id="presetVariableHelper" class="org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableHelper" />
2121
<bean id="QuotaTariffDao" class="org.apache.cloudstack.quota.dao.QuotaTariffDaoImpl" />
22-
<bean id="QuotaAccountDao" class="org.apache.cloudstack.quota.dao.QuotaAccountDaoImpl" />
22+
<bean id="QuotaSummaryDao" class="org.apache.cloudstack.quota.dao.QuotaSummaryDaoImpl" />
23+
<bean id="QuotaAccountDao" class="org.apache.cloudstack.quota.dao.QuotaAccountDaoImpl" />
2324
<bean id="QuotaBalanceDao" class="org.apache.cloudstack.quota.dao.QuotaBalanceDaoImpl" />
2425
<bean id="QuotaCreditsDao" class="org.apache.cloudstack.quota.dao.QuotaCreditsDaoImpl" />
2526
<bean id="QuotaEmailTemplatesDao"

0 commit comments

Comments
 (0)