Quota: findbug fixes

Findbug fixes for cloud-framework-quota and cloud-plugin-database-quota.
This commit is contained in:
Abhinandan Prateek 2015-12-23 10:12:11 +05:30 committed by Abhinandan Prateek
parent 67b753c11b
commit 1304406fd1
4 changed files with 25 additions and 72 deletions

View File

@ -85,7 +85,7 @@ public class QuotaStatementImpl extends ManagerBase implements QuotaStatement {
mergeConfigs(configs, params); mergeConfigs(configs, params);
} }
String period_str = configs.get(QuotaConfig.QuotaStatementPeriod.key()); String period_str = configs.get(QuotaConfig.QuotaStatementPeriod.key());
int period = period_str == null ? 1 : Integer.valueOf(period_str); int period = period_str == null ? 1 : Integer.parseInt(period_str);
STATEMENT_PERIODS _period = STATEMENT_PERIODS.values()[period]; STATEMENT_PERIODS _period = STATEMENT_PERIODS.values()[period];
return true; return true;

View File

@ -16,6 +16,7 @@
//under the License. //under the License.
package org.apache.cloudstack.quota.vo; package org.apache.cloudstack.quota.vo;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.persistence.Column; import javax.persistence.Column;
@ -74,14 +75,9 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
@Column(name = "deployment_planner") @Column(name = "deployment_planner")
private String deploymentPlanner = null; private String deploymentPlanner = null;
// This is a delayed load value. If the value is null,
// then this field has not been loaded yet.
// Call service offering dao to load it.
@Transient @Transient
Map<String, String> details; Map<String, String> details = new HashMap<String, String>();
// This flag is required to tell if the offering is dynamic once the cpu, memory and speed are set.
// In some cases cpu, memory and speed are set to non-null values even if the offering is dynamic.
@Transient @Transient
boolean isDynamic; boolean isDynamic;
@ -90,7 +86,7 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
} }
public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText,
ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) { ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) {
super(name, displayText, provisioningType, false, tags, recreatable, useLocalStorage, systemUse, true); super(name, displayText, provisioningType, false, tags, recreatable, useLocalStorage, systemUse, true);
this.cpu = cpu; this.cpu = cpu;
this.ramSize = ramSize; this.ramSize = ramSize;
@ -105,7 +101,8 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
} }
public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitCpuUse, public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitCpuUse,
boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, Long domainId) { boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse,
VirtualMachine.Type vmType, Long domainId) {
super(name, displayText, provisioningType, false, tags, recreatable, useLocalStorage, systemUse, true, domainId); super(name, displayText, provisioningType, false, tags, recreatable, useLocalStorage, systemUse, true, domainId);
this.cpu = cpu; this.cpu = cpu;
this.ramSize = ramSize; this.ramSize = ramSize;
@ -118,68 +115,26 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
this.vmType = vmType == null ? null : vmType.toString().toLowerCase(); this.vmType = vmType == null ? null : vmType.toString().toLowerCase();
} }
public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse,
boolean limitResourceUse, boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse,
VirtualMachine.Type vmType, Long domainId, String hostTag) { VirtualMachine.Type vmType, Long domainId, String hostTag) {
this(name, this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm, displayText, provisioningType, useLocalStorage, recreatable, tags,
cpu, systemUse, vmType, domainId);
ramSize,
speed,
rateMbps,
multicastRateMbps,
offerHA,
limitResourceUse,
volatileVm,
displayText,
provisioningType,
useLocalStorage,
recreatable,
tags,
systemUse,
vmType,
domainId);
this.hostTag = hostTag; this.hostTag = hostTag;
} }
public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, boolean limitResourceUse,
boolean limitResourceUse, boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse, boolean volatileVm, String displayText, ProvisioningType provisioningType, boolean useLocalStorage, boolean recreatable, String tags, boolean systemUse,
VirtualMachine.Type vmType, Long domainId, String hostTag, String deploymentPlanner) { VirtualMachine.Type vmType, Long domainId, String hostTag, String deploymentPlanner) {
this(name, this(name, cpu, ramSize, speed, rateMbps, multicastRateMbps, offerHA, limitResourceUse, volatileVm, displayText, provisioningType, useLocalStorage, recreatable, tags,
cpu, systemUse, vmType, domainId, hostTag);
ramSize,
speed,
rateMbps,
multicastRateMbps,
offerHA,
limitResourceUse,
volatileVm,
displayText,
provisioningType,
useLocalStorage,
recreatable,
tags,
systemUse,
vmType,
domainId,
hostTag);
this.deploymentPlanner = deploymentPlanner; this.deploymentPlanner = deploymentPlanner;
} }
public ServiceOfferingVO(ServiceOfferingVO offering) { public ServiceOfferingVO(ServiceOfferingVO offering) {
super(offering.getId(), super(offering.getId(), offering.getName(), offering.getDisplayText(), offering.getProvisioningType(), false, offering.getTags(), offering.isRecreatable(),
offering.getName(), offering.getUseLocalStorage(), offering.getSystemUse(), true, offering.isCustomizedIops() == null ? false : offering.isCustomizedIops(), offering.getDomainId(),
offering.getDisplayText(), offering.getMinIops(), offering.getMaxIops());
offering.getProvisioningType(),
false,
offering.getTags(),
offering.isRecreatable(),
offering.getUseLocalStorage(),
offering.getSystemUse(),
true,
offering.isCustomizedIops()== null ? false:offering.isCustomizedIops(),
offering.getDomainId(),
offering.getMinIops(),
offering.getMaxIops());
cpu = offering.getCpu(); cpu = offering.getCpu();
ramSize = offering.getRamSize(); ramSize = offering.getRamSize();
speed = offering.getSpeed(); speed = offering.getSpeed();
@ -310,14 +265,10 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
} }
public String getDetail(String name) { public String getDetail(String name) {
assert (details != null) : "Did you forget to load the details?"; return details.get(name);
return details != null ? details.get(name) : null;
} }
public void setDetail(String name, String value) { public void addDetail(String name, String value) {
assert (details != null) : "Did you forget to load the details?";
details.put(name, value); details.put(name, value);
} }

View File

@ -174,10 +174,12 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
@Override @Override
public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate, Date endDate) { public QuotaBalanceResponse createQuotaBalanceResponse(List<QuotaBalanceVO> quotaBalance, Date startDate, Date endDate) {
if (quotaBalance == null || quotaBalance.isEmpty()) { if (quotaBalance == null || quotaBalance.isEmpty()) {
new InvalidParameterValueException("The request period does not contain balance entries."); throw new InvalidParameterValueException("The request period does not contain balance entries.");
} }
Collections.sort(quotaBalance, new Comparator<QuotaBalanceVO>() { Collections.sort(quotaBalance, new Comparator<QuotaBalanceVO>() {
public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) {
o1 = o1 == null ? new QuotaBalanceVO() : o1;
o2 = o2 == null ? new QuotaBalanceVO() : o2;
return o2.getUpdatedOn().compareTo(o1.getUpdatedOn()); // desc return o2.getUpdatedOn().compareTo(o1.getUpdatedOn()); // desc
} }
}); });

View File

@ -118,7 +118,7 @@ public class QuotaResponseBuilderImplTest extends TestCase {
tariffVO.setUsageType(QuotaTypes.IP_ADDRESS); tariffVO.setUsageType(QuotaTypes.IP_ADDRESS);
tariffVO.setUsageName("ip address"); tariffVO.setUsageName("ip address");
tariffVO.setUsageUnit("IP-Month"); tariffVO.setUsageUnit("IP-Month");
tariffVO.setCurrencyValue(new BigDecimal(100.19)); tariffVO.setCurrencyValue(BigDecimal.valueOf(100.19));
tariffVO.setEffectiveOn(new Date()); tariffVO.setEffectiveOn(new Date());
tariffVO.setUsageDiscriminator(""); tariffVO.setUsageDiscriminator("");
return tariffVO; return tariffVO;