Search in sources :

Example 1 with QuotaTariffVO

use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.

the class QuotaManagerImpl method updateQuotaDiskUsage.

public QuotaUsageVO updateQuotaDiskUsage(UsageVO usageRecord, final BigDecimal aggregationRatio, final int quotaType) {
    QuotaUsageVO quota_usage = null;
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(quotaType, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        BigDecimal quotaUsgage;
        BigDecimal onehourcostpergb;
        BigDecimal noofgbinuse;
        onehourcostpergb = tariff.getCurrencyValue().multiply(aggregationRatio);
        noofgbinuse = new BigDecimal(usageRecord.getSize()).divide(s_gb, 8, RoundingMode.HALF_EVEN);
        quotaUsgage = new BigDecimal(usageRecord.getRawUsage()).multiply(onehourcostpergb).multiply(noofgbinuse);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), usageRecord.getUsageType(), quotaUsgage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
    }
    usageRecord.setQuotaCalculated(1);
    _usageDao.persistUsage(usageRecord);
    return quota_usage;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) BigDecimal(java.math.BigDecimal) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO)

Example 2 with QuotaTariffVO

use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.

the class QuotaTariffListCmdTest method testQuotaTariffListCmd.

@Test
public void testQuotaTariffListCmd() throws NoSuchFieldException, IllegalAccessException {
    QuotaTariffListCmd cmd = new QuotaTariffListCmd();
    Field rbField = QuotaTariffListCmd.class.getDeclaredField("_responseBuilder");
    rbField.setAccessible(true);
    rbField.set(cmd, responseBuilder);
    List<QuotaTariffVO> quotaTariffVOList = new ArrayList<QuotaTariffVO>();
    QuotaTariffVO tariff = new QuotaTariffVO();
    tariff.setEffectiveOn(new Date());
    tariff.setCurrencyValue(new BigDecimal(100));
    tariff.setUsageType(QuotaTypes.MEMORY);
    quotaTariffVOList.add(new QuotaTariffVO());
    Mockito.when(responseBuilder.listQuotaTariffPlans(Mockito.eq(cmd))).thenReturn(new Pair<>(quotaTariffVOList, quotaTariffVOList.size()));
    Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class))).thenReturn(new QuotaTariffResponse());
    cmd.execute();
    Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class));
}
Also used : Field(java.lang.reflect.Field) QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) ArrayList(java.util.ArrayList) QuotaTariffResponse(org.apache.cloudstack.api.response.QuotaTariffResponse) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with QuotaTariffVO

use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.

the class QuotaResponseBuilderImplTest method testQuotaResponse.

@Test
public void testQuotaResponse() {
    QuotaTariffVO tariffVO = makeTariffTestData();
    QuotaTariffResponse response = quotaResponseBuilder.createQuotaTariffResponse(tariffVO);
    assertTrue(tariffVO.getUsageType() == response.getUsageType());
    assertTrue(tariffVO.getCurrencyValue().equals(response.getTariffValue()));
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) Test(org.junit.Test)

Example 4 with QuotaTariffVO

use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.

the class QuotaManagerImpl method updateQuotaDiskUsage.

public QuotaUsageVO updateQuotaDiskUsage(UsageVO usageRecord, final int quotaType) {
    QuotaUsageVO quota_usage = null;
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(quotaType, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        BigDecimal quotaUsgage;
        BigDecimal onehourcostpergb;
        BigDecimal noofgbinuse;
        onehourcostpergb = tariff.getCurrencyValue().divide(s_hoursInMonth, 8, RoundingMode.HALF_DOWN);
        noofgbinuse = new BigDecimal(usageRecord.getSize()).divide(s_gb, 8, RoundingMode.HALF_EVEN);
        quotaUsgage = new BigDecimal(usageRecord.getRawUsage()).multiply(onehourcostpergb).multiply(noofgbinuse);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), usageRecord.getUsageType(), quotaUsgage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
    }
    usageRecord.setQuotaCalculated(1);
    _usageDao.persistUsage(usageRecord);
    return quota_usage;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) BigDecimal(java.math.BigDecimal) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO)

Example 5 with QuotaTariffVO

use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.

the class QuotaManagerImpl method updateQuotaAllocatedVMUsage.

public QuotaUsageVO updateQuotaAllocatedVMUsage(UsageVO usageRecord) {
    QuotaUsageVO quota_usage = null;
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(QuotaTypes.ALLOCATED_VM, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        BigDecimal vmusage;
        BigDecimal onehourcostforvmusage;
        onehourcostforvmusage = tariff.getCurrencyValue().divide(s_hoursInMonth, 8, RoundingMode.HALF_DOWN);
        vmusage = new BigDecimal(usageRecord.getRawUsage()).multiply(onehourcostforvmusage);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), QuotaTypes.ALLOCATED_VM, vmusage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
    }
    usageRecord.setQuotaCalculated(1);
    _usageDao.persistUsage(usageRecord);
    return quota_usage;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) BigDecimal(java.math.BigDecimal) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO)

Aggregations

QuotaTariffVO (org.apache.cloudstack.quota.vo.QuotaTariffVO)18 BigDecimal (java.math.BigDecimal)13 QuotaUsageVO (org.apache.cloudstack.quota.vo.QuotaUsageVO)10 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 QuotaTariffResponse (org.apache.cloudstack.api.response.QuotaTariffResponse)4 Test (org.junit.Test)4 LocalDate (java.time.LocalDate)3 Field (java.lang.reflect.Field)2 List (java.util.List)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 ServiceOfferingVO (org.apache.cloudstack.quota.vo.ServiceOfferingVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 UsageVO (com.cloud.usage.UsageVO)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 QuotaTypes (org.apache.cloudstack.quota.constant.QuotaTypes)1