Search in sources :

Example 11 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, final BigDecimal aggregationRatio) {
    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().multiply(aggregationRatio);
        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)

Example 12 with QuotaTariffVO

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

the class QuotaManagerImpl method updateQuotaRunningVMUsage.

public List<QuotaUsageVO> updateQuotaRunningVMUsage(UsageVO usageRecord, final BigDecimal aggregationRatio) {
    List<QuotaUsageVO> quotalist = new ArrayList<QuotaUsageVO>();
    QuotaUsageVO quota_usage;
    BigDecimal cpuquotausgage, speedquotausage, memoryquotausage, vmusage;
    BigDecimal onehourcostpercpu, onehourcostper100mhz, onehourcostper1mb, onehourcostforvmusage;
    BigDecimal rawusage;
    // get service offering details
    ServiceOfferingVO serviceoffering = _serviceOfferingDao.findServiceOffering(usageRecord.getVmInstanceId(), usageRecord.getOfferingId());
    if (serviceoffering == null)
        return quotalist;
    rawusage = new BigDecimal(usageRecord.getRawUsage());
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(QuotaTypes.CPU_NUMBER, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0 && serviceoffering.getCpu() != null) {
        BigDecimal cpu = new BigDecimal(serviceoffering.getCpu());
        onehourcostpercpu = tariff.getCurrencyValue().multiply(aggregationRatio);
        cpuquotausgage = rawusage.multiply(onehourcostpercpu).multiply(cpu);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), QuotaTypes.CPU_NUMBER, cpuquotausgage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
        quotalist.add(quota_usage);
    }
    tariff = _quotaTariffDao.findTariffPlanByUsageType(QuotaTypes.CPU_CLOCK_RATE, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0 && serviceoffering.getSpeed() != null) {
        BigDecimal speed = new BigDecimal(serviceoffering.getSpeed() / 100.00);
        onehourcostper100mhz = tariff.getCurrencyValue().multiply(aggregationRatio);
        speedquotausage = rawusage.multiply(onehourcostper100mhz).multiply(speed);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), QuotaTypes.CPU_CLOCK_RATE, speedquotausage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
        quotalist.add(quota_usage);
    }
    tariff = _quotaTariffDao.findTariffPlanByUsageType(QuotaTypes.MEMORY, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0 && serviceoffering.getRamSize() != null) {
        BigDecimal memory = new BigDecimal(serviceoffering.getRamSize());
        onehourcostper1mb = tariff.getCurrencyValue().multiply(aggregationRatio);
        memoryquotausage = rawusage.multiply(onehourcostper1mb).multiply(memory);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), QuotaTypes.MEMORY, memoryquotausage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
        quotalist.add(quota_usage);
    }
    tariff = _quotaTariffDao.findTariffPlanByUsageType(QuotaTypes.RUNNING_VM, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        onehourcostforvmusage = tariff.getCurrencyValue().multiply(aggregationRatio);
        vmusage = rawusage.multiply(onehourcostforvmusage);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), QuotaTypes.RUNNING_VM, vmusage, usageRecord.getStartDate(), usageRecord.getEndDate());
        _quotaUsageDao.persistQuotaUsage(quota_usage);
        quotalist.add(quota_usage);
    }
    usageRecord.setQuotaCalculated(1);
    _usageDao.persistUsage(usageRecord);
    return quotalist;
}
Also used : QuotaTariffVO(org.apache.cloudstack.quota.vo.QuotaTariffVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(org.apache.cloudstack.quota.vo.ServiceOfferingVO) BigDecimal(java.math.BigDecimal) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO)

Example 13 with QuotaTariffVO

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

the class QuotaManagerImpl method updateQuotaRaw.

public QuotaUsageVO updateQuotaRaw(UsageVO usageRecord, final BigDecimal aggregationRatio, final int ruleType) {
    QuotaUsageVO quota_usage = null;
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(ruleType, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        BigDecimal ruleusage;
        BigDecimal onehourcost;
        onehourcost = tariff.getCurrencyValue().multiply(aggregationRatio);
        ruleusage = new BigDecimal(usageRecord.getRawUsage()).multiply(onehourcost);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), ruleType, ruleusage, 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 14 with QuotaTariffVO

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

the class QuotaManagerImpl method updateQuotaNetwork.

public QuotaUsageVO updateQuotaNetwork(UsageVO usageRecord, final int transferType) {
    QuotaUsageVO quota_usage = null;
    QuotaTariffVO tariff = _quotaTariffDao.findTariffPlanByUsageType(transferType, usageRecord.getEndDate());
    if (tariff != null && tariff.getCurrencyValue().compareTo(BigDecimal.ZERO) != 0) {
        BigDecimal onegbcost;
        BigDecimal rawusageingb;
        BigDecimal networkusage;
        onegbcost = tariff.getCurrencyValue();
        rawusageingb = new BigDecimal(usageRecord.getRawUsage()).divide(s_gb, 8, RoundingMode.HALF_EVEN);
        networkusage = rawusageingb.multiply(onegbcost);
        quota_usage = new QuotaUsageVO(usageRecord.getId(), usageRecord.getZoneId(), usageRecord.getAccountId(), usageRecord.getDomainId(), transferType, networkusage, 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)14 BigDecimal (java.math.BigDecimal)9 Date (java.util.Date)6 QuotaUsageVO (org.apache.cloudstack.quota.vo.QuotaUsageVO)6 ArrayList (java.util.ArrayList)4 QuotaTariffResponse (org.apache.cloudstack.api.response.QuotaTariffResponse)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)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 ServiceOfferingVO (org.apache.cloudstack.quota.vo.ServiceOfferingVO)1