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