Skip to content

Commit

Permalink
Improvements to quota tariffs APIs and UI (#9225)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bernardodemarco authored Aug 15, 2024
1 parent 3399abd commit 01c721f
Show file tree
Hide file tree
Showing 35 changed files with 1,176 additions and 312 deletions.
6 changes: 6 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ public class ApiConstants {
public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor";
public static final String KEYWORD = "keyword";
public static final String LIST_ALL = "listall";
public static final String LIST_ONLY_REMOVED = "listonlyremoved";
public static final String LIST_SYSTEM_VMS = "listsystemvms";
public static final String IP_RANGES = "ipranges";
public static final String IPV6_ROUTING = "ip6routing";
Expand Down Expand Up @@ -1141,6 +1142,11 @@ public class ApiConstants {

public static final String NFS_MOUNT_OPTIONS = "nfsmountopts";

public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
"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 " +
"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 " +
"value will be applied.";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UsageTypeResponse;
import org.apache.cloudstack.usage.UsageTypes;

import com.cloud.user.Account;

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

@Override
public void execute() {
List<UsageTypeResponse> result = _usageService.listUsageTypes();
ListResponse<UsageTypeResponse> response = new ListResponse<UsageTypeResponse>();
List<UsageTypeResponse> result = UsageTypes.listUsageTypes();
ListResponse<UsageTypeResponse> response = new ListResponse<>();
response.setResponses(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

public class UsageTypeResponse extends BaseResponse {

@SerializedName("usagetypeid")
@Param(description = "usage type")
@SerializedName("id")
@Param(description = "Usage type ID")
private Integer usageType;

@SerializedName(ApiConstants.NAME)
@Param(description = "Usage type name")
private String name;

@SerializedName(ApiConstants.DESCRIPTION)
@Param(description = "description of usage type")
@Param(description = "Usage type description")
private String description;

public String getDescription() {
Expand All @@ -49,10 +53,10 @@ public void setUsageType(Integer usageType) {
this.usageType = usageType;
}

public UsageTypeResponse(Integer usageType, String description) {
public UsageTypeResponse(Integer usageType, String name, String description) {
this.usageType = usageType;
this.name = name;
this.description = description;
setObjectName("usagetype");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
import org.apache.cloudstack.api.response.UsageTypeResponse;

import java.util.List;
import java.util.TimeZone;
Expand Down Expand Up @@ -62,6 +61,4 @@ public interface UsageService {
TimeZone getUsageTimezone();

boolean removeRawUsageRecords(RemoveRawUsageRecordsCmd cmd);

List<UsageTypeResponse> listUsageTypes();
}
50 changes: 25 additions & 25 deletions api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@ public class UsageTypes {

public static List<UsageTypeResponse> listUsageTypes() {
List<UsageTypeResponse> responseList = new ArrayList<UsageTypeResponse>();
responseList.add(new UsageTypeResponse(RUNNING_VM, "Running Vm Usage"));
responseList.add(new UsageTypeResponse(ALLOCATED_VM, "Allocated Vm Usage"));
responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP Address Usage"));
responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "Network Usage (Bytes Sent)"));
responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "Network Usage (Bytes Received)"));
responseList.add(new UsageTypeResponse(VOLUME, "Volume Usage"));
responseList.add(new UsageTypeResponse(TEMPLATE, "Template Usage"));
responseList.add(new UsageTypeResponse(ISO, "ISO Usage"));
responseList.add(new UsageTypeResponse(SNAPSHOT, "Snapshot Usage"));
responseList.add(new UsageTypeResponse(SECURITY_GROUP, "Security Group Usage"));
responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "Load Balancer Usage"));
responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "Port Forwarding Usage"));
responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "Network Offering Usage"));
responseList.add(new UsageTypeResponse(VPN_USERS, "VPN users usage"));
responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM Disk usage(I/O Read)"));
responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM Disk usage(I/O Write)"));
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM Disk usage(Bytes Read)"));
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM Disk usage(Bytes Write)"));
responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM Snapshot storage usage"));
responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "Volume on secondary storage usage"));
responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM Snapshot on primary storage usage"));
responseList.add(new UsageTypeResponse(BACKUP, "Backup storage usage"));
responseList.add(new UsageTypeResponse(BUCKET, "Bucket storage usage"));
responseList.add(new UsageTypeResponse(NETWORK, "Network usage"));
responseList.add(new UsageTypeResponse(VPC, "VPC usage"));
responseList.add(new UsageTypeResponse(RUNNING_VM, "RUNNING_VM", "Running Vm Usage"));
responseList.add(new UsageTypeResponse(ALLOCATED_VM, "ALLOCATED_VM", "Allocated Vm Usage"));
responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP_ADDRESS", "IP Address Usage"));
responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "NETWORK_BYTES_SENT", "Network Usage (Bytes Sent)"));
responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "NETWORK_BYTES_RECEIVED", "Network Usage (Bytes Received)"));
responseList.add(new UsageTypeResponse(VOLUME, "VOLUME", "Volume Usage"));
responseList.add(new UsageTypeResponse(TEMPLATE, "TEMPLATE", "Template Usage"));
responseList.add(new UsageTypeResponse(ISO, "ISO", "ISO Usage"));
responseList.add(new UsageTypeResponse(SNAPSHOT, "SNAPSHOT", "Snapshot Usage"));
responseList.add(new UsageTypeResponse(SECURITY_GROUP, "SECURITY_GROUP", "Security Group Usage"));
responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "LOAD_BALANCER_POLICY", "Load Balancer Usage"));
responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "PORT_FORWARDING_RULE", "Port Forwarding Usage"));
responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "NETWORK_OFFERING", "Network Offering Usage"));
responseList.add(new UsageTypeResponse(VPN_USERS, "VPN_USERS", "VPN users usage"));
responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM_DISK_IO_READ", "VM Disk usage(I/O Read)"));
responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM_DISK_IO_WRITE", "VM Disk usage(I/O Write)"));
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM_DISK_BYTES_READ", "VM Disk usage(Bytes Read)"));
responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM_DISK_BYTES_WRITE", "VM Disk usage(Bytes Write)"));
responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM_SNAPSHOT", "VM Snapshot storage usage"));
responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "VOLUME_SECONDARY", "Volume on secondary storage usage"));
responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM_SNAPSHOT_ON_PRIMARY", "VM Snapshot on primary storage usage"));
responseList.add(new UsageTypeResponse(BACKUP, "BACKUP", "Backup storage usage"));
responseList.add(new UsageTypeResponse(BUCKET, "BUCKET", "Bucket storage usage"));
responseList.add(new UsageTypeResponse(NETWORK, "NETWORK", "Network usage"));
responseList.add(new UsageTypeResponse(VPC, "VPC", "VPC usage"));
return responseList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@ public interface QuotaTariffDao extends GenericDao<QuotaTariffVO, Long> {

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

QuotaTariffVO findByName(String name);

QuotaTariffVO findTariffPlanByUsageType(int quotaType, Date onOrBefore);

Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans();
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);

Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(final Long startIndex, final Long pageSize);

Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(Date onOrBefore);

Pair<List<QuotaTariffVO>, Integer> listAllTariffPlans(Date onOrBefore, Long startIndex, Long pageSize);
QuotaTariffVO findByName(String name);

Boolean updateQuotaTariff(QuotaTariffVO plan);

Expand Down
Loading

0 comments on commit 01c721f

Please sign in to comment.