quota: fix db quota usage

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2015-07-22 15:11:42 +05:30
parent c991b08be6
commit df2687aca8
1 changed files with 19 additions and 11 deletions

View File

@ -227,18 +227,26 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
final int resourceType = cmd.getUsageType();
final BigDecimal quotaCost = new BigDecimal(cmd.getValue());
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));
QuotaTariffVO result = null;
try {
final int resourceType = cmd.getUsageType();
final BigDecimal quotaCost = new BigDecimal(cmd.getValue());
final Date effectiveDate = _quotaManager.computeAdjustedTime(cmd.getStartDate());
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);
} catch (Exception pokemon) {
s_logger.error("Error in update quota tariff plan: " + pokemon);
} finally {
TransactionLegacy.open(opendb).close();
}
if (result != null) {
_quotaTariffDao.updateQuotaTariff(result);
}
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;
}