Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public class ApiConstants {
public static final String RECOVER = "recover";
public static final String REPAIR = "repair";
public static final String REQUIRES_HVM = "requireshvm";
public static final String RESOURCES = "resources";
public static final String RESOURCE_COUNT = "resourcecount";
public static final String RESOURCE_NAME = "resourcename";
public static final String RESOURCE_TYPE = "resourcetype";
Expand Down Expand Up @@ -460,6 +461,7 @@ public class ApiConstants {
public static final String SESSIONKEY = "sessionkey";
public static final String SHOW_CAPACITIES = "showcapacities";
public static final String SHOW_REMOVED = "showremoved";
public static final String SHOW_RESOURCES = "showresources";
public static final String SHOW_RESOURCE_ICON = "showicon";
public static final String SHOW_INACTIVE = "showinactive";
public static final String SHOW_UNIQUE = "showunique";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface AccountDao extends GenericDao<AccountVO, Long> {

List<AccountVO> listAccounts(String accountName, Long domainId, Filter filter);

AccountVO findAccountByNameAndDomainIncludingRemoved(String accountName, Long domainId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as findAccountIncludingRemoved


List<AccountVO> findCleanupsForDisabledAccounts();

//return account only in enabled state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@
return listBy(sc);
}

@Override
public AccountVO findAccountByNameAndDomainIncludingRemoved(String accountName, Long domainId) {
SearchCriteria<AccountVO> sc = AllFieldsSearch.create("accountName", accountName);
sc.setParameters("domainId", domainId);
return findOneIncludingRemovedBy(sc);
}

Check warning on line 312 in engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java#L308-L312

Added lines #L308 - L312 were not covered by tests

@Override
public void markForCleanup(long accountId) {
AccountVO account = findByIdIncludingRemoved(accountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@

}

public void setJoinParametersIfNotNull(String joinName, String conditionName, Object... params) {

Check warning on line 203 in framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java#L203

Added line #L203 was not covered by tests
if (ArrayUtils.isNotEmpty(params) && (params.length > 1 || params[0] != null)) {
setJoinParameters(joinName, conditionName, params);

Check warning on line 205 in framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java#L205

Added line #L205 was not covered by tests
}
}

Check warning on line 207 in framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java#L207

Added line #L207 was not covered by tests

public SearchCriteria<?> getJoin(String joinName) {
return _joins.get(joinName).getT();
}
Expand Down
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);

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

Check warning on line 41 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java#L37-L41

Added lines #L37 - L41 were not covered by tests

@Override
public void persistQuotaUsageDetail(final QuotaUsageDetailVO quotaUsageDetail) {
logger.trace("Persisting quota usage detail [{}].", quotaUsageDetail);
Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaUsageDetailVO>) status -> persist(quotaUsageDetail));
}

Check warning on line 47 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java#L44-L47

Added lines #L44 - L47 were not covered by tests

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

Check warning on line 54 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java#L50-L54

Added lines #L50 - L54 were not covered by tests

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

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

Check warning on line 51 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L48-L51

Added lines #L48 - L51 were not covered by tests

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

Check warning on line 60 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L53-L60

Added lines #L53 - L60 were not covered by tests

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

Check warning on line 71 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L62-L71

Added lines #L62 - L71 were not covered by tests

@Override
public List<QuotaUsageJoinVO> findQuotaUsage(Long accountId, Long domainId, Integer usageType, Long resourceId, Long networkId, Long offeringId, Date startDate, Date endDate, Long tariffId) {

Check warning on line 74 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L74

Added line #L74 was not covered by tests
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);

Check warning on line 82 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L77-L82

Added lines #L77 - L82 were not covered by tests

if (ObjectUtils.allNotNull(startDate, endDate)) {
sc.setParameters("startDate", startDate, endDate);
sc.setParameters("endDate", startDate, endDate);

Check warning on line 86 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L85-L86

Added lines #L85 - L86 were not covered by tests
}

sc.setJoinParametersIfNotNull("searchQuotaUsageDetails", "tariffId", tariffId);

Check warning on line 89 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L89

Added line #L89 was not covered by tests

return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<List<QuotaUsageJoinVO>>) status -> listBy(sc));
}

Check warning on line 92 in framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java#L91-L92

Added lines #L91 - L92 were not covered by tests

}
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel table should be named differently as CLoudStack uses *_detail table for the details of the entity mostly in the similar format resource_id,name,value

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

Check warning on line 47 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L45-L47

Added lines #L45 - L47 were not covered by tests

@Override
public long getId() {
return id;
}

Check warning on line 52 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L50-L52

Added lines #L50 - L52 were not covered by tests

public Long getTariffId() {
return tariffId;
}

Check warning on line 56 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L54-L56

Added lines #L54 - L56 were not covered by tests

public Long getQuotaUsageId() {
return quotaUsageId;
}

Check warning on line 60 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L58-L60

Added lines #L58 - L60 were not covered by tests

public BigDecimal getQuotaUsed() {
return quotaUsed;
}

Check warning on line 64 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L62-L64

Added lines #L62 - L64 were not covered by tests

public void setId(Long id) {
this.id = id;
}

Check warning on line 68 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L66-L68

Added lines #L66 - L68 were not covered by tests

public void setTariffId(Long tariffId) {
this.tariffId = tariffId;
}

Check warning on line 72 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L70-L72

Added lines #L70 - L72 were not covered by tests

public void setQuotaUsageId(Long quotaUsageId) {
this.quotaUsageId = quotaUsageId;
}

Check warning on line 76 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L74-L76

Added lines #L74 - L76 were not covered by tests

public void setQuotaUsed(BigDecimal quotaUsed) {
this.quotaUsed = quotaUsed;
}

Check warning on line 80 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L78-L80

Added lines #L78 - L80 were not covered by tests

@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).toString();
}

Check warning on line 85 in framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java#L83-L85

Added lines #L83 - L85 were not covered by tests
}
Loading
Loading