mirror of https://github.com/apache/cloudstack.git
quota: fix stuff
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
df2687aca8
commit
a539574ef0
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -30,4 +30,6 @@ public interface QuotaTariffDao extends GenericDao<QuotaTariffVO, Long> {
|
|||
List<QuotaTariffVO> listAllTariffPlans(Date onOrBefore);
|
||||
|
||||
boolean updateQuotaTariff(QuotaTariffVO plan);
|
||||
|
||||
QuotaTariffVO addQuotaTariff(QuotaTariffVO plan);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue