Fixed Coverity reported performance issues like inefficient string concatenations, wrong boxing or unboxing types, inefficent map element retrievals

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Santhosh Edukulla 2014-07-01 12:24:59 +05:30 committed by Daan Hoogland
parent 667347d17e
commit 97d296bfbd
25 changed files with 126 additions and 97 deletions

View File

@ -86,8 +86,8 @@ public class ScaleSystemVMCmd extends BaseAsyncCmd {
Iterator iter = parameterCollection.iterator(); Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next(); HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (String key : value.keySet()) { for (Map.Entry<String, String> entry : value.entrySet()) {
customparameterMap.put(key, value.get(key)); customparameterMap.put(entry.getKey(), entry.getValue());
} }
} }
} }

View File

@ -81,8 +81,8 @@ public class UpgradeSystemVMCmd extends BaseCmd {
Iterator iter = parameterCollection.iterator(); Iterator iter = parameterCollection.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
HashMap<String, String> value = (HashMap<String, String>)iter.next(); HashMap<String, String> value = (HashMap<String, String>)iter.next();
for (String key : value.keySet()) { for (Map.Entry<String,String>entry : value.entrySet()) {
customparameterMap.put(key, value.get(key)); customparameterMap.put(entry.getKey(), entry.getValue());
} }
} }
} }

View File

@ -332,8 +332,8 @@ public class CallContext {
public void putContextParameters(Map<Object, Object> details){ public void putContextParameters(Map<Object, Object> details){
if (details == null) return; if (details == null) return;
for(Object key : details.keySet()){ for(Map.Entry<Object,Object>entry : details.entrySet()){
putContextParameter(key, details.get(key)); putContextParameter(entry.getKey(), entry.getValue());
} }
} }

View File

@ -476,15 +476,14 @@ public class VirtualRoutingResource {
LoadBalancerConfigurator cfgtr = new HAProxyConfigurator(); LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();
String[] config = cfgtr.generateConfiguration(cmd); String[] config = cfgtr.generateConfiguration(cmd);
String tmpCfgFileContents = ""; StringBuffer buff = new StringBuffer();
for (int i = 0; i < config.length; i++) { for (int i = 0; i < config.length; i++) {
tmpCfgFileContents += config[i]; buff.append(config[i]);
tmpCfgFileContents += "\n"; buff.append("\n");
} }
String tmpCfgFilePath = "/etc/haproxy/"; String tmpCfgFilePath = "/etc/haproxy/";
String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis()); String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis());
cfg.add(new ConfigItem(tmpCfgFilePath, tmpCfgFileName, tmpCfgFileContents)); cfg.add(new ConfigItem(tmpCfgFilePath, tmpCfgFileName, buff.toString()));
String[][] rules = cfgtr.generateFwRules(cmd); String[][] rules = cfgtr.generateFwRules(cmd);
@ -610,18 +609,28 @@ public class VirtualRoutingResource {
LinkedList<ConfigItem> cfg = new LinkedList<>(); LinkedList<ConfigItem> cfg = new LinkedList<>();
String args = ""; String args = "";
StringBuffer buff = new StringBuffer();
List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
for (IpAliasTO ipAliasTO : revokedIpAliasTOs) { for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
args = args + ipAliasTO.getAlias_count() + ":" + ipAliasTO.getRouterip() + ":" + ipAliasTO.getNetmask() + "-"; buff.append(ipAliasTO.getAlias_count());
buff.append(":");
buff.append(ipAliasTO.getRouterip());
buff.append(":");
buff.append(ipAliasTO.getNetmask());
buff.append("-");
} }
//this is to ensure that thre is some argument passed to the deleteipAlias script when there are no revoked rules. //this is to ensure that thre is some argument passed to the deleteipAlias script when there are no revoked rules.
args = args + "- "; buff.append("- ");
List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos(); List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
for (IpAliasTO ipAliasTO : activeIpAliasTOs) { for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
args = args + ipAliasTO.getAlias_count() + ":" + ipAliasTO.getRouterip() + ":" + ipAliasTO.getNetmask() + "-"; buff.append(ipAliasTO.getAlias_count());
buff.append(":");
buff.append(ipAliasTO.getRouterip());
buff.append(":");
buff.append(ipAliasTO.getNetmask());
buff.append("-");
} }
cfg.add(new ConfigItem(VRScripts.IPALIAS_DELETE, buff.toString()));
cfg.add(new ConfigItem(VRScripts.IPALIAS_DELETE, args));
return cfg; return cfg;
} }
@ -629,22 +638,29 @@ public class VirtualRoutingResource {
LinkedList<ConfigItem> cfg = new LinkedList<>(); LinkedList<ConfigItem> cfg = new LinkedList<>();
List<DhcpTO> dhcpTos = cmd.getIps(); List<DhcpTO> dhcpTos = cmd.getIps();
String args = ""; StringBuffer buff = new StringBuffer();
for (DhcpTO dhcpTo : dhcpTos) { for (DhcpTO dhcpTo : dhcpTos) {
args = args + dhcpTo.getRouterIp() + ":" + dhcpTo.getGateway() + ":" + dhcpTo.getNetmask() + ":" + dhcpTo.getStartIpOfSubnet() + "-"; buff.append(dhcpTo.getRouterIp());
buff.append(":");
buff.append(dhcpTo.getGateway());
buff.append(":");
buff.append(dhcpTo.getNetmask());
buff.append(":");
buff.append(dhcpTo.getStartIpOfSubnet());
buff.append("-");
} }
cfg.add(new ConfigItem(VRScripts.DNSMASQ_CONFIG, buff.toString()));
cfg.add(new ConfigItem(VRScripts.DNSMASQ_CONFIG, args));
return cfg; return cfg;
} }
private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) { private CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
String args = "";
for (String ip : cmd.getVpnIps()) {
args += ip + " ";
}
ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.S2SVPN_CHECK, args); StringBuffer buff = new StringBuffer();
for (String ip : cmd.getVpnIps()) {
buff.append(ip);
buff.append(" ");
}
ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.S2SVPN_CHECK, buff.toString());
return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails()); return new CheckS2SVpnConnectionsAnswer(cmd, result.isSuccess(), result.getDetails());
} }

View File

@ -126,7 +126,7 @@ public abstract class AgentAttache {
_maintenance = maintenance; _maintenance = maintenance;
_requests = new LinkedList<Request>(); _requests = new LinkedList<Request>();
_agentMgr = agentMgr; _agentMgr = agentMgr;
_nextSequence = new Long(s_rand.nextInt(Short.MAX_VALUE)) << 48; _nextSequence = new Long(s_rand.nextInt(Short.MAX_VALUE)).longValue() << 48;
} }
public synchronized long getNextSequence() { public synchronized long getNextSequence() {

View File

@ -643,8 +643,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Map<String, String> args = new HashMap<String, String>(); Map<String, String> args = new HashMap<String, String>();
Task task = null; Task task = null;
try { try {
for (String key : params.keySet()) { for (Map.Entry< String, String > entry : params.entrySet()) {
args.put(key, params.get(key)); args.put(entry.getKey(), entry.getValue());
} }
if (s_logger.isTraceEnabled()) { if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin executing for command " + cmd s_logger.trace("callHostPlugin executing for command " + cmd
@ -2313,8 +2313,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return new GetVmStatsAnswer(cmd, vmStatsNameMap); return new GetVmStatsAnswer(cmd, vmStatsNameMap);
} }
for (String vmUUID : vmStatsUUIDMap.keySet()) { for (Map.Entry<String,VmStatsEntry>entry : vmStatsUUIDMap.entrySet()) {
vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(vmUUID)), vmStatsUUIDMap.get(vmUUID)); vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(entry.getKey())), entry.getValue());
} }
return new GetVmStatsAnswer(cmd, vmStatsNameMap); return new GetVmStatsAnswer(cmd, vmStatsNameMap);
@ -2387,8 +2387,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
} }
for (String vmUUID : vmResponseMap.keySet()) { for (Map.Entry<String, VmStatsEntry> entry: vmResponseMap.entrySet()) {
VmStatsEntry vmStatsAnswer = vmResponseMap.get(vmUUID); VmStatsEntry vmStatsAnswer = entry.getValue();
if (vmStatsAnswer.getNumCPUs() != 0) { if (vmStatsAnswer.getNumCPUs() != 0) {
vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() / vmStatsAnswer.getNumCPUs()); vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() / vmStatsAnswer.getNumCPUs());
@ -6533,8 +6533,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
s_logger.warn("Unable to find vdi by uuid: " + vdiUuid + ", skip it"); s_logger.warn("Unable to find vdi by uuid: " + vdiUuid + ", skip it");
} }
} }
for (VDI vdi : vdiMap.keySet()) { for (Map.Entry<VDI, VolumeObjectTO>entry : vdiMap.entrySet()) {
VolumeObjectTO volumeTO = vdiMap.get(vdi); VDI vdi = entry.getKey();
VolumeObjectTO volumeTO = entry.getValue();
VBD.Record vbdr = new VBD.Record(); VBD.Record vbdr = new VBD.Record();
vbdr.VM = vm; vbdr.VM = vm;
vbdr.VDI = vdi; vbdr.VDI = vdi;

View File

@ -80,8 +80,10 @@ public class XenServerPoolVms {
public String toString() { public String toString() {
StringBuilder sbuf = new StringBuilder("PoolVms="); StringBuilder sbuf = new StringBuilder("PoolVms=");
for (HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>> clusterVM : _clusterVms.values()) { for (HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>> clusterVM : _clusterVms.values()) {
for (String vmname : clusterVM.keySet()) { for (Map.Entry<String,Pair<String,State>> entry: clusterVM.entrySet()) {
sbuf.append(vmname).append("-").append(clusterVM.get(vmname).second()).append(","); String vmname = entry.getKey();
Pair<String,State> vmstate= entry.getValue();
sbuf.append(vmname).append("-").append(vmstate.second()).append(",");
} }
} }
return sbuf.toString(); return sbuf.toString();

View File

@ -677,11 +677,13 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
// NetScaler can only act as Lb and Static Nat service provider // NetScaler can only act as Lb and Static Nat service provider
if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) { if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) {
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported.");
String servicesList = "";
StringBuffer buff = new StringBuffer();
for (Service service : services) { for (Service service : services) {
servicesList += service.getName() + " "; buff.append(service.getName());
buff.append(" ");
} }
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + servicesList + " is not supported."); s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + buff.toString() + " is not supported.");
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported.");
return false; return false;
} }

View File

@ -1763,14 +1763,14 @@ public class NetscalerResource implements ServerResource {
} }
private static String genGslbObjectName(Object... args) { private static String genGslbObjectName(Object... args) {
String objectName = ""; StringBuffer buff = new StringBuffer();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
objectName += args[i]; buff.append(args[i]);
if (i != args.length - 1) { if (i != args.length - 1) {
objectName += "-"; buff.append("-");
} }
} }
return objectName; return buff.toString();
} }
} }
@ -3767,14 +3767,14 @@ public class NetscalerResource implements ServerResource {
} }
private String genObjectName(Object... args) { private String genObjectName(Object... args) {
String objectName = ""; StringBuffer buff = new StringBuffer();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
objectName += args[i]; buff.append(args[i]);
if (i != args.length - 1) { if (i != args.length - 1) {
objectName += _objectNamePathSep; buff.append(_objectNamePathSep);
} }
} }
return objectName; return buff.toString();
} }
@Override @Override

