quota: fix tariff update cmd to accept start date, update effective/start date in db

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2015-07-22 14:48:36 +05:30
parent ae26d67cb0
commit c991b08be6
3 changed files with 17 additions and 4 deletions

View File

@ -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();
}

View File

@ -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")

View File

@ -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;