Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
115d303
Refactor Quota Summary API
Feb 28, 2025
36fe76e
Fixes imports
Mar 6, 2025
6897eeb
Fix QuotaServiceImplTest
Mar 11, 2025
87feb02
Update plugins/database/quota/src/main/java/org/apache/cloudstack/api…
julien-vaz Apr 9, 2025
1dcfbbf
Fix QuotaSummaryCmd
Jun 4, 2025
6e7eeb5
Remove unnecessary imports
Jun 9, 2025
1cceb81
Remove unused createQuotaSummaryResponse declarations
Jul 1, 2025
e723223
Remove unnecessary imports
Jul 2, 2025
2800239
Update plugins/database/quota/src/main/java/org/apache/cloudstack/api…
julien-vaz Jul 8, 2025
4d3ad22
Fix QuotaSummaryCmd
Jul 10, 2025
34fb78b
Fix QuotaResponseBuilderImplTest
Jul 11, 2025
b4db390
Refactor test
Jul 11, 2025
d9984c0
Fix QuotaSummaryCmd
Aug 7, 2025
8cdd7fd
Fix projectid behavior
Aug 8, 2025
37ebd68
Simplify QuotaSummary and deprecate listall
Aug 18, 2025
75e851e
Fix createQuotaSummaryResponse
Aug 28, 2025
ba99ec8
Remove unused import
Sep 2, 2025
589a07e
Merge remote-tracking branch 'upstream/main' into refactor-quota-summ…
winterhazel Feb 3, 2026
fc92e39
Apply suggestions + some adjustments
winterhazel Feb 3, 2026
b532758
Remove duplicated check
winterhazel Feb 3, 2026
c90b609
Fix checkstyle
winterhazel Feb 3, 2026
a146047
Adjust entity owner
winterhazel Feb 4, 2026
592f1cb
Remove unused method + fix tests
winterhazel Feb 11, 2026
e4ee69e
Add missing @ACL to some parameters
winterhazel Feb 19, 2026
5bdac75
Adjust how the parameters behave
winterhazel Feb 20, 2026
67d4d0b
Merge remote-tracking branch 'upstream/main' into refactor-quota-summ…
winterhazel Mar 1, 2026
90180dd
Allow domain admins and users to use keyword
winterhazel Mar 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/user/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ User createUser(String userName, String password, String firstName, String lastN

Long finalizeAccountId(String accountName, Long domainId, Long projectId, boolean enabledOnly);

Long finalizeAccountId(Long accountId, String accountName, Long domainId, Long projectId);

/**
* returns the user account object for a given user id
* @param userId user id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class ApiConstants {
public static final String ACCOUNT = "account";
public static final String ACCOUNTS = "accounts";
public static final String ACCOUNT_STATE_TO_SHOW = "accountstatetoshow";
public static final String ACCOUNT_TYPE = "accounttype";
public static final String ACCOUNT_ID = "accountid";
public static final String ACCOUNT_IDS = "accountids";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public boolean isChildDomain(Long parentId, Long childId) {
SearchCriteria<DomainVO> sc = DomainPairSearch.create();
sc.setParameters("id", parentId, childId);

List<DomainVO> domainPair = listBy(sc);
List<DomainVO> domainPair = listIncludingRemovedBy(sc);

if ((domainPair != null) && (domainPair.size() == 2)) {
DomainVO d1 = domainPair.get(0);
Expand Down
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,35 @@
// 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;

import org.apache.commons.lang3.StringUtils;

public enum QuotaAccountStateFilter {
ALL, ACTIVE, REMOVED;

public static QuotaAccountStateFilter getValue(String value) {
if (StringUtils.isBlank(value)) {
return null;
}
for (QuotaAccountStateFilter state : values()) {
if (state.name().equalsIgnoreCase(value)) {
return state;
}
}
return null;
}
}
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);

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;
}

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

<bean id="presetVariableHelper" class="org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableHelper" />
<bean id="QuotaTariffDao" class="org.apache.cloudstack.quota.dao.QuotaTariffDaoImpl" />
<bean id="QuotaAccountDao" class="org.apache.cloudstack.quota.dao.QuotaAccountDaoImpl" />
<bean id="QuotaSummaryDao" class="org.apache.cloudstack.quota.dao.QuotaSummaryDaoImpl" />
<bean id="QuotaAccountDao" class="org.apache.cloudstack.quota.dao.QuotaAccountDaoImpl" />
<bean id="QuotaBalanceDao" class="org.apache.cloudstack.quota.dao.QuotaBalanceDaoImpl" />
<bean id="QuotaCreditsDao" class="org.apache.cloudstack.quota.dao.QuotaCreditsDaoImpl" />
<bean id="QuotaEmailTemplatesDao"
Expand Down
Loading
Loading