View File

@ -155,7 +155,7 @@ public class LDAPConfigCmd extends BaseCmd {
} }
public Integer getPort() { public Integer getPort() {
return port <= 0 ? 389 : port; return (Integer)(port.intValue() <= 0 ? 389 : port.intValue());
} }
public void setPort(Integer port) { public void setPort(Integer port) {

View File

@ -1906,7 +1906,8 @@ public class ApiResponseHelper implements ResponseGenerator {
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId()); Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>(); List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
if (serviceCapabilitiesMap != null) { if (serviceCapabilitiesMap != null) {
for (Service service : serviceCapabilitiesMap.keySet()) { for (Map.Entry<Service, Map<Capability, String>>entry : serviceCapabilitiesMap.entrySet()) {
Service service = entry.getKey();
ServiceResponse serviceResponse = new ServiceResponse(); ServiceResponse serviceResponse = new ServiceResponse();
// skip gateway service // skip gateway service
if (service == Service.Gateway) { if (service == Service.Gateway) {
@ -1916,11 +1917,12 @@ public class ApiResponseHelper implements ResponseGenerator {
// set list of capabilities for the service // set list of capabilities for the service
List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>(); List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
Map<Capability, String> serviceCapabilities = serviceCapabilitiesMap.get(service); Map<Capability, String> serviceCapabilities = entry.getValue();
if (serviceCapabilities != null) { if (serviceCapabilities != null) {
for (Capability capability : serviceCapabilities.keySet()) { for (Map.Entry<Capability,String> ser_cap_entries : serviceCapabilities.entrySet()) {
Capability capability = ser_cap_entries.getKey();
CapabilityResponse capabilityResponse = new CapabilityResponse(); CapabilityResponse capabilityResponse = new CapabilityResponse();
String capabilityValue = serviceCapabilities.get(capability); String capabilityValue = ser_cap_entries.getValue();
capabilityResponse.setName(capability.getName()); capabilityResponse.setName(capability.getName());
capabilityResponse.setValue(capabilityValue); capabilityResponse.setValue(capabilityValue);
capabilityResponse.setObjectName("capability"); capabilityResponse.setObjectName("capability");
@ -2605,7 +2607,9 @@ public class ApiResponseHelper implements ResponseGenerator {
Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId()); Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>(); List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
for (Service service : serviceProviderMap.keySet()) { for (Map.Entry<Service,Set<Provider>>entry : serviceProviderMap.entrySet()) {
Service service = entry.getKey();
Set<Provider> serviceProviders = entry.getValue();
ServiceResponse svcRsp = new ServiceResponse(); ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service // skip gateway service
if (service == Service.Gateway) { if (service == Service.Gateway) {
@ -2613,7 +2617,7 @@ public class ApiResponseHelper implements ResponseGenerator {
} }
svcRsp.setName(service.getName()); svcRsp.setName(service.getName());
List<ProviderResponse> providers = new ArrayList<ProviderResponse>(); List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
for (Provider provider : serviceProviderMap.get(service)) { for (Provider provider : serviceProviders) {
if (provider != null) { if (provider != null) {
ProviderResponse providerRsp = new ProviderResponse(); ProviderResponse providerRsp = new ProviderResponse();
providerRsp.setName(provider.getName()); providerRsp.setName(provider.getName());

View File

@ -652,7 +652,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
// save the scheduled event // save the scheduled event
final Long eventId = final Long eventId =
ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? (Long)User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(),
asyncCmd.getEventDescription(), asyncCmd.isDisplay(), startEventId); asyncCmd.getEventDescription(), asyncCmd.isDisplay(), startEventId);
if (startEventId == 0) { if (startEventId == 0) {
// There was no create event before, set current event id as start eventId // There was no create event before, set current event id as start eventId

View File

@ -33,6 +33,7 @@ import java.util.regex.Matcher;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity;
@ -229,9 +230,10 @@ public class ParamProcessWorker implements DispatchWorker {
if (!entitiesToAccess.isEmpty()) { if (!entitiesToAccess.isEmpty()) {
// check that caller can access the owner account. // check that caller can access the owner account.
_accountMgr.checkAccess(caller, null, true, owner); _accountMgr.checkAccess(caller, null, true, owner);
for (Object entity : entitiesToAccess.keySet()) { for (Map.Entry<Object,AccessType>entry : entitiesToAccess.entrySet()) {
Object entity = entry.getKey();
if (entity instanceof ControlledEntity) { if (entity instanceof ControlledEntity) {
_accountMgr.checkAccess(caller, entitiesToAccess.get(entity), true, (ControlledEntity) entity); _accountMgr.checkAccess(caller, entry.getValue(), true, (ControlledEntity) entity);
} else if (entity instanceof InfrastructureEntity) { } else if (entity instanceof InfrastructureEntity) {
// FIXME: Move this code in adapter, remove code from // FIXME: Move this code in adapter, remove code from
// Account manager // Account manager

View File

@ -33,7 +33,8 @@ public class ParamUnpackWorker implements DispatchWorker {
public void handle(final DispatchTask task) throws ServerApiException { public void handle(final DispatchTask task) throws ServerApiException {
final Map<String, Object> lowercaseParams = new HashMap<String, Object>(); final Map<String, Object> lowercaseParams = new HashMap<String, Object>();
final Map<String, String> params = task.getParams(); final Map<String, String> params = task.getParams();
for (final String key : params.keySet()) { for (final Map.Entry<String,String> entry : params.entrySet()) {
final String key = entry.getKey();
final int arrayStartIndex = key.indexOf('['); final int arrayStartIndex = key.indexOf('[');
final int arrayStartLastIndex = key.lastIndexOf('['); final int arrayStartLastIndex = key.lastIndexOf('[');
if (arrayStartIndex != arrayStartLastIndex) { if (arrayStartIndex != arrayStartLastIndex) {
@ -99,11 +100,11 @@ public class ParamUnpackWorker implements DispatchWorker {
} }
// we are ready to store the value for a particular field into the map for this object // we are ready to store the value for a particular field into the map for this object
mapValue.put(fieldName, params.get(key)); mapValue.put(fieldName, entry.getValue());
lowercaseParams.put(paramName, mapArray); lowercaseParams.put(paramName, mapArray);
} else { } else {
lowercaseParams.put(key.toLowerCase(), params.get(key)); lowercaseParams.put(key.toLowerCase(), entry.getValue());
} }
} }

View File

@ -857,10 +857,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
SearchCriteria<UserVmJoinVO> tagSc = _userVmJoinDao.createSearchCriteria(); SearchCriteria<UserVmJoinVO> tagSc = _userVmJoinDao.createSearchCriteria();
for (String key : tags.keySet()) { for (Map.Entry<String,String> entry : tags.entrySet()) {
SearchCriteria<UserVmJoinVO> tsc = _userVmJoinDao.createSearchCriteria(); SearchCriteria<UserVmJoinVO> tsc = _userVmJoinDao.createSearchCriteria();
tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key); tsc.addAnd("tagKey", SearchCriteria.Op.EQ,entry.getKey());
tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key)); tsc.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc); tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc);
} }
sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc); sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc);
@ -2739,9 +2739,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
if (resourceTags != null && !resourceTags.isEmpty()) { if (resourceTags != null && !resourceTags.isEmpty()) {
int count = 0; int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Zone.toString()); sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Zone.toString());
for (String key : resourceTags.keySet()) { for (Map.Entry<String,String> entry : resourceTags.entrySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), resourceTags.get(key)); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
count++; count++;
} }
} }
@ -2859,7 +2859,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
VMTemplateVO template = null; VMTemplateVO template = null;
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending); isAscending = (isAscending == null ? Boolean.TRUE : isAscending);
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, startIndex, pageSize); Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, startIndex, pageSize);
SearchBuilder<TemplateJoinVO> sb = _templateJoinDao.createSearchBuilder(); SearchBuilder<TemplateJoinVO> sb = _templateJoinDao.createSearchBuilder();
@ -2999,10 +2999,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
// add tags criteria // add tags criteria
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria(); SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
for (String key : tags.keySet()) { for (Map.Entry<String,String>entry : tags.entrySet()) {
SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria(); SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria();
scTag.addAnd("tagKey", SearchCriteria.Op.EQ, key); scTag.addAnd("tagKey", SearchCriteria.Op.EQ, entry.getKey());
scTag.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key)); scTag.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
if (isIso) { if (isIso) {
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.ISO); scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.ISO);
} else { } else {

View File

@ -380,7 +380,7 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
} }
// query details by batches // query details by batches
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? true : isAscending); isAscending = (isAscending == null ? Boolean.TRUE : isAscending);
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, null, null); Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, null, null);
List<TemplateJoinVO> uvList = new ArrayList<TemplateJoinVO>(); List<TemplateJoinVO> uvList = new ArrayList<TemplateJoinVO>();
// query details by batches // query details by batches

View File

@ -4004,9 +4004,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
void validateConnectivityServiceCapablities(Set<Provider> providers, Map<Capability, String> connectivityServiceCapabilityMap) { void validateConnectivityServiceCapablities(Set<Provider> providers, Map<Capability, String> connectivityServiceCapabilityMap) {
if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) { if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
for (Capability capability: connectivityServiceCapabilityMap.keySet()) { for (Map.Entry<Capability, String>entry: connectivityServiceCapabilityMap.entrySet()) {
Capability capability = entry.getKey();
if (capability == Capability.StretchedL2Subnet) { if (capability == Capability.StretchedL2Subnet) {
String value = connectivityServiceCapabilityMap.get(capability).toLowerCase(); String value = entry.getValue().toLowerCase();
if (!(value.contains("true") ^ value.contains("false"))) { if (!(value.contains("true") ^ value.contains("false"))) {
throw new InvalidParameterValueException("Invalid value (" + value + ") for " + capability + throw new InvalidParameterValueException("Invalid value (" + value + ") for " + capability +
" should be true/false"); " should be true/false");

View File

@ -1693,9 +1693,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
int count = 0; int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Network.toString()); sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Network.toString());
for (String key : tags.keySet()) { for ( Map.Entry<String,String> entry: tags.entrySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
count++; count++;
} }
} }

View File

@ -1051,9 +1051,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
int count = 0; int count = 0;
sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Vpc.toString()); sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Vpc.toString());
for (String key : tags.keySet()) { for (Map.Entry<String,String>entry : tags.entrySet()) {
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
count++; count++;
} }
} }

View File

@ -1248,9 +1248,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
defaultVpcNetworkOfferingProvidersNoLB.put(Service.PortForwarding, Provider.VPCVirtualRouter); defaultVpcNetworkOfferingProvidersNoLB.put(Service.PortForwarding, Provider.VPCVirtualRouter);
defaultVpcNetworkOfferingProvidersNoLB.put(Service.Vpn, Provider.VPCVirtualRouter); defaultVpcNetworkOfferingProvidersNoLB.put(Service.Vpn, Provider.VPCVirtualRouter);
for (Service service : defaultVpcNetworkOfferingProvidersNoLB.keySet()) { for (Map.Entry<Service,Provider> entry : defaultVpcNetworkOfferingProvidersNoLB.entrySet()) {
NetworkOfferingServiceMapVO offService = NetworkOfferingServiceMapVO offService =
new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), service, defaultVpcNetworkOfferingProvidersNoLB.get(service)); new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), entry.getKey(), entry.getValue());
_ntwkOfferingServiceMapDao.persist(offService); _ntwkOfferingServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService); s_logger.trace("Added service for the network offering: " + offService);
} }

View File

@ -912,15 +912,17 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
AutoScalePolicyVO policyVo = _asPolicyDao.findById(gpMap.getPolicyId()); AutoScalePolicyVO policyVo = _asPolicyDao.findById(gpMap.getPolicyId());
Integer duration = policyVo.getDuration(); Integer duration = policyVo.getDuration();
//get collection of counter name //get collection of counter name
String counterNames = "";
StringBuffer buff = new StringBuffer();
List<AutoScalePolicyConditionMapVO> lstPCmap = _asConditionMapDao.findByPolicyId(policyVo.getId()); List<AutoScalePolicyConditionMapVO> lstPCmap = _asConditionMapDao.findByPolicyId(policyVo.getId());
for (AutoScalePolicyConditionMapVO pcMap : lstPCmap) { for (AutoScalePolicyConditionMapVO pcMap : lstPCmap) {
String counterName = getCounternamebyCondition(pcMap.getConditionId()); String counterName = getCounternamebyCondition(pcMap.getConditionId());
buff.append(counterName);
counterNames += counterName + "," + pcMap.getConditionId(); buff.append(",");
buff.append(pcMap.getConditionId());
} }
// add to result // add to result
Pair<String, Integer> pair = new Pair<String, Integer>(counterNames, duration); Pair<String, Integer> pair = new Pair<String, Integer>(buff.toString(), duration);
result.add(pair); result.add(pair);
} }

View File

@ -820,7 +820,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (!shrinkOk) { if (!shrinkOk) {
/* Check resource limit for this account on primary storage resource */ /* Check resource limit for this account on primary storage resource */
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(newSize _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()), ResourceType.primary_storage, volume.isDisplayVolume(), new Long(newSize
- currentSize)); - currentSize).longValue());
} }
/* If this volume has never been beyond allocated state, short circuit everything and simply update the database */ /* If this volume has never been beyond allocated state, short circuit everything and simply update the database */
@ -1667,7 +1667,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
// retrieve the migrated new volume from job result // retrieve the migrated new volume from job result
if (jobResult != null && jobResult instanceof Long) { if (jobResult != null && jobResult instanceof Long) {
return _entityMgr.findById(VolumeVO.class, ((Long)jobResult).longValue()); return _entityMgr.findById(VolumeVO.class, ((Long)jobResult));
} }
return null; return null;
} }

