use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaManagerImplTest method testUpdateQuotaRecords.
@Test
public void testUpdateQuotaRecords() {
UsageVO usageVO = new UsageVO();
usageVO.setId(100L);
usageVO.setQuotaCalculated(0);
usageVO.setUsageType(UsageTypes.NETWORK_BYTES_SENT);
usageVO.setRawUsage(9000000000.0);
usageVO.setSize(1010101010L);
QuotaTariffVO tariffVO = new QuotaTariffVO();
tariffVO.setCurrencyValue(new BigDecimal(1));
Mockito.when(quotaTariffDao.findTariffPlanByUsageType(Mockito.anyInt(), Mockito.any(Date.class))).thenReturn(tariffVO);
QuotaUsageVO qu = quotaManager.updateQuotaNetwork(usageVO, UsageTypes.NETWORK_BYTES_SENT);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaAllocatedVMUsage(usageVO, new BigDecimal(0.5));
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaDiskUsage(usageVO, new BigDecimal(0.5), UsageTypes.VOLUME);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaRaw(usageVO, new BigDecimal(0.5), UsageTypes.VPN_USERS);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
Mockito.verify(quotaUsageDao, Mockito.times(4)).persistQuotaUsage(Mockito.any(QuotaUsageVO.class));
Mockito.verify(usageDao, Mockito.times(4)).persistUsage(Mockito.any(UsageVO.class));
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaResponseBuilderImpl method updateQuotaTariffPlan.
@Override
public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
final int quotaType = cmd.getUsageType();
final BigDecimal quotaCost = new BigDecimal(cmd.getValue());
final Date effectiveDate = _quotaService.computeAdjustedTime(cmd.getStartDate());
final Date now = _quotaService.computeAdjustedTime(new Date());
// if effective date is in the past return error
if (effectiveDate.compareTo(now) < 0) {
throw new InvalidParameterValueException("Incorrect effective date for tariff " + effectiveDate + " is less than now " + now);
}
QuotaTypes quotaConstant = QuotaTypes.listQuotaTypes().get(quotaType);
if (quotaConstant == null) {
throw new InvalidParameterValueException("Quota type does not exists " + quotaType);
}
QuotaTariffVO result = null;
result = new QuotaTariffVO(quotaType);
result.setUsageName(quotaConstant.getQuotaName());
result.setUsageUnit(quotaConstant.getQuotaUnit());
result.setUsageDiscriminator(quotaConstant.getDiscriminator());
result.setCurrencyValue(quotaCost);
result.setEffectiveOn(effectiveDate);
result.setUpdatedOn(now);
result.setUpdatedBy(cmd.getEntityOwnerId());
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Updating Quota Tariff Plan: New value=%s for resource type=%d effective on date=%s", quotaCost, quotaType, effectiveDate));
}
_quotaTariffDao.addQuotaTariff(result);
return result;
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaResponseBuilderImpl method listQuotaTariffPlans.
@Override
public List<QuotaTariffVO> listQuotaTariffPlans(final QuotaTariffListCmd cmd) {
List<QuotaTariffVO> result = new ArrayList<QuotaTariffVO>();
Date effectiveDate = cmd.getEffectiveDate() == null ? new Date() : cmd.getEffectiveDate();
Date adjustedEffectiveDate = _quotaService.computeAdjustedTime(effectiveDate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Effective datec=" + effectiveDate + " quotatype=" + cmd.getUsageType() + " Adjusted date=" + adjustedEffectiveDate);
}
if (cmd.getUsageType() != null) {
QuotaTariffVO tariffPlan = _quotaTariffDao.findTariffPlanByUsageType(cmd.getUsageType(), adjustedEffectiveDate);
if (tariffPlan != null) {
result.add(tariffPlan);
}
} else {
result = _quotaTariffDao.listAllTariffPlans(adjustedEffectiveDate);
}
return result;
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaTariffUpdateCmdTest method testQuotaTariffUpdateCmd.
@Test
public void testQuotaTariffUpdateCmd() throws NoSuchFieldException, IllegalAccessException {
QuotaTariffUpdateCmd cmd = new QuotaTariffUpdateCmd();
Field rbField = QuotaTariffUpdateCmd.class.getDeclaredField("_responseBuilder");
rbField.setAccessible(true);
rbField.set(cmd, responseBuilder);
QuotaTariffVO tariff = new QuotaTariffVO();
tariff.setEffectiveOn(new Date());
tariff.setCurrencyValue(new BigDecimal(100));
tariff.setUsageType(QuotaTypes.MEMORY);
Mockito.when(responseBuilder.updateQuotaTariffPlan(Mockito.eq(cmd))).thenReturn(null);
try {
cmd.execute();
} catch (ServerApiException e) {
assertTrue(e.getErrorCode().equals(ApiErrorCode.INTERNAL_ERROR));
}
Mockito.when(responseBuilder.updateQuotaTariffPlan(Mockito.eq(cmd))).thenReturn(tariff);
Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.eq(tariff))).thenReturn(new QuotaTariffResponse());
cmd.execute();
Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.eq(tariff));
}
use of org.apache.cloudstack.quota.vo.QuotaTariffVO in project cloudstack by apache.
the class QuotaResponseBuilderImplTest method makeTariffTestData.
private QuotaTariffVO makeTariffTestData() {
QuotaTariffVO tariffVO = new QuotaTariffVO();
tariffVO.setUsageType(QuotaTypes.IP_ADDRESS);
tariffVO.setUsageName("ip address");
tariffVO.setUsageUnit("IP-Month");
tariffVO.setCurrencyValue(BigDecimal.valueOf(100.19));
tariffVO.setEffectiveOn(new Date());
tariffVO.setUsageDiscriminator("");
return tariffVO;
}
Aggregations