From c991b08be6489bab79319af3051fd4e03cde7fa9 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 22 Jul 2015 14:48:36 +0530 Subject: [PATCH] quota: fix tariff update cmd to accept start date, update effective/start date in db Signed-off-by: Rohit Yadav --- .../cloudstack/api/command/QuotaTariffUpdateCmd.java | 12 ++++++++++++ .../cloudstack/api/response/QuotaTariffResponse.java | 4 ++-- .../apache/cloudstack/quota/QuotaDBUtilsImpl.java | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java index 080010e1240..acf23411a16 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.quota.QuotaTariffVO; import org.apache.log4j.Logger; import javax.inject.Inject; +import java.util.Date; @APICommand(name = "quotaTariffUpdate", responseObject = QuotaTariffResponse.class, description = "Update the tariff plan for a resource", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaTariffUpdateCmd extends BaseCmd { @@ -44,6 +45,9 @@ public class QuotaTariffUpdateCmd extends BaseCmd { @Parameter(name = "value", type = CommandType.DOUBLE, required = true, description = "The quota tariff value of the resource as per the default unit") private Double value; + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "The effective start date on/after which the quota tariff is effective and older tariffs are no longer used for the usage type. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") + private Date startDate; + public int getUsageType() { return usageType; } @@ -60,6 +64,14 @@ public class QuotaTariffUpdateCmd extends BaseCmd { this.value = value; } + public Date getStartDate() { + return startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + public QuotaTariffUpdateCmd() { super(); } diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaTariffResponse.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaTariffResponse.java index 0c0df2515df..73ec4f645a2 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaTariffResponse.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaTariffResponse.java @@ -46,8 +46,8 @@ public class QuotaTariffResponse extends BaseResponse { @Param(description = "tariffValue") private BigDecimal tariffValue; - @SerializedName("effective_on") - @Param(description = "the time at whihc this quota value will be effective") + @SerializedName("effectiveDate") + @Param(description = "the date on/after which this quota value will be effective") private Date effectiveOn = null; @SerializedName("include") diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaDBUtilsImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaDBUtilsImpl.java index 1a8fc0bc978..c136c4520fe 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaDBUtilsImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/QuotaDBUtilsImpl.java @@ -229,13 +229,14 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils { TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); final int resourceType = cmd.getUsageType(); final BigDecimal quotaCost = new BigDecimal(cmd.getValue()); - Date now = _quotaManager.computeAdjustedTime(new Date()); - QuotaTariffVO result = _quotaTariffDao.findTariffPlanByUsageType(resourceType, now); + final Date effectiveDate = _quotaManager.computeAdjustedTime(cmd.getStartDate()); + QuotaTariffVO result = _quotaTariffDao.findTariffPlanByUsageType(resourceType, effectiveDate); if (result == null) { throw new InvalidParameterValueException(String.format("Invalid Usage Resource type=%d provided", resourceType)); } s_logger.debug(String.format("Updating Quota Tariff Plan: Old value=%s, new value=%s for resource type=%d", result.getCurrencyValue(), quotaCost, resourceType)); result.setCurrencyValue(quotaCost); + result.setEffectiveOn(effectiveDate); _quotaTariffDao.updateQuotaTariff(result); TransactionLegacy.open(opendb).close(); return result;