View File

@ -1079,7 +1079,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
try { try {
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot); _resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize())); _resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()).longValue());
} catch (ResourceAllocationException e) { } catch (ResourceAllocationException e) {
if (snapshotType != Type.MANUAL) { if (snapshotType != Type.MANUAL) {
String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots"; String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots";

View File

@ -363,7 +363,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
Account account = CallContext.current().getCallingAccount(); Account account = CallContext.current().getCallingAccount();
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); VMTemplateVO template = _tmpltDao.findById(templateId);
if (template == null) { if (template == null) {
throw new InvalidParameterValueException("unable to find template with id " + templateId); throw new InvalidParameterValueException("unable to find template with id " + templateId);
} }
@ -388,7 +388,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
Long userId = CallContext.current().getCallingUserId(); Long userId = CallContext.current().getCallingUserId();
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); VMTemplateVO template = _tmpltDao.findById(templateId);
if (template == null) { if (template == null) {
throw new InvalidParameterValueException("unable to find template with id " + templateId); throw new InvalidParameterValueException("unable to find template with id " + templateId);
} }
@ -402,7 +402,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
Account account = CallContext.current().getCallingAccount(); Account account = CallContext.current().getCallingAccount();
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
VMTemplateVO template = _tmpltDao.findById(templateId.longValue()); VMTemplateVO template = _tmpltDao.findById(templateId);
if (template == null) { if (template == null) {
throw new InvalidParameterValueException("unable to find iso with id " + templateId); throw new InvalidParameterValueException("unable to find iso with id " + templateId);
} }

View File

@ -381,8 +381,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
if (isISO) { if (isISO) {
desc = Upload.Type.ISO.toString(); desc = Upload.Type.ISO.toString();
} }
eventId = eventId == null ? 0 : eventId;
if (!_accountMgr.isRootAdmin(caller.getId()) && _disableExtraction) { if (!_accountMgr.isRootAdmin(caller.getId()) && _disableExtraction) {
throw new PermissionDeniedException("Extraction has been disabled by admin"); throw new PermissionDeniedException("Extraction has been disabled by admin");
} }
@ -628,7 +626,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId); TemplateDataStoreVO srcTmpltStore = _tmplStoreDao.findByStoreTemplate(srcSecStore.getId(), tmpltId);
_resourceLimitMgr.checkResourceLimit(account, ResourceType.template); _resourceLimitMgr.checkResourceLimit(account, ResourceType.template);
_resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize())); _resourceLimitMgr.checkResourceLimit(account, ResourceType.secondary_storage, new Long(srcTmpltStore.getSize()).longValue());
// Event details // Event details
String copyEventType; String copyEventType;
@ -1593,7 +1591,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
} }
_resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.template); _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.template);
_resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize())); _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize()).longValue());
if (!isAdmin || featured == null) { if (!isAdmin || featured == null) {
featured = Boolean.FALSE; featured = Boolean.FALSE;