Skip to content

Commit 01c721f

Browse files
Improvements to quota tariffs APIs and UI (#9225)
* reface quotaTariffList process and add listOnlyRemoved parameter * add unit tests for createQuotaTariffResponse and isUserAllowedToSeeActivationRules methods * update QuotaTariffListCmdTest * refactor quota tariffs creation * refactor quota tariffs update * fix unit test in JsInterpreter * remove unused import * refactor quota listing and add quota deletion * add functionality to create tariff from UI, not working when specifying dates * fix date parsing * add labels * fix details view of tariffs * new update tariff view * fix filter placeholder * remove debug html * add labels * make value field to be required when updating a tariff * add labels * add portuguese labels * remove unused label * fix updating tariff when there was no enddate specified * refactor dates * refactor dates * clear code * update disabled dates in date picker * clear ListView component * fix unnecessary updates when the new end date was equal to the exising end date * fix when today was selected to start date * add keyword to filter * change usage type response * add keyword and usagetype filter on UI * fix disabled end dates in date picker * modify datepickers to use datetime * small fixes * make value an unrequired field on update form * remove duplicate import * remove unused css classes * add UI support for position parameter * resize input fields to fill all available horizontal space * remove console.log() * remove unnecessary fully qualified names * replace `usagetypeid` property name to `id` on `listUsageTypes` API call * replace `usagetypeid` property name to `id` on `listUsageTypes` API call
1 parent 3399abd commit 01c721f

File tree

35 files changed

+1176
-312
lines changed

35 files changed

+1176
-312
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ public class ApiConstants {
696696
public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor";
697697
public static final String KEYWORD = "keyword";
698698
public static final String LIST_ALL = "listall";
699+
public static final String LIST_ONLY_REMOVED = "listonlyremoved";
699700
public static final String LIST_SYSTEM_VMS = "listsystemvms";
700701
public static final String IP_RANGES = "ipranges";
701702
public static final String IPV6_ROUTING = "ip6routing";
@@ -1141,6 +1142,11 @@ public class ApiConstants {
11411142

11421143
public static final String NFS_MOUNT_OPTIONS = "nfsmountopts";
11431144

1145+
public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
1146+
"a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " +
1147+
"numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " +
1148+
"value will be applied.";
1149+
11441150
/**
11451151
* This enum specifies IO Drivers, each option controls specific policies on I/O.
11461152
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).

api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.api.BaseCmd;
2424
import org.apache.cloudstack.api.response.ListResponse;
2525
import org.apache.cloudstack.api.response.UsageTypeResponse;
26+
import org.apache.cloudstack.usage.UsageTypes;
2627

2728
import com.cloud.user.Account;
2829

@@ -37,8 +38,8 @@ public long getEntityOwnerId() {
3738

3839
@Override
3940
public void execute() {
40-
List<UsageTypeResponse> result = _usageService.listUsageTypes();
41-
ListResponse<UsageTypeResponse> response = new ListResponse<UsageTypeResponse>();
41+
List<UsageTypeResponse> result = UsageTypes.listUsageTypes();
42+
ListResponse<UsageTypeResponse> response = new ListResponse<>();
4243
response.setResponses(result);
4344
response.setResponseName(getCommandName());
4445
this.setResponseObject(response);

api/src/main/java/org/apache/cloudstack/api/response/UsageTypeResponse.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525

2626
public class UsageTypeResponse extends BaseResponse {
2727

28-
@SerializedName("usagetypeid")
29-
@Param(description = "usage type")
28+
@SerializedName("id")
29+
@Param(description = "Usage type ID")
3030
private Integer usageType;
3131

32+
@SerializedName(ApiConstants.NAME)
33+
@Param(description = "Usage type name")
34+
private String name;
35+
3236
@SerializedName(ApiConstants.DESCRIPTION)
33-
@Param(description = "description of usage type")
37+
@Param(description = "Usage type description")
3438
private String description;
3539

3640
public String getDescription() {
@@ -49,10 +53,10 @@ public void setUsageType(Integer usageType) {
4953
this.usageType = usageType;
5054
}
5155

52-
public UsageTypeResponse(Integer usageType, String description) {
56+
public UsageTypeResponse(Integer usageType, String name, String description) {
5357
this.usageType = usageType;
58+
this.name = name;
5459
this.description = description;
5560
setObjectName("usagetype");
5661
}
57-
5862
}

api/src/main/java/org/apache/cloudstack/usage/UsageService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
2121
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
2222
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
23-
import org.apache.cloudstack.api.response.UsageTypeResponse;
2423

2524
import java.util.List;
2625
import java.util.TimeZone;
@@ -62,6 +61,4 @@ public interface UsageService {
6261
TimeZone getUsageTimezone();
6362

6463
boolean removeRawUsageRecords(RemoveRawUsageRecordsCmd cmd);
65-
66-
List<UsageTypeResponse> listUsageTypes();
6764
}

api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@ public class UsageTypes {
5151

5252
public static List<UsageTypeResponse> listUsageTypes() {
5353
List<UsageTypeResponse> responseList = new ArrayList<UsageTypeResponse>();
54-
responseList.add(new UsageTypeResponse(RUNNING_VM, "Running Vm Usage"));
55-
responseList.add(new UsageTypeResponse(ALLOCATED_VM, "Allocated Vm Usage"));
56-
responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP Address Usage"));
57-
responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "Network Usage (Bytes Sent)"));
58-
responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "Network Usage (Bytes Received)"));
59-
responseList.add(new UsageTypeResponse(VOLUME, "Volume Usage"));
60-
responseList.add(new UsageTypeResponse(TEMPLATE, "Template Usage"));
61-
responseList.add(new UsageTypeResponse(ISO, "ISO Usage"));
62-
responseList.add(new UsageTypeResponse(SNAPSHOT, "Snapshot Usage"));
63-
responseList.add(new UsageTypeResponse(SECURITY_GROUP, "Security Group Usage"));
64-
responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "Load Balancer Usage"));
65-
responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "Port Forwarding Usage"));
66-
responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "Network Offering Usage"));
67-
responseList.add(new UsageTypeResponse(VPN_USERS, "VPN users usage"));
68-
responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM Disk usage(I/O Read)"));
69-
responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM Disk usage(I/O Write)"));
70-
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM Disk usage(Bytes Read)"));
71-
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM Disk usage(Bytes Write)"));
72-
responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM Snapshot storage usage"));
73-
responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "Volume on secondary storage usage"));
74-
responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM Snapshot on primary storage usage"));
75-
responseList.add(new UsageTypeResponse(BACKUP, "Backup storage usage"));
76-
responseList.add(new UsageTypeResponse(BUCKET, "Bucket storage usage"));
77-
responseList.add(new UsageTypeResponse(NETWORK, "Network usage"));
78-
responseList.add(new UsageTypeResponse(VPC, "VPC usage"));
54+
responseList.add(new UsageTypeResponse(RUNNING_VM, "RUNNING_VM", "Running Vm Usage"));
55+
responseList.add(new UsageTypeResponse(ALLOCATED_VM, "ALLOCATED_VM", "Allocated Vm Usage"));
56+
responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP_ADDRESS", "IP Address Usage"));
57+
responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "NETWORK_BYTES_SENT", "Network Usage (Bytes Sent)"));
58+
responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "NETWORK_BYTES_RECEIVED", "Network Usage (Bytes Received)"));
59+
responseList.add(new UsageTypeResponse(VOLUME, "VOLUME", "Volume Usage"));
60+
responseList.add(new UsageTypeResponse(TEMPLATE, "TEMPLATE", "Template Usage"));
61+
responseList.add(new UsageTypeResponse(ISO, "ISO", "ISO Usage"));
62+
responseList.add(new UsageTypeResponse(SNAPSHOT, "SNAPSHOT", "Snapshot Usage"));
63+
responseList.add(new UsageTypeResponse(SECURITY_GROUP, "SECURITY_GROUP", "Security Group Usage"));
64+
responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "LOAD_BALANCER_POLICY", "Load Balancer Usage"));
65+
responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "PORT_FORWARDING_RULE", "Port Forwarding Usage"));
66+
responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "NETWORK_OFFERING", "Network Offering Usage"));
67+
responseList.add(new UsageTypeResponse(VPN_USERS, "VPN_USERS", "VPN users usage"));
68+
responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM_DISK_IO_READ", "VM Disk usage(I/O Read)"));
69+
responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM_DISK_IO_WRITE", "VM Disk usage(I/O Write)"));
70+
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM_DISK_BYTES_READ", "VM Disk usage(Bytes Read)"));
71+
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM_DISK_BYTES_WRITE", "VM Disk usage(Bytes Write)"));
72+
responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM_SNAPSHOT", "VM Snapshot storage usage"));
73+
responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "VOLUME_SECONDARY", "Volume on secondary storage usage"));
74+
responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM_SNAPSHOT_ON_PRIMARY", "VM Snapshot on primary storage usage"));
75+
responseList.add(new UsageTypeResponse(BACKUP, "BACKUP", "Backup storage usage"));
76+
responseList.add(new UsageTypeResponse(BUCKET, "BUCKET", "Bucket storage usage"));
77+
responseList.add(new UsageTypeResponse(NETWORK, "NETWORK", "Network usage"));
78+
responseList.add(new UsageTypeResponse(VPC, "VPC", "VPC usage"));
7979
return responseList;
8080
}
8181
}

framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,9 @@ public interface QuotaTariffDao extends GenericDao<QuotaTariffVO, Long> {
2828

2929
Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize);
3030

31-
QuotaTariffVO findByName(String name);
32-
33-
QuotaTariffVO findTariffPlanByUsageType(int quotaType, Date onOrBefore);
34-
35-
Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans();
31+
Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize, String keyword);
3632

37-
Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(final Long startIndex, final Long pageSize);
38-
39-
Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(Date onOrBefore);
40-
41-
Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(Date onOrBefore, Long startIndex, Long pageSize);
33+
QuotaTariffVO findByName(String name);
4234

4335
Boolean updateQuotaTariff(QuotaTariffVO plan);
4436

0 commit comments

Comments
 (0)