Skip to content
8 changes: 8 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 @@ -1141,6 +1141,14 @@ public String toString() {
}
}

public static final String PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS = "The recommended format is \"yyyy-MM-dd'T'HH:mm:ssZ\" (e.g.: \"2023-01-01T12:00:00+0100\"); " +
"however, the following formats are also accepted: \"yyyy-MM-dd HH:mm:ss\" (e.g.: \"2023-01-01 12:00:00\") and \"yyyy-MM-dd\" (e.g.: \"2023-01-01\" - if the time is not " +
"added, it will be interpreted as \"00:00:00\"). If the recommended format is not used, the date will be considered in the server timezone.";

public static final String PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS = "The recommended format is \"yyyy-MM-dd'T'HH:mm:ssZ\" (e.g.: \"2023-01-01T12:00:00+0100\"); " +
"however, the following formats are also accepted: \"yyyy-MM-dd HH:mm:ss\" (e.g.: \"2023-01-01 12:00:00\") and \"yyyy-MM-dd\" (e.g.: \"2023-01-01\" - if the time is not " +
"added, it will be interpreted as \"23:59:59\"). If the recommended format is not used, the date will be considered in the server timezone.";

public enum BootType {
UEFI, BIOS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ public class ListUsageRecordsCmd extends BaseListCmd {
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "List usage records for the specified domain.")
private Long domainId;

@Parameter(name = ApiConstants.END_DATE,
type = CommandType.DATE,
required = true,
description = "End date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 10:30:00).")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End date range for usage record query. " +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS)
private Date endDate;

@Parameter(name = ApiConstants.START_DATE,
type = CommandType.DATE,
required = true,
description = "Start date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 11:00:00).")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start date range for usage record query. " +
ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
private Date startDate;

@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
Expand Down Expand Up @@ -137,11 +133,11 @@ public void setDomainId(Long domainId) {
}

public void setEndDate(Date endDate) {
this.endDate = endDate == null ? null : new Date(endDate.getTime());
this.endDate = endDate;
}

public void setStartDate(Date startDate) {
this.startDate = startDate == null ? null : new Date(startDate.getTime());
this.startDate = startDate;
}

public void setAccountId(Long accountId) {
Expand All @@ -167,8 +163,8 @@ public Boolean isRecursive() {
@Override
public void execute() {
Pair<List<? extends Usage>, Integer> usageRecords = _usageService.getUsageRecords(this);
ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
ListResponse<UsageRecordResponse> response = new ListResponse<>();
List<UsageRecordResponse> usageResponses = new ArrayList<>();
Map<String, Set<ResourceTagResponse>> resourceTagResponseMap = null;
if (usageRecords != null) {
//read the resource tags details for all the resources in usage data and store in Map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.response;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down Expand Up @@ -133,11 +134,11 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen

@SerializedName(ApiConstants.START_DATE)
@Param(description = "start date of the usage record")
private String startDate;
private Date startDate;

@SerializedName(ApiConstants.END_DATE)
@Param(description = "end date of the usage record")
private String endDate;
private Date endDate;

@SerializedName("issourcenat")
@Param(description = "True if the IPAddress is source NAT")
Expand All @@ -160,7 +161,7 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen
private String vpcId;

public UsageRecordResponse() {
tags = new LinkedHashSet<ResourceTagResponse>();
tags = new LinkedHashSet<>();
}

public void setTags(Set<ResourceTagResponse> tags) {
Expand Down Expand Up @@ -245,11 +246,11 @@ public void setSize(Long size) {
this.size = size;
}

public void setStartDate(String startDate) {
public void setStartDate(Date startDate) {
this.startDate = startDate;
}

public void setEndDate(String endDate) {
public void setEndDate(Date endDate) {
this.endDate = endDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public class QuotaBalanceCmd extends BaseCmd {
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "If domain Id is given and the caller is domain admin then the statement is generated for domain.")
private Long domainId;

@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End of the period of the Quota balance." +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS)
private Date endDate;

@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start of the period of the Quota balance. " +
ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
private Date startDate;

@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public class QuotaStatementCmd extends BaseCmd {
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Optional, If domain Id is given and the caller is domain admin then the statement is generated for domain.")
private Long domainId;

@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End of the period of the Quota statement. " +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS)
private Date endDate;

@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start of the period of the Quota statement. " +
ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
private Date startDate;

@Parameter(name = ApiConstants.TYPE, type = CommandType.INTEGER, description = "List quota usage records for the specified usage type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public class QuotaTariffCreateCmd extends BaseCmd {
"value will be applied.", length = 65535)
private String activationRule;

@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The effective start date on/after which the quota tariff is effective. Use yyyy-MM-dd as"
+ " the date format, e.g. startDate=2009-06-03. Inform null to use the current date.")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The effective start date on/after which the quota tariff is effective. Inform null to " +
"use the current date. " + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
private Date startDate;

@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g."
+ " endDate=2009-06-03.")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. If not informed, the tariff will be valid indefinitely. " +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS)
private Date endDate;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public class QuotaTariffListCmd extends BaseListCmd {
@Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, description = "Usage type of the resource")
private Integer usageType;

@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The start date of the quota tariff. Use yyyy-MM-dd as the date format, "
+ "e.g. startDate=2009-06-03.")
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The start date of the quota tariff. " +
ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS)
private Date effectiveDate;

@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g. "
+ "endDate=2021-11-03.", since = "4.18.0.0")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. " +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS, since = "4.18.0.0")
private Date endDate;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the quota tariff.", since = "4.18.0.0")
private String name;

@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "False will list only not removed quota tariffs. If set to True, we will "
@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "False will list only not removed quota tariffs. If set to true, we will "
+ "list all, including the removed ones. The default is false.", since = "4.18.0.0")
private boolean listAll = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class QuotaTariffUpdateCmd extends BaseCmd {
"Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.")
private Date startDate;

@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g."
+ " endDate=2009-06-03.", since = "4.18.0.0")
@Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. " +
ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS, since = "4.18.0.0")
private Date endDate;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Quota tariff's name", length = 65535, since = "4.18.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff) {
response.setName(tariff.getName());
response.setEndDate(tariff.getEndDate());
response.setDescription(tariff.getDescription());
response.setUuid(tariff.getUuid());
response.setId(tariff.getUuid());
response.setRemoved(tariff.getRemoved());
return response;
}
Expand Down Expand Up @@ -376,8 +376,8 @@ public int compare(QuotaUsageVO o1, QuotaUsageVO o2) {

@Override
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariffListCmd cmd) {
Date startDate = _quotaService.computeAdjustedTime(cmd.getEffectiveDate());
Date endDate = _quotaService.computeAdjustedTime(cmd.getEndDate());
Date startDate = cmd.getEffectiveDate();
Date endDate = cmd.getEndDate();
Integer usageType = cmd.getUsageType();
String name = cmd.getName();
boolean listAll = cmd.isListAll();
Expand All @@ -395,10 +395,10 @@ public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariff
public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
String name = cmd.getName();
Double value = cmd.getValue();
Date endDate = _quotaService.computeAdjustedTime(cmd.getEndDate());
Date endDate = cmd.getEndDate();
String description = cmd.getDescription();
String activationRule = cmd.getActivationRule();
Date now = _quotaService.computeAdjustedTime(new Date());
Date now = new Date();

warnQuotaTariffUpdateDeprecatedFields(cmd);

Expand Down Expand Up @@ -488,7 +488,7 @@ protected void validateEndDateOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTar
endDate, startDate));
}

