-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Hervot de Mattos Vaz
committed
Mar 4, 2025
1 parent
69cf299
commit 9617344
Showing
22 changed files
with
993 additions
and
164 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
29 changes: 29 additions & 0 deletions
29
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDao.java
This file contains 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,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); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDetailDaoImpl.java
This file contains 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,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(); | ||
} | ||
|
||
@Override | ||
public void persistQuotaUsageDetail(final QuotaUsageDetailVO quotaUsageDetail) { | ||
logger.trace("Persisting quota usage detail [{}].", quotaUsageDetail); | ||
Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaUsageDetailVO>) status -> persist(quotaUsageDetail)); | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDao.java
This file contains 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.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); | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageJoinDaoImpl.java
This file contains 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,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(); | ||
|
||
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(); | ||
} | ||
|
||
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); | ||
} | ||
|
||
@Override | ||
public List<QuotaUsageJoinVO> findQuotaUsage(Long accountId, Long domainId, Integer usageType, Long resourceId, Long networkId, Long offeringId, Date startDate, Date endDate, Long tariffId) { | ||
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); | ||
|
||
if (ObjectUtils.allNotNull(startDate, endDate)) { | ||
sc.setParameters("startDate", startDate, endDate); | ||
sc.setParameters("endDate", startDate, endDate); | ||
} | ||
|
||
sc.setJoinParametersIfNotNull("searchQuotaUsageDetails", "tariffId", tariffId); | ||
|
||
return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<List<QuotaUsageJoinVO>>) status -> listBy(sc)); | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaUsageDetailVO.java
This file contains 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,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") | ||
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); | ||
} | ||
|
||
@Override | ||
public long getId() { | ||
return id; | ||
} | ||
|
||
public Long getTariffId() { | ||
return tariffId; | ||
} | ||
|
||
public Long getQuotaUsageId() { | ||
return quotaUsageId; | ||
} | ||
|
||
public BigDecimal getQuotaUsed() { | ||
return quotaUsed; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public void setTariffId(Long tariffId) { | ||
this.tariffId = tariffId; | ||
} | ||
|
||
public void setQuotaUsageId(Long quotaUsageId) { | ||
this.quotaUsageId = quotaUsageId; | ||
} | ||
|
||
public void setQuotaUsed(BigDecimal quotaUsed) { | ||
this.quotaUsed = quotaUsed; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).toString(); | ||
} | ||
} |
Oops, something went wrong.