mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-8592: further review fixes
This commit is contained in:
parent
6c246acc16
commit
c3364324e6
|
|
@ -18,7 +18,9 @@ package org.apache.cloudstack.quota.constant;
|
|||
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QuotaTypes extends UsageTypes {
|
||||
public static final int CPU_CLOCK_RATE = 15;
|
||||
|
|
@ -30,9 +32,10 @@ public class QuotaTypes extends UsageTypes {
|
|||
private final String quotaUnit;
|
||||
private final String description;
|
||||
private final String discriminator;
|
||||
private static final HashMap<Integer, QuotaTypes> quotaTypeList = new HashMap<Integer, QuotaTypes>();
|
||||
private final static Map<Integer, QuotaTypes> quotaTypeMap;
|
||||
|
||||
static {
|
||||
final HashMap<Integer, QuotaTypes> quotaTypeList = new HashMap<Integer, QuotaTypes>();
|
||||
quotaTypeList.put(RUNNING_VM, new QuotaTypes(RUNNING_VM, "RUNNING_VM", "Compute-Month", "Running Vm Usage"));
|
||||
quotaTypeList.put(ALLOCATED_VM, new QuotaTypes(ALLOCATED_VM, "ALLOCATED_VM", "Compute-Month", "Allocated Vm Usage"));
|
||||
quotaTypeList.put(IP_ADDRESS, new QuotaTypes(IP_ADDRESS, "IP_ADDRESS", "IP-Month", "IP Address Usage"));
|
||||
|
|
@ -55,6 +58,7 @@ public class QuotaTypes extends UsageTypes {
|
|||
quotaTypeList.put(CPU_CLOCK_RATE, new QuotaTypes(CPU_CLOCK_RATE, "CPU_CLOCK_RATE", "Compute-Month", "Quota tariff for using 1 CPU of clock rate 100MHz"));
|
||||
quotaTypeList.put(CPU_NUMBER, new QuotaTypes(CPU_NUMBER, "CPU_NUMBER", "Compute-Month", "Quota tariff for running VM that has 1vCPU"));
|
||||
quotaTypeList.put(MEMORY, new QuotaTypes(MEMORY, "MEMORY", "Compute-Month", "Quota tariff for using 1MB or RAM for 1 hour"));
|
||||
quotaTypeMap = Collections.unmodifiableMap(quotaTypeList);
|
||||
}
|
||||
|
||||
private QuotaTypes(Integer quotaType, String name, String unit, String description) {
|
||||
|
|
@ -65,8 +69,8 @@ public class QuotaTypes extends UsageTypes {
|
|||
this.discriminator = "None";
|
||||
}
|
||||
|
||||
public static HashMap<Integer, QuotaTypes> listQuotaTypes() {
|
||||
return quotaTypeList;
|
||||
public static Map<Integer, QuotaTypes> listQuotaTypes() {
|
||||
return quotaTypeMap;
|
||||
}
|
||||
|
||||
public String getDiscriminator() {
|
||||
|
|
@ -90,10 +94,6 @@ public class QuotaTypes extends UsageTypes {
|
|||
}
|
||||
|
||||
static public String getDescription(int quotaType) {
|
||||
HashMap<Integer, QuotaTypes> quotaMap = listQuotaTypes();
|
||||
if (quotaMap.containsKey(quotaType)) {
|
||||
return quotaMap.get(quotaType).getDescription();
|
||||
}
|
||||
return null;
|
||||
return quotaTypeMap.get(quotaType).getDescription();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
|||
@Component
|
||||
@Local(value = { QuotaAccountDao.class })
|
||||
public class QuotaAccountDaoImpl extends GenericDaoBase<QuotaAccountVO, Long> implements QuotaAccountDao {
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaAccountDaoImpl.class.getName());
|
||||
public static final Logger s_logger = Logger.getLogger(QuotaAccountDaoImpl.class);
|
||||
|
||||
@Override
|
||||
public List<QuotaAccountVO> listAll() {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
|
|||
sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
|
||||
sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
|
||||
quotaBalanceEntries = search(sc, filter);
|
||||
return quotaBalanceEntries.size() > 0 ? quotaBalanceEntries.get(0) : null;
|
||||
return ! quotaBalanceEntries.isEmpty() ? quotaBalanceEntries.get(0) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -169,7 +169,9 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
|
|||
|
||||
// get records before startDate to find start balance
|
||||
for (QuotaBalanceVO entry : quotaUsageRecords) {
|
||||
s_logger.debug("FindQuotaBalance Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId());
|
||||
if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("FindQuotaBalIance Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId());
|
||||
}
|
||||
if (entry.getCreditsId() > 0) {
|
||||
trimmedRecords.add(entry);
|
||||
} else {
|
||||
|
|
@ -190,7 +192,9 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
|
|||
}
|
||||
BigDecimal finalBalance = new BigDecimal(0);
|
||||
for (QuotaBalanceVO entry : quotaBalance) {
|
||||
s_logger.debug("lastQuotaBalance Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId());
|
||||
if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("lastQuotaBalance Date=" + entry.getUpdatedOn().toGMTString() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId());
|
||||
}
|
||||
finalBalance = finalBalance.add(entry.getCreditBalance());
|
||||
}
|
||||
return finalBalance;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.cloud.utils.db.Transaction;
|
|||
import com.cloud.utils.db.TransactionCallback;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.db.TransactionStatus;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -35,7 +36,7 @@ import java.util.List;
|
|||
@Component
|
||||
@Local(value = { QuotaEmailTemplatesDao.class })
|
||||
public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase<QuotaEmailTemplatesVO, Long> implements QuotaEmailTemplatesDao {
|
||||
private static final Logger s_logger = Logger.getLogger(QuotaEmailTemplatesDaoImpl.class.getName());
|
||||
private static final Logger s_logger = Logger.getLogger(QuotaEmailTemplatesDaoImpl.class);
|
||||
|
||||
protected SearchBuilder<QuotaEmailTemplatesVO> QuotaEmailTemplateSearch;
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase<QuotaEmailTemplat
|
|||
@Override
|
||||
public List<QuotaEmailTemplatesVO> doInTransaction(final TransactionStatus status) {
|
||||
SearchCriteria<QuotaEmailTemplatesVO> sc = QuotaEmailTemplateSearch.create();
|
||||
if (templateName != null) {
|
||||
if (!Strings.isNullOrEmpty(templateName)) {
|
||||
sc.setParameters("template_name", templateName);
|
||||
}
|
||||
return listBy(sc);
|
||||
|
|
|
|||
|
|
@ -17,23 +17,24 @@
|
|||
package org.apache.cloudstack.quota.constant;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class QuotaTypesTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testQuotaTypesList() {
|
||||
HashMap<Integer, QuotaTypes> quotaTypes = QuotaTypes.listQuotaTypes();
|
||||
Map<Integer, QuotaTypes> quotaTypes = QuotaTypes.listQuotaTypes();
|
||||
List<UsageTypeResponse> usageTypesResponseList = UsageTypes.listUsageTypes();
|
||||
for (UsageTypeResponse usageTypeResponse: usageTypesResponseList) {
|
||||
for (UsageTypeResponse usageTypeResponse : usageTypesResponseList) {
|
||||
final Integer usageTypeInt = usageTypeResponse.getUsageType();
|
||||
assertTrue(quotaTypes.containsKey(usageTypeInt));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
// under the License.
|
||||
(function($, cloudStack) {
|
||||
cloudStack.plugins = [
|
||||
//'quota',
|
||||
'quota',
|
||||
//'testPlugin'
|
||||
];
|
||||
}(jQuery, cloudStack));
|
||||
|
|
|
|||
Loading…
Reference in New Issue