Date now = _quotaService.computeAdjustedTime(new Date());
Date now = new Date();
if (endDate.compareTo(now) < 0) {
throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than now [%s].",
endDate, now));
Expand All @@ -499,7 +499,7 @@ protected void validateEndDateOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTar

@Override
public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy, Boolean enforce) {
Date despositedOn = _quotaService.computeAdjustedTime(new Date());
Date despositedOn = new Date();
QuotaBalanceVO qb = _quotaBalanceDao.findLaterBalanceEntry(accountId, domainId, despositedOn);

if (qb != null) {
Expand Down Expand Up @@ -643,8 +643,8 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) {
int usageType = cmd.getUsageType();
Date startDate = cmd.getStartDate();
Date now = new Date();
startDate = _quotaService.computeAdjustedTime(startDate == null ? now : startDate);
Date endDate = _quotaService.computeAdjustedTime(cmd.getEndDate());
startDate = startDate == null ? now : startDate;
Date endDate = cmd.getEndDate();
Double value = cmd.getValue();
String description = cmd.getDescription();
String activationRule = cmd.getActivationRule();
Expand Down Expand Up @@ -675,10 +675,8 @@ public boolean deleteQuotaTariff(String quotaTariffUuid) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Quota tariff with the provided UUID does not exist.");
}

quotaTariff.setRemoved(_quotaService.computeAdjustedTime(new Date()));

quotaTariff.setRemoved(new Date());
CallContext.current().setEventResourceId(quotaTariff.getId());

return _quotaTariffDao.updateQuotaTariff(quotaTariff);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;

import java.math.BigDecimal;
Expand Down Expand Up @@ -74,9 +75,9 @@ public class QuotaTariffResponse extends BaseResponse {
@Param(description = "description")
private String description;

@SerializedName("uuid")
@Param(description = "uuid")
private String uuid;
@SerializedName(ApiConstants.ID)
@Param(description = "the ID of the tariff")
private String id;

@SerializedName("removed")
@Param(description = "when the quota tariff was removed")
Expand All @@ -87,15 +88,6 @@ public QuotaTariffResponse() {
this.setObjectName("quotatariff");
}

public QuotaTariffResponse(final int usageType) {
super();
this.usageType = usageType;
}

public String getUsageName() {
return usageName;
}

public void setUsageName(String usageName) {
this.usageName = usageName;
}
Expand All @@ -108,18 +100,10 @@ public void setUsageType(int usageType) {
this.usageType = usageType;
}

public String getUsageUnit() {
return usageUnit;
}

public void setUsageUnit(String usageUnit) {
this.usageUnit = usageUnit;
}

public String getUsageDiscriminator() {
return usageDiscriminator;
}

public void setUsageDiscriminator(String usageDiscriminator) {
this.usageDiscriminator = usageDiscriminator;
}
Expand All @@ -132,26 +116,14 @@ public void setTariffValue(BigDecimal tariffValue) {
this.tariffValue = tariffValue;
}

public String getUsageTypeDescription() {
return usageTypeDescription;
}

public void setUsageTypeDescription(String usageTypeDescription) {
this.usageTypeDescription = usageTypeDescription;
}

public Date getEffectiveOn() {
return effectiveOn;
}

public void setEffectiveOn(Date effectiveOn) {
this.effectiveOn = effectiveOn;
}

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}
Expand Down Expand Up @@ -188,16 +160,12 @@ public void setDescription(String description) {
this.description = description;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
public String getId() {
return id;
}

public Date getRemoved() {
return removed;
public void setId(String id) {
this.id = id;
}

public void setRemoved(Date removed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public interface QuotaService extends PluggableService {

List<QuotaBalanceVO> findQuotaBalanceVO(Long accountId, String accountName, Long domainId, Date startDate, Date endDate);

Date computeAdjustedTime(Date date);

void setLockAccount(Long accountId, Boolean state);

void setMinBalance(Long accountId, Double balance);
Expand Down
Loading