quota: fix stuff

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2015-07-22 16:04:38 +05:30
parent df2687aca8
commit a539574ef0
6 changed files with 30 additions and 3 deletions

View File

@ -39,5 +39,10 @@
<artifactId>commons-lang3</artifactId>
<version>${cs.commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${cs.joda-time.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -37,6 +37,7 @@ import org.apache.cloudstack.api.response.QuotaTariffResponse;
import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
import org.apache.cloudstack.quota.dao.QuotaTariffDao;
import org.apache.log4j.Logger;
import org.joda.time.DateTimeComparator;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
@ -228,6 +229,7 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
QuotaTariffVO result = null;
boolean updateRecord = false;
try {
final int resourceType = cmd.getUsageType();
final BigDecimal quotaCost = new BigDecimal(cmd.getValue());
@ -237,6 +239,9 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
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));
if (DateTimeComparator.getDateOnlyInstance().compare(result.getEffectiveOn(), effectiveDate) == 0) {
updateRecord = true;
}
result.setCurrencyValue(quotaCost);
result.setEffectiveOn(effectiveDate);
} catch (Exception pokemon) {
@ -245,7 +250,11 @@ public class QuotaDBUtilsImpl implements QuotaDBUtils {
TransactionLegacy.open(opendb).close();
}
if (result != null) {
_quotaTariffDao.updateQuotaTariff(result);
if (updateRecord) {
_quotaTariffDao.updateQuotaTariff(result);
} else {
result = _quotaTariffDao.addQuotaTariff(result);
}
}
return result;
}

View File

@ -27,9 +27,8 @@ public class QuotaTypes extends UsageTypes {
public static final int CPU_NUMBER = 16;
public static final int MEMORY = 17;
public static List<QuotaTypeResponse> responseList = new ArrayList<QuotaTypeResponse>();
public static List<QuotaTypeResponse> listQuotaUsageTypes() {
final List<QuotaTypeResponse> responseList = new ArrayList<QuotaTypeResponse>();
responseList.add(new QuotaTypeResponse(RUNNING_VM, "Running Vm Usage"));
responseList.add(new QuotaTypeResponse(ALLOCATED_VM, "Allocated Vm Usage"));
responseList.add(new QuotaTypeResponse(IP_ADDRESS, "IP Address Usage"));

View File

@ -30,4 +30,6 @@ public interface QuotaTariffDao extends GenericDao<QuotaTariffVO, Long> {
List<QuotaTariffVO> listAllTariffPlans(Date onOrBefore);
boolean updateQuotaTariff(QuotaTariffVO plan);
QuotaTariffVO addQuotaTariff(QuotaTariffVO plan);
}

View File

@ -117,4 +117,15 @@ public class QuotaTariffDaoImpl extends GenericDaoBase<QuotaTariffVO, Long> impl
TransactionLegacy.open(opendb).close(); // Switch back
return result;
}
@Override
public QuotaTariffVO addQuotaTariff(QuotaTariffVO plan) {
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy.open(TransactionLegacy.USAGE_DB).close(); // Switch to
// Usage DB
plan.setId(null);
QuotaTariffVO result = this.persist(plan);
TransactionLegacy.open(opendb).close(); // Switch back
return result;
}
}

View File

@ -97,6 +97,7 @@
<cs.findbugs.version>2.5.3</cs.findbugs.version>
<cs.javadoc.version>2.9.1</cs.javadoc.version>
<cs.opensaml.version>2.6.1</cs.opensaml.version>
<cs.joda-time.version>2.8.1</cs.joda-time.version>
</properties>
<distributionManagement>