Repository: cloudstack Updated Branches: refs/heads/master 7d3f381d9 -> 4523490d4
Fixed Coverity Issues reported Signed-off-by: Santhosh Edukulla <santhosh.eduku...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4523490d Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4523490d Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4523490d Branch: refs/heads/master Commit: 4523490d44160b054de9e943f72db1d0ce06054a Parents: 7d3f381 Author: Santhosh Edukulla <santhosh.eduku...@gmail.com> Authored: Mon Jul 21 20:49:03 2014 +0530 Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com> Committed: Tue Jul 22 18:03:36 2014 +0530 ---------------------------------------------------------------------- .../api/command/user/vm/DeployVMCmd.java | 4 +- .../storage/dao/VMTemplatePoolDaoImpl.java | 67 ++++-------- .../com/cloud/upgrade/dao/Upgrade440to450.java | 5 +- .../endpoint/DefaultEndPointSelector.java | 28 ++--- .../storage/volume/VolumeServiceImpl.java | 5 +- .../kvm/resource/BridgeVifDriver.java | 24 ++--- server/src/com/cloud/api/ApiResponseHelper.java | 76 ++++++++------ .../src/com/cloud/api/doc/ApiXmlDocWriter.java | 25 +++-- .../com/cloud/resource/ResourceManagerImpl.java | 21 ++-- .../cloud/server/ConfigurationServerImpl.java | 6 +- utils/src/com/cloud/utils/nio/NioClient.java | 104 ++++++++++--------- 11 files changed, 172 insertions(+), 193 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 1beb595..14b703c 100755 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -225,8 +225,8 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd { Iterator iter = parameterCollection.iterator(); while (iter.hasNext()) { HashMap<String, String> value = (HashMap<String, String>)iter.next(); - for (String key : value.keySet()) { - customparameterMap.put(key, value.get(key)); + for (Map.Entry<String,String> entry: value.entrySet()) { + customparameterMap.put(entry.getKey(),entry.getValue()); } } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java index 12a0921..aacd4ff 100644 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java @@ -18,7 +18,6 @@ package com.cloud.storage.dao; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -170,36 +169,25 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV @Override public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>(); - ResultSet rs = null; - try { - String sql = DOWNLOADS_STATE_DC_POD; - pstmt = txn.prepareStatement(sql); - + String sql = DOWNLOADS_STATE_DC_POD; + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { pstmt.setLong(1, datacenterId); pstmt.setLong(2, podId); pstmt.setLong(3, templateId); pstmt.setString(4, downloadState.toString()); - rs = pstmt.executeQuery(); - while (rs.next()) { - // result.add(toEntityBean(rs, false)); TODO: this is buggy in - // GenericDaoBase for hand constructed queries - long id = rs.getLong(1); // ID column - result.add(findById(id)); + try(ResultSet rs = pstmt.executeQuery();) { + while (rs.next()) { + // result.add(toEntityBean(rs, false)); TODO: this is buggy in + // GenericDaoBase for hand constructed queries + long id = rs.getLong(1); // ID column + result.add(findById(id)); + } + }catch (Exception e) { + s_logger.warn("Exception: ", e); } } catch (Exception e) { s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } } return result; @@ -207,34 +195,23 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase<VMTemplateStoragePoolV public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - PreparedStatement pstmt = null; List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>(); - ResultSet rs = null; - try { - String sql = HOST_TEMPLATE_SEARCH; - pstmt = txn.prepareStatement(sql); - + String sql = HOST_TEMPLATE_SEARCH; + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { pstmt.setLong(1, hostId); pstmt.setLong(2, templateId); - rs = pstmt.executeQuery(); - while (rs.next()) { - // result.add(toEntityBean(rs, false)); TODO: this is buggy in - // GenericDaoBase for hand constructed queries - long id = rs.getLong(1); // ID column - result.add(findById(id)); + try(ResultSet rs = pstmt.executeQuery();) { + while (rs.next()) { + // result.add(toEntityBean(rs, false)); TODO: this is buggy in + // GenericDaoBase for hand constructed queries + long id = rs.getLong(1); // ID column + result.add(findById(id)); + } + }catch (Exception e) { + s_logger.warn("Exception: ", e); } } catch (Exception e) { s_logger.warn("Exception: ", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } } return result; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/engine/schema/src/com/cloud/upgrade/dao/Upgrade440to450.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade440to450.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade440to450.java index caf3b42..aad5162 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade440to450.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade440to450.java @@ -22,6 +22,7 @@ import java.sql.Connection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; @@ -80,8 +81,8 @@ public class Upgrade440to450 implements DbUpgrade { uniqueKeys.put("storage_pool", keys); s_logger.debug("Droping id_2 key from storage_pool table"); - for (String tableName : uniqueKeys.keySet()) { - DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), false); + for (Map.Entry<String, List<String>> entry: uniqueKeys.entrySet()) { + DbUpgradeUtils.dropKeysIfExist(conn,entry.getKey(), entry.getValue(), false); } } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java index f06b43e..0a867f6 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java +++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java @@ -115,33 +115,21 @@ public class DefaultEndPointSelector implements EndPointSelector { // TODO: order by rand() is slow if there are lot of hosts sbuilder.append(" ORDER by rand() limit 1"); String sql = sbuilder.toString(); - PreparedStatement pstmt = null; - ResultSet rs = null; HostVO host = null; TransactionLegacy txn = TransactionLegacy.currentTxn(); - - try { - pstmt = txn.prepareStatement(sql); + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { pstmt.setLong(1, poolId); - rs = pstmt.executeQuery(); - while (rs.next()) { - long id = rs.getLong(1); - host = hostDao.findById(id); + try(ResultSet rs = pstmt.executeQuery();) { + while (rs.next()) { + long id = rs.getLong(1); + host = hostDao.findById(id); + } + }catch (SQLException e) { + s_logger.warn("can't find endpoint", e); } } catch (SQLException e) { s_logger.warn("can't find endpoint", e); - } finally { - try { - if (rs != null) { - rs.close(); - } - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { - } } - if (host == null) { return null; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 3fc43ea..821c939 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -1464,8 +1464,9 @@ public class VolumeServiceImpl implements VolumeService { } // Delete volumes which are not present on DB. - for (Long uniqueName : volumeInfos.keySet()) { - TemplateProp tInfo = volumeInfos.get(uniqueName); + for (Map.Entry<Long,TemplateProp> entry : volumeInfos.entrySet()) { + Long uniqueName = entry.getKey(); + TemplateProp tInfo = entry.getValue(); //we cannot directly call expungeVolumeAsync here to // reuse delete logic since in this case, our db does not have http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java index e684b8d..3b034bb 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java @@ -104,16 +104,16 @@ public class BridgeVifDriver extends VifDriverBase { String trafficLabel = nic.getName(); if (nic.getType() == Networks.TrafficType.Guest) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; - if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan && !vNetId.equalsIgnoreCase("untagged") || - nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) { - if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); - String brName = createVnetBr(vNetId, trafficLabel, protocol); - intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); - } else { - String brName = createVnetBr(vNetId, "private", protocol); - intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); - } + if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || + (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) { + if (trafficLabel != null && !trafficLabel.isEmpty()) { + s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); + String brName = createVnetBr(vNetId, trafficLabel, protocol); + intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); + } else { + String brName = createVnetBr(vNetId, "private", protocol); + intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); + } } else { intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } @@ -123,8 +123,8 @@ public class BridgeVifDriver extends VifDriverBase { intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter)); } else if (nic.getType() == Networks.TrafficType.Public) { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; - if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan && !vNetId.equalsIgnoreCase("untagged") || - nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan) { + if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || + (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/server/src/com/cloud/api/ApiResponseHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 013da0b..70ed47d 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1026,20 +1026,24 @@ public class ApiResponseHelper implements ResponseGenerator { IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId()); - response.setPublicIpAddressId(ip.getUuid()); - response.setPublicIpAddress(ip.getAddress().addr()); - if (ip != null && fwRule.getDestinationIpAddress() != null) { - response.setDestNatVmIp(fwRule.getDestinationIpAddress().toString()); - UserVm vm = ApiDBUtils.findUserVmById(fwRule.getVirtualMachineId()); - if (vm != null) { - response.setVirtualMachineId(vm.getUuid()); - response.setVirtualMachineName(vm.getHostName()); + if (ip != null) + { + response.setPublicIpAddressId(ip.getUuid()); + response.setPublicIpAddress(ip.getAddress().addr()); + if (fwRule.getDestinationIpAddress() != null) + { + response.setDestNatVmIp(fwRule.getDestinationIpAddress().toString()); + UserVm vm = ApiDBUtils.findUserVmById(fwRule.getVirtualMachineId()); + if (vm != null) { + response.setVirtualMachineId(vm.getUuid()); + response.setVirtualMachineName(vm.getHostName()); - if (vm.getDisplayName() != null) { - response.setVirtualMachineDisplayName(vm.getDisplayName()); - } else { - response.setVirtualMachineDisplayName(vm.getHostName()); + if (vm.getDisplayName() != null) { + response.setVirtualMachineDisplayName(vm.getDisplayName()); + } else { + response.setVirtualMachineDisplayName(vm.getHostName()); + } } } } @@ -1071,18 +1075,20 @@ public class ApiResponseHelper implements ResponseGenerator { response.setProtocol(fwRule.getProtocol()); IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId()); - response.setPublicIpAddressId(ip.getId()); - response.setPublicIpAddress(ip.getAddress().addr()); - - if (ip != null && fwRule.getDestIpAddress() != null) { - UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId()); - if (vm != null) {// vm might be destroyed - response.setVirtualMachineId(vm.getUuid()); - response.setVirtualMachineName(vm.getHostName()); - if (vm.getDisplayName() != null) { - response.setVirtualMachineDisplayName(vm.getDisplayName()); - } else { - response.setVirtualMachineDisplayName(vm.getHostName()); + + if (ip != null) { + response.setPublicIpAddressId(ip.getId()); + response.setPublicIpAddress(ip.getAddress().addr()); + if (fwRule.getDestIpAddress() != null) { + UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId()); + if (vm != null) {// vm might be destroyed + response.setVirtualMachineId(vm.getUuid()); + response.setVirtualMachineName(vm.getHostName()); + if (vm.getDisplayName() != null) { + response.setVirtualMachineDisplayName(vm.getDisplayName()); + } else { + response.setVirtualMachineDisplayName(vm.getHostName()); + } } } } @@ -1701,7 +1707,9 @@ public class ApiResponseHelper implements ResponseGenerator { Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId()); 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> srvc_providers = entry.getValue(); ServiceResponse svcRsp = new ServiceResponse(); // skip gateway service if (service == Service.Gateway) { @@ -1709,7 +1717,7 @@ public class ApiResponseHelper implements ResponseGenerator { } svcRsp.setName(service.getName()); List<ProviderResponse> providers = new ArrayList<ProviderResponse>(); - for (Provider provider : serviceProviderMap.get(service)) { + for (Provider provider : srvc_providers) { if (provider != null) { ProviderResponse providerRsp = new ProviderResponse(); providerRsp.setName(provider.getName()); @@ -1956,8 +1964,9 @@ public class ApiResponseHelper implements ResponseGenerator { Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId); if (domain != null) { response.setDomainId(domain.getUuid()); + response.setDomainName(domain.getName()); } - response.setDomainName(domain.getName()); + } response.setSpecifyIpRanges(network.getSpecifyIpRanges()); @@ -2563,7 +2572,10 @@ public class ApiResponseHelper implements ResponseGenerator { Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(offering.getId()); 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> srvc_providers = entry.getValue(); + ServiceResponse svcRsp = new ServiceResponse(); // skip gateway service if (service == Service.Gateway) { @@ -2571,7 +2583,7 @@ public class ApiResponseHelper implements ResponseGenerator { } svcRsp.setName(service.getName()); List<ProviderResponse> providers = new ArrayList<ProviderResponse>(); - for (Provider provider : serviceProviderMap.get(service)) { + for (Provider provider : srvc_providers) { if (provider != null) { ProviderResponse providerRsp = new ProviderResponse(); providerRsp.setName(provider.getName()); @@ -3114,7 +3126,6 @@ public class ApiResponseHelper implements ResponseGenerator { } else if (usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO) { //Template/ISO ID VMTemplateVO tmpl = _entityMgr.findByIdIncludingRemoved(VMTemplateVO.class, usageRecord.getUsageId().toString()); - usageRecResponse.setUsageId(tmpl.getUuid()); if (tmpl != null) { usageRecResponse.setUsageId(tmpl.getUuid()); } @@ -3389,10 +3400,11 @@ public class ApiResponseHelper implements ResponseGenerator { //set Lb instances information List<ApplicationLoadBalancerInstanceResponse> instanceResponses = new ArrayList<ApplicationLoadBalancerInstanceResponse>(); - for (Ip ip : lbInstances.keySet()) { + for (Map.Entry<Ip,UserVm> entry : lbInstances.entrySet()) { + Ip ip = entry.getKey(); + UserVm vm = entry.getValue(); ApplicationLoadBalancerInstanceResponse instanceResponse = new ApplicationLoadBalancerInstanceResponse(); instanceResponse.setIpAddress(ip.addr()); - UserVm vm = lbInstances.get(ip); instanceResponse.setId(vm.getUuid()); instanceResponse.setName(vm.getInstanceName()); instanceResponse.setObjectName("loadbalancerinstance"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/server/src/com/cloud/api/doc/ApiXmlDocWriter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index fe07056..6824185 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -144,10 +144,8 @@ public class ApiXmlDocWriter { } for (String fileName : fileNames) { - try { - FileInputStream in = new FileInputStream(fileName); + try(FileInputStream in = new FileInputStream(fileName);) { preProcessedCommands.load(in); - in.close(); } catch (FileNotFoundException ex) { System.out.println("Can't find file " + fileName); System.exit(2); @@ -595,14 +593,17 @@ public class ApiXmlDocWriter { addDir(files[i], out); continue; } - FileInputStream in = new FileInputStream(files[i].getPath()); - out.putNextEntry(new ZipEntry(files[i].getPath().substring(pathToDir.length()))); - int len; - while ((len = in.read(tmpBuf)) > 0) { - out.write(tmpBuf, 0, len); + try(FileInputStream in = new FileInputStream(files[i].getPath());) { + out.putNextEntry(new ZipEntry(files[i].getPath().substring(pathToDir.length()))); + int len; + while ((len = in.read(tmpBuf)) > 0) { + out.write(tmpBuf, 0, len); + } + out.closeEntry(); + }catch(IOException ex) + { + s_logger.error("addDir:Exception:"+ ex.getMessage(),ex); } - out.closeEntry(); - in.close(); } } @@ -619,8 +620,7 @@ public class ApiXmlDocWriter { private static void writeAlertTypes(String dirName) { XStream xs = new XStream(); xs.alias("alert", Alert.class); - try { - ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts"); + try(ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts");) { for (Field f : AlertManager.class.getFields()) { if (f.getClass().isAssignableFrom(Number.class)) { String name = f.getName().substring(11); @@ -628,7 +628,6 @@ public class ApiXmlDocWriter { out.writeObject(alert); } } - out.close(); } catch (IOException e) { s_logger.error("Failed to create output stream to write an alert types ", e); } catch (IllegalAccessException e) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 68c9286..6f089af 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -136,7 +136,6 @@ import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.user.Account; import com.cloud.user.AccountManager; -import com.cloud.user.User; import com.cloud.utils.StringUtils; import com.cloud.utils.UriUtils; import com.cloud.utils.component.Manager; @@ -323,29 +322,29 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, String eventName; for (ResourceListener l : lst) { - if (event == ResourceListener.EVENT_DISCOVER_BEFORE) { + if (event.equals(ResourceListener.EVENT_DISCOVER_BEFORE)) { l.processDiscoverEventBefore((Long)params[0], (Long)params[1], (Long)params[2], (URI)params[3], (String)params[4], (String)params[5], (List<String>)params[6]); eventName = "EVENT_DISCOVER_BEFORE"; - } else if (event == ResourceListener.EVENT_DISCOVER_AFTER) { + } else if (event.equals(ResourceListener.EVENT_DISCOVER_AFTER)) { l.processDiscoverEventAfter((Map<? extends ServerResource, Map<String, String>>)params[0]); eventName = "EVENT_DISCOVER_AFTER"; - } else if (event == ResourceListener.EVENT_DELETE_HOST_BEFORE) { + } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_BEFORE)) { l.processDeleteHostEventBefore((HostVO)params[0]); eventName = "EVENT_DELETE_HOST_BEFORE"; - } else if (event == ResourceListener.EVENT_DELETE_HOST_AFTER) { + } else if (event.equals(ResourceListener.EVENT_DELETE_HOST_AFTER)) { l.processDeletHostEventAfter((HostVO)params[0]); eventName = "EVENT_DELETE_HOST_AFTER"; - } else if (event == ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE) { + } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_BEFORE)) { l.processCancelMaintenaceEventBefore((Long)params[0]); eventName = "EVENT_CANCEL_MAINTENANCE_BEFORE"; - } else if (event == ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER) { + } else if (event.equals(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER)) { l.processCancelMaintenaceEventAfter((Long)params[0]); eventName = "EVENT_CANCEL_MAINTENANCE_AFTER"; - } else if (event == ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE) { + } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE)) { l.processPrepareMaintenaceEventBefore((Long)params[0]); eventName = "EVENT_PREPARE_MAINTENANCE_BEFORE"; - } else if (event == ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER) { + } else if (event.equals(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER)) { l.processPrepareMaintenaceEventAfter((Long)params[0]); eventName = "EVENT_PREPARE_MAINTENANCE_AFTER"; } else { @@ -798,7 +797,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @DB protected boolean doDeleteHost(final long hostId, boolean isForced, final boolean isForceDeleteStorage) { - User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); + _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); // Verify that host exists final HostVO host = _hostDao.findById(hostId); if (host == null) { @@ -1463,7 +1462,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, Map.Entry<String, ResourceStateAdapter> item = it.next(); ResourceStateAdapter adapter = item.getValue(); - String msg = new String("Dispatching resource state event " + event + " to " + item.getKey()); + String msg = "Dispatching resource state event " + event + " to " + item.getKey(); s_logger.debug(msg); if (event == ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_CONNECTED) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/server/src/com/cloud/server/ConfigurationServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 7c3b5a5..6e72d08 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -1221,9 +1221,9 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio defaultVpcNetworkOfferingProviders.put(Service.PortForwarding, Provider.VPCVirtualRouter); defaultVpcNetworkOfferingProviders.put(Service.Vpn, Provider.VPCVirtualRouter); - for (Service service : defaultVpcNetworkOfferingProviders.keySet()) { - NetworkOfferingServiceMapVO offService = - new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), service, defaultVpcNetworkOfferingProviders.get(service)); + for (Map.Entry<Service,Provider> entry : defaultVpcNetworkOfferingProviders.entrySet()) { + NetworkOfferingServiceMapVO offService = + new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), entry.getKey(), entry.getValue()); _ntwkOfferingServiceMapDao.persist(offService); s_logger.trace("Added service for the network offering: " + offService); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4523490d/utils/src/com/cloud/utils/nio/NioClient.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/nio/NioClient.java b/utils/src/com/cloud/utils/nio/NioClient.java index 34d03c2..db17b7a 100755 --- a/utils/src/com/cloud/utils/nio/NioClient.java +++ b/utils/src/com/cloud/utils/nio/NioClient.java @@ -48,61 +48,63 @@ public class NioClient extends NioConnection { @Override protected void init() throws IOException { _selector = Selector.open(); - SocketChannel sch = null; InetSocketAddress addr = null; - - try { - sch = SocketChannel.open(); - sch.configureBlocking(true); - s_logger.info("Connecting to " + _host + ":" + _port); - - if (_bindAddress != null) { - s_logger.info("Binding outbound interface at " + _bindAddress); - - addr = new InetSocketAddress(_bindAddress, 0); - sch.socket().bind(addr); + try(SocketChannel sch = SocketChannel.open();) { + try { + sch.configureBlocking(true); + s_logger.info("Connecting to " + _host + ":" + _port); + + if (_bindAddress != null) { + s_logger.info("Binding outbound interface at " + _bindAddress); + + addr = new InetSocketAddress(_bindAddress, 0); + sch.socket().bind(addr); + } + + addr = new InetSocketAddress(_host, _port); + sch.connect(addr); + } catch (IOException e) { + _selector.close(); + throw e; + } + SSLEngine sslEngine = null; + try { + // Begin SSL handshake in BLOCKING mode + sch.configureBlocking(true); + + SSLContext sslContext = Link.initSSLContext(true); + sslEngine = sslContext.createSSLEngine(_host, _port); + sslEngine.setUseClientMode(true); + + Link.doHandshake(sch, sslEngine, true); + s_logger.info("SSL: Handshake done"); + s_logger.info("Connected to " + _host + ":" + _port); + } catch (Exception e) { + _selector.close(); + throw new IOException("SSL: Fail to init SSL! " + e); } - addr = new InetSocketAddress(_host, _port); - sch.connect(addr); - } catch (IOException e) { - _selector.close(); - throw e; - } - - SSLEngine sslEngine = null; - try { - // Begin SSL handshake in BLOCKING mode - sch.configureBlocking(true); - - SSLContext sslContext = Link.initSSLContext(true); - sslEngine = sslContext.createSSLEngine(_host, _port); - sslEngine.setUseClientMode(true); - - Link.doHandshake(sch, sslEngine, true); - s_logger.info("SSL: Handshake done"); - s_logger.info("Connected to " + _host + ":" + _port); - } catch (Exception e) { - _selector.close(); - throw new IOException("SSL: Fail to init SSL! " + e); - } - - Task task = null; - try { - sch.configureBlocking(false); - Link link = new Link(addr, this); - link.setSSLEngine(sslEngine); - SelectionKey key = sch.register(_selector, SelectionKey.OP_READ); - link.setKey(key); - key.attach(link); - // Notice we've already connected due to the handshake, so let's get the - // remaining task done - task = _factory.create(Task.Type.CONNECT, link, null); - } catch (Exception e) { - _selector.close(); - throw new IOException("Fail to init NioClient! " + e); + Task task = null; + try { + sch.configureBlocking(false); + Link link = new Link(addr, this); + link.setSSLEngine(sslEngine); + SelectionKey key = sch.register(_selector, SelectionKey.OP_READ); + link.setKey(key); + key.attach(link); + // Notice we've already connected due to the handshake, so let's get the + // remaining task done + task = _factory.create(Task.Type.CONNECT, link, null); + } catch (Exception e) { + _selector.close(); + throw new IOException("Fail to init NioClient! " + e); + } + _executor.execute(task); + }catch(IOException ex) + { + s_logger.error("NioClient:init:Exception:"+ex.getMessage()); + throw new IOException("NioClient:init:Exception:"+ex.getMessage(),ex); } - _executor.execute(task); } @Override