mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Quota VM_DISK tariff calculation (#7152)
Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
This commit is contained in:
parent
62e342c1bc
commit
5c20e7844c
@ -22,7 +22,9 @@ public enum UsageUnitTypes {
|
||||
IP_MONTH ("IP*Month"),
|
||||
GB ("GB"),
|
||||
GB_MONTH ("GB*Month"),
|
||||
POLICY_MONTH ("Policy*Month");
|
||||
POLICY_MONTH ("Policy*Month"),
|
||||
IOPS ("IOPS"),
|
||||
BYTES ("Bytes");
|
||||
|
||||
private final String description;
|
||||
|
||||
|
||||
@ -1493,3 +1493,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`console_session` (
|
||||
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`) VALUES (UUID(), 2, 'assignVolume', 'ALLOW');
|
||||
INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`) VALUES (UUID(), 3, 'assignVolume', 'ALLOW');
|
||||
|
||||
|
||||
-- Increases the precision of the column `quota_used` from 15 to 20, keeping the scale of 8.
|
||||
|
||||
ALTER TABLE `cloud_usage`.`quota_usage` MODIFY COLUMN quota_used decimal(20,8) unsigned NOT NULL;
|
||||
|
||||
@ -45,7 +45,6 @@ import org.apache.cloudstack.quota.vo.QuotaAccountVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
|
||||
import org.apache.cloudstack.quota.vo.QuotaUsageVO;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.apache.cloudstack.usage.UsageUnitTypes;
|
||||
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
|
||||
import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter;
|
||||
@ -95,9 +94,6 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
||||
static final BigDecimal GiB_DECIMAL = BigDecimal.valueOf(ByteScaleUtils.GiB);
|
||||
List<Account.Type> lockablesAccountTypes = Arrays.asList(Account.Type.NORMAL, Account.Type.DOMAIN_ADMIN);
|
||||
|
||||
List<Integer> usageTypesToAvoidCalculation = Arrays.asList(UsageTypes.VM_DISK_IO_READ, UsageTypes.VM_DISK_IO_WRITE, UsageTypes.VM_DISK_BYTES_READ,
|
||||
UsageTypes.VM_DISK_BYTES_WRITE);
|
||||
|
||||
public QuotaManagerImpl() {
|
||||
super();
|
||||
}
|
||||
@ -344,12 +340,6 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
||||
}
|
||||
|
||||
protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageRecord) {
|
||||
if (usageTypesToAvoidCalculation.contains(usageRecord.getUsageType())) {
|
||||
s_logger.debug(String.format("Considering usage record [%s] as calculated and skipping it because the calculation of the types [%s] has not been implemented yet.",
|
||||
usageRecord, usageTypesToAvoidCalculation));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId()))) {
|
||||
s_logger.debug(String.format("Considering usage record [%s] as calculated and skipping it because account [%s] has the quota plugin disabled.",
|
||||
usageRecord, accountVO.reflectionToString()));
|
||||
@ -559,6 +549,10 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
||||
BigDecimal gbInUse = BigDecimal.valueOf(usageRecord.getSize()).divide(GiB_DECIMAL, 8, RoundingMode.HALF_EVEN);
|
||||
return rawUsage.multiply(costPerHour).multiply(gbInUse);
|
||||
|
||||
case BYTES:
|
||||
case IOPS:
|
||||
return rawUsage.multiply(aggregatedQuotaTariffsValue);
|
||||
|
||||
default:
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
@ -47,10 +47,10 @@ public class QuotaTypes extends UsageTypes {
|
||||
quotaTypeList.put(PORT_FORWARDING_RULE, new QuotaTypes(PORT_FORWARDING_RULE, "PORT_FORWARDING_RULE", UsageUnitTypes.POLICY_MONTH.toString(), "Port Forwarding Usage"));
|
||||
quotaTypeList.put(NETWORK_OFFERING, new QuotaTypes(NETWORK_OFFERING, "NETWORK_OFFERING", UsageUnitTypes.POLICY_MONTH.toString(), "Network Offering Usage"));
|
||||
quotaTypeList.put(VPN_USERS, new QuotaTypes(VPN_USERS, "VPN_USERS", UsageUnitTypes.POLICY_MONTH.toString(), "VPN users usage"));
|
||||
quotaTypeList.put(VM_DISK_IO_READ, new QuotaTypes(VM_DISK_IO_READ, "VM_DISK_IO_READ", UsageUnitTypes.GB.toString(), "VM Disk usage(I/O Read)"));
|
||||
quotaTypeList.put(VM_DISK_IO_WRITE, new QuotaTypes(VM_DISK_IO_WRITE, "VM_DISK_IO_WRITE", UsageUnitTypes.GB.toString(), "VM Disk usage(I/O Write)"));
|
||||
quotaTypeList.put(VM_DISK_BYTES_READ, new QuotaTypes(VM_DISK_BYTES_READ, "VM_DISK_BYTES_READ", UsageUnitTypes.GB.toString(), "VM Disk usage(Bytes Read)"));
|
||||
quotaTypeList.put(VM_DISK_BYTES_WRITE, new QuotaTypes(VM_DISK_BYTES_WRITE, "VM_DISK_BYTES_WRITE", UsageUnitTypes.GB.toString(), "VM Disk usage(Bytes Write)"));
|
||||
quotaTypeList.put(VM_DISK_IO_READ, new QuotaTypes(VM_DISK_IO_READ, "VM_DISK_IO_READ", UsageUnitTypes.IOPS.toString(), "VM Disk usage(I/O Read)"));
|
||||
quotaTypeList.put(VM_DISK_IO_WRITE, new QuotaTypes(VM_DISK_IO_WRITE, "VM_DISK_IO_WRITE", UsageUnitTypes.IOPS.toString(), "VM Disk usage(I/O Write)"));
|
||||
quotaTypeList.put(VM_DISK_BYTES_READ, new QuotaTypes(VM_DISK_BYTES_READ, "VM_DISK_BYTES_READ", UsageUnitTypes.BYTES.toString(), "VM Disk usage(Bytes Read)"));
|
||||
quotaTypeList.put(VM_DISK_BYTES_WRITE, new QuotaTypes(VM_DISK_BYTES_WRITE, "VM_DISK_BYTES_WRITE", UsageUnitTypes.BYTES.toString(), "VM Disk usage(Bytes Write)"));
|
||||
quotaTypeList.put(VM_SNAPSHOT, new QuotaTypes(VM_SNAPSHOT, "VM_SNAPSHOT", UsageUnitTypes.GB_MONTH.toString(), "VM Snapshot storage usage"));
|
||||
quotaTypeList.put(VOLUME_SECONDARY, new QuotaTypes(VOLUME_SECONDARY, "VOLUME_SECONDARY", UsageUnitTypes.GB_MONTH.toString(), "Volume secondary storage usage"));
|
||||
quotaTypeList.put(VM_SNAPSHOT_ON_PRIMARY, new QuotaTypes(VM_SNAPSHOT_ON_PRIMARY, "VM_SNAPSHOT_ON_PRIMARY", UsageUnitTypes.GB_MONTH.toString(), "VM Snapshot primary storage usage"));
|
||||
|
||||
@ -166,6 +166,12 @@ public class QuotaManagerImplTest {
|
||||
expected = 5.5555556;
|
||||
break;
|
||||
|
||||
case BYTES:
|
||||
case IOPS:
|
||||
//The value 4000.0 is referent to the calculation ( raw usage * tariffs values ).
|
||||
expected = 4000.0;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user