From 0e0df49d3ea602e91f08f54507ef5c3e97eb2f11 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 24 Jul 2015 14:34:39 +0530 Subject: [PATCH] quota: remove include column from tariff, fix list tariff api to accept start date Signed-off-by: Rohit Yadav --- .../cloudstack/api/command/QuotaTariffListCmd.java | 8 ++++++++ .../api/response/QuotaResponseBuilderImpl.java | 6 ++++-- .../api/response/QuotaTariffResponse.java | 12 ------------ .../cloudstack/quota/dao/QuotaTariffDaoImpl.java | 3 --- .../apache/cloudstack/quota/vo/QuotaTariffVO.java | 14 +------------- setup/db/db/schema-451to452.sql | 1 - 6 files changed, 13 insertions(+), 31 deletions(-) diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java index bad2016685e..1b0625703f7 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.java @@ -31,6 +31,7 @@ import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; +import java.util.Date; import java.util.List; @APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) @@ -44,6 +45,9 @@ public class QuotaTariffListCmd extends BaseListCmd { @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, required = false, description = "Usage type of the resource") private Integer usageType; + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = false, 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 QuotaTariffListCmd() { super(); } @@ -74,6 +78,10 @@ public class QuotaTariffListCmd extends BaseListCmd { return Account.ACCOUNT_ID_SYSTEM; } + public Date getStartDate() { + return startDate; + } + public Integer getUsageType() { return usageType; } diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index 1337e0a4313..d0d2123c3c9 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -79,7 +79,6 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { response.setUsageUnit(tariff.getUsageUnit()); response.setUsageDiscriminator(tariff.getUsageDiscriminator()); response.setTariffValue(tariff.getCurrencyValue()); - response.setInclude(tariff.getInclude()); response.setEffectiveOn(tariff.getEffectiveOn()); response.setDescription(tariff.getDescription()); return response; @@ -215,7 +214,10 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { @Override public List listQuotaTariffPlans(final QuotaTariffListCmd cmd) { List result = new ArrayList(); - Date now = _quotaService.computeAdjustedTime(new Date()); + Date now = cmd.getStartDate(); + if (now == null) { + now = _quotaService.computeAdjustedTime(new Date()); + } s_logger.info("Now=" + now.toGMTString() + " quotatype=" + cmd.getUsageType()); if (cmd.getUsageType() != null) { QuotaTariffVO tariffPlan = _quotaTariffDao.findTariffPlanByUsageType(cmd.getUsageType(), now); 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 73ec4f645a2..af4de174d72 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 @@ -50,10 +50,6 @@ public class QuotaTariffResponse extends BaseResponse { @Param(description = "the date on/after which this quota value will be effective") private Date effectiveOn = null; - @SerializedName("include") - @Param(description = "include") - private int include; - @SerializedName("description") @Param(description = "description") private String description; @@ -108,14 +104,6 @@ public class QuotaTariffResponse extends BaseResponse { this.tariffValue = tariffValue; } - public int getInclude() { - return include; - } - - public void setInclude(int include) { - this.include = include; - } - public String getDescription() { return description; } diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java index 3efe1dc86aa..d5f2f927ca2 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java @@ -48,7 +48,6 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl searchUsageType.done(); listAllIncludedUsageType = createSearchBuilder(); - listAllIncludedUsageType.and("include", listAllIncludedUsageType.entity().getInclude(), SearchCriteria.Op.EQ); listAllIncludedUsageType.and("onorbeforedate", listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ); listAllIncludedUsageType.and("quotatype", listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ); listAllIncludedUsageType.done(); @@ -62,7 +61,6 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl try { final Filter filter = new Filter(QuotaTariffVO.class, "effectiveOn", false, 0L, 1L); final SearchCriteria sc = listAllIncludedUsageType.create(); - sc.setParameters("include", 1); sc.setParameters("onorbeforedate", onOrBeforeDate); sc.setParameters("quotatype", quotaType); result = search(sc, filter); @@ -88,7 +86,6 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl try { final Filter filter = new Filter(QuotaTariffVO.class, "effectiveOn", false, 0L, 1L); final SearchCriteria sc = listAllIncludedUsageType.create(); - sc.setParameters("include", 1); sc.setParameters("onorbeforedate", onOrBeforeDate); for (Integer quotaType : QuotaTypes.listQuotaTypes().keySet()) { sc.setParameters("quotatype", quotaType); diff --git a/plugins/database/quota/src/org/apache/cloudstack/quota/vo/QuotaTariffVO.java b/plugins/database/quota/src/org/apache/cloudstack/quota/vo/QuotaTariffVO.java index 5b849477009..38a26b7c709 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/quota/vo/QuotaTariffVO.java +++ b/plugins/database/quota/src/org/apache/cloudstack/quota/vo/QuotaTariffVO.java @@ -56,9 +56,6 @@ public class QuotaTariffVO implements InternalIdentity { @Column(name = "currency_value") private BigDecimal currencyValue; - @Column(name = "include") - private int include; - @Column(name = "effective_on") @Temporal(value = TemporalType.TIMESTAMP) private Date effectiveOn = null; @@ -73,14 +70,13 @@ public class QuotaTariffVO implements InternalIdentity { public QuotaTariffVO() { } - public QuotaTariffVO(final int usagetype, final String usagename, final String usageunit, final String usagediscriminator, final BigDecimal currencyvalue, final int include, + public QuotaTariffVO(final int usagetype, final String usagename, final String usageunit, final String usagediscriminator, final BigDecimal currencyvalue, final Date effectiveOn, final Date updatedOn, final long updatedBy) { this.usageType = usagetype; this.usageName = usagename; this.usageUnit = usageunit; this.usageDiscriminator = usagediscriminator; this.currencyValue = currencyvalue; - this.include = include; this.effectiveOn = effectiveOn; this.updatedOn = updatedOn; this.updatedBy = updatedBy; @@ -155,14 +151,6 @@ public class QuotaTariffVO implements InternalIdentity { this.currencyValue = currencyValue; } - public int getInclude() { - return include; - } - - public void setInclude(int include) { - this.include = include; - } - public String getDescription() { return QuotaTypes.getDescription(usageType); } diff --git a/setup/db/db/schema-451to452.sql b/setup/db/db/schema-451to452.sql index 08671766266..041d0e5d3a4 100644 --- a/setup/db/db/schema-451to452.sql +++ b/setup/db/db/schema-451to452.sql @@ -48,7 +48,6 @@ CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_tariff` ( `usage_unit` varchar(255) NOT NULL COMMENT 'usage type', `usage_discriminator` varchar(255) NOT NULL COMMENT 'usage type', `currency_value` decimal(15,2) NOT NULL COMMENT 'usage type', - `include` tinyint(1) NOT NULL COMMENT 'usage type', `effective_on` datetime NOT NULL COMMENT 'date time on which this quota values will become effective', `updated_on` datetime NOT NULL COMMENT 'date this entry was updated on', `updated_by` bigint unsigned NOT NULL,