From 5706041ef7fd73257ec0fb34dbe4bcd02b1ce204 Mon Sep 17 00:00:00 2001 From: prachi Date: Fri, 22 Apr 2011 18:54:16 -0700 Subject: [PATCH] Manual merge of Bug 9539 - cpu.overprovisioning.factor does not work Partial Changes: - Changed host allocators/planner to use cpu.overprovisioning.factor - Removed following: while adding a new host, we were setting the total_cpu in op_host_capacity to be actual_cpu * cpu.overprovisioning.factor. Now we set it to actual_cpu. - ListCapacities response now calculates the total CPU as actual * cpu.overprovisioning.factor (This change does not add anything new - listCapacities was pulling total CPU from op_host_capacity DB earlier which had the cpu.overprovisioning.factor applied already. Now we need to apply it over the DB entry.) - HostResponse has a new field: 'cpuWithOverprovisioning' that returns the cpu after applying the cpu.overprovisioning.factor - Db Upgrade 222 to 224 now updates the total_cpu in op_host_capacity to be the actual_cpu for each Routing host. Conflicts: server/src/com/cloud/agent/manager/AgentManagerImpl.java server/src/com/cloud/api/ApiDBUtils.java server/src/com/cloud/api/ApiResponseHelper.java server/src/com/cloud/deploy/BareMetalPlanner.java server/src/com/cloud/server/ManagementServerImpl.java --- .../com/cloud/api/response/HostResponse.java | 13 ++++- .../allocator/impl/FirstFitAllocator.java | 6 +-- server/src/com/cloud/api/ApiDBUtils.java | 11 +++++ .../src/com/cloud/api/ApiResponseHelper.java | 25 ++++++++-- .../com/cloud/capacity/CapacityManager.java | 2 +- .../cloud/capacity/CapacityManagerImpl.java | 48 ++++++++++++------ .../com/cloud/capacity/dao/CapacityDao.java | 4 +- .../cloud/capacity/dao/CapacityDaoImpl.java | 39 +++++++++------ .../src/com/cloud/deploy/FirstFitPlanner.java | 20 +++++--- .../cloud/upgrade/dao/Upgrade222to224.java | 49 +++++++++++++++++++ 10 files changed, 167 insertions(+), 50 deletions(-) diff --git a/api/src/com/cloud/api/response/HostResponse.java b/api/src/com/cloud/api/response/HostResponse.java index efa76355d55..cd8e7fb2126 100755 --- a/api/src/com/cloud/api/response/HostResponse.java +++ b/api/src/com/cloud/api/response/HostResponse.java @@ -80,6 +80,9 @@ public class HostResponse extends BaseResponse { @SerializedName("cpuused") @Param(description="the amount of the host's CPU currently used") private String cpuUsed; + + @SerializedName("cpuwithoverprovisioning") @Param(description="the amount of the host's CPU after applying the cpu.overprovisioning.factor ") + private String cpuWithOverprovisioning; @SerializedName("averageload") @Param(description="the cpu average load on the host") private Long averageLoad; @@ -486,5 +489,13 @@ public class HostResponse extends BaseResponse { public void setAllocationState(String allocationState) { this.allocationState = allocationState; - } + } + + public String getCpuWithOverprovisioning() { + return cpuWithOverprovisioning; + } + + public void setCpuWithOverprovisioning(String cpuWithOverprovisioning) { + this.cpuWithOverprovisioning = cpuWithOverprovisioning; + } } diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index 765e007bae2..a567ed4b5e6 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -162,7 +162,7 @@ public class FirstFitAllocator implements HostAllocator { boolean numCpusGood = host.getCpus().intValue() >= offering.getCpu(); int cpu_requested = offering.getCpu() * offering.getSpeed(); long ram_requested = offering.getRamSize() * 1024L * 1024L; - boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false); + boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, _factor); if (numCpusGood && hostHasCapacity) { if (s_logger.isDebugEnabled()) { @@ -304,10 +304,6 @@ public class FirstFitAllocator implements HostAllocator { Map configs = _configDao.getConfiguration(params); String opFactor = configs.get("cpu.overprovisioning.factor"); _factor = NumbersUtil.parseFloat(opFactor, 1); - //Over provisioning factor cannot be < 1. Reset to 1 in such cases - if (_factor < 1){ - _factor = 1; - } String allocationAlgorithm = configs.get("vm.allocation.algorithm"); if (allocationAlgorithm != null && (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("firstfit"))) { diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 987b13a84ae..6b51c6d68bf 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -7,8 +7,10 @@ import java.util.Map; import com.cloud.agent.AgentManager; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; +import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationService; import com.cloud.configuration.ResourceCount.ResourceType; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenterVO; @@ -85,6 +87,7 @@ import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.user.dao.UserStatisticsDao; import com.cloud.uservm.UserVm; +import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.ComponentLocator; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.InstanceGroupVO; @@ -138,6 +141,7 @@ public class ApiDBUtils { private static NetworkOfferingDao _networkOfferingDao; private static NetworkDao _networkDao; private static ConfigurationService _configMgr; + private static ConfigurationDao _configDao; static { _ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); @@ -181,6 +185,7 @@ public class ApiDBUtils { _networkGroupDao = locator.getDao(SecurityGroupDao.class); _networkOfferingDao = locator.getDao(NetworkOfferingDao.class); _networkDao = locator.getDao(NetworkDao.class); + _configDao = locator.getDao(ConfigurationDao.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -544,4 +549,10 @@ public class ApiDBUtils { return _networkMgr.getDedicatedNetworkDomain(networkId); } + public static float getCpuOverprovisioningFactor(){ + String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); + float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); + return cpuOverprovisioningFactor; + } + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 62ceec2dda9..bf076168d4a 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -518,6 +518,9 @@ public class ApiResponseHelper implements ResponseGenerator { } cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%"; hostResponse.setCpuAllocated(cpuAlloc); + + String cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor()).toString(); + hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning); } // calculate cpu utilized @@ -2078,6 +2081,9 @@ public class ApiResponseHelper implements ResponseGenerator { poolIdsToIgnore.add(pool.getId()); } } + + + float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); // collect all the capacity types, sum allocated/used and sum total...get one capacity number for each for (Capacity capacity : hostCapacities) { @@ -2096,11 +2102,17 @@ public class ApiResponseHelper implements ResponseGenerator { Long totalCapacity = totalCapacityMap.get(key); Long usedCapacity = usedCapacityMap.get(key); + + //reset overprovisioning factor to 1 + float overprovisioningFactor = 1; + if (capacityType == Capacity.CAPACITY_TYPE_CPU){ + overprovisioningFactor = cpuOverprovisioningFactor; + } if (totalCapacity == null) { - totalCapacity = new Long(capacity.getTotalCapacity()); + totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)); } else { - totalCapacity = new Long(capacity.getTotalCapacity() + totalCapacity); + totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity; } if (usedCapacity == null) { @@ -2120,10 +2132,15 @@ public class ApiResponseHelper implements ResponseGenerator { totalCapacity = totalCapacityMap.get(keyForPodTotal); usedCapacity = usedCapacityMap.get(keyForPodTotal); + overprovisioningFactor = 1; + if (capacityType == Capacity.CAPACITY_TYPE_CPU){ + overprovisioningFactor = cpuOverprovisioningFactor; + } + if (totalCapacity == null) { - totalCapacity = new Long(capacity.getTotalCapacity()); + totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)); } else { - totalCapacity = new Long(capacity.getTotalCapacity() + totalCapacity); + totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity; } if (usedCapacity == null) { diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/server/src/com/cloud/capacity/CapacityManager.java index 8bcd36e0ed4..5876c01732a 100644 --- a/server/src/com/cloud/capacity/CapacityManager.java +++ b/server/src/com/cloud/capacity/CapacityManager.java @@ -13,5 +13,5 @@ public interface CapacityManager extends Manager { void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost); - boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity); + boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor); } diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index 0d5989462cc..7ffebd2a1e4 100644 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -124,7 +124,13 @@ public class CapacityManagerImpl implements CapacityManager , StateListener { void clearStorageCapacities(); CapacityVO findByHostIdType(Long hostId, short capacityType); void clearNonStorageCapacities2(); - List orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone); - List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType); + List orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor); + List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor); } diff --git a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java index b3249e8d853..9b0f264b7f4 100755 --- a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -46,16 +46,16 @@ public class CapacityDaoImpl extends GenericDaoBase implements private static final String CLEAR_NON_STORAGE_CAPACITIES2 = "DELETE FROM `cloud`.`op_host_capacity` WHERE capacity_type<>2 AND capacity_type<>3 AND capacity_type<>6 AND capacity_type<>0 AND capacity_type<>1"; //clear non-storage and non-secondary_storage capacities private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1 = "SELECT DISTINCT cluster_id FROM `cloud`.`op_host_capacity` WHERE "; - private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND (total_capacity - used_capacity + reserved_capacity) >= ? " + + private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " + "AND cluster_id IN (SELECT distinct cluster_id FROM `cloud`.`op_host_capacity` WHERE "; - private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND (total_capacity - used_capacity + reserved_capacity) >= ?) " + - "ORDER BY (total_capacity - used_capacity + reserved_capacity) DESC"; + private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) " + + "ORDER BY ((total_capacity * ?) - used_capacity + reserved_capacity) DESC"; private SearchBuilder _hostIdTypeSearch; private SearchBuilder _hostOrPoolIdSearch; private static final String LIST_HOSTS_IN_CLUSTER_WITH_ENOUGH_CAPACITY = "SELECT a.host_id FROM (host JOIN op_host_capacity a ON host.id = a.host_id AND host.cluster_id = ? AND host.type = ? " + - "AND a.total_capacity - a.used_capacity >= ? and a.capacity_type = 1) " + + "AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " + "JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0"; public CapacityDaoImpl() { @@ -150,7 +150,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements } @Override - public List orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone){ + public List orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){ Transaction txn = Transaction.currentTxn(); PreparedStatement pstmt = null; List result = new ArrayList(); @@ -174,16 +174,22 @@ public class CapacityDaoImpl extends GenericDaoBase implements pstmt.setLong(1, id); if(capacityTypeForOrdering == CapacityVO.CAPACITY_TYPE_CPU){ pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU); - pstmt.setLong(3, requiredCpu); - pstmt.setLong(4, id); - pstmt.setShort(5, CapacityVO.CAPACITY_TYPE_MEMORY); - pstmt.setLong(6, requiredRam); + pstmt.setFloat(3, cpuOverprovisioningFactor); + pstmt.setLong(4, requiredCpu); + pstmt.setLong(5, id); + pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY); + pstmt.setFloat(7, 1); + pstmt.setLong(8, requiredRam); + pstmt.setFloat(9, cpuOverprovisioningFactor); }else{ pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_MEMORY); - pstmt.setLong(3, requiredRam); - pstmt.setLong(4, id); - pstmt.setShort(5, CapacityVO.CAPACITY_TYPE_CPU); - pstmt.setLong(6, requiredCpu); + pstmt.setFloat(3, 1); + pstmt.setLong(4, requiredRam); + pstmt.setLong(5, id); + pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_CPU); + pstmt.setFloat(7, cpuOverprovisioningFactor); + pstmt.setLong(8, requiredCpu); + pstmt.setFloat(9, 1); } ResultSet rs = pstmt.executeQuery(); @@ -200,7 +206,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements @Override - public List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType){ + public List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor){ Transaction txn = Transaction.currentTxn(); PreparedStatement pstmt = null; List result = new ArrayList(); @@ -210,8 +216,9 @@ public class CapacityDaoImpl extends GenericDaoBase implements pstmt = txn.prepareAutoCloseStatement(sql.toString()); pstmt.setLong(1, clusterId); pstmt.setString(2, hostType); - pstmt.setLong(3, requiredCpu); - pstmt.setLong(4, requiredRam); + pstmt.setFloat(3, cpuOverprovisioningFactor); + pstmt.setLong(4, requiredCpu); + pstmt.setLong(5, requiredRam); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index c62706fdfae..bbaf6ae9ccf 100644 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -48,6 +48,7 @@ import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Inject; @@ -95,6 +96,10 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { int cpu_requested = offering.getCpu() * offering.getSpeed(); long ram_requested = offering.getRamSize() * 1024L * 1024L; + String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); + float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); + + s_logger.debug("In FirstFitPlanner:: plan"); s_logger.debug("Trying to allocate a host and storage pools from dc:" + plan.getDataCenterId() + ", pod:" + plan.getPodId() + ",cluster:" + plan.getClusterId() + @@ -145,7 +150,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { if (host.getStatus() == Status.Up && host.getHostAllocationState() == Host.HostAllocationState.Enabled) { //check zone/pod/cluster are enabled if(isEnabledForAllocation(vm.getDataCenterId(), vm.getPodId(), host.getClusterId())){ - if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true)){ + if(_capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, true, cpuOverprovisioningFactor)){ s_logger.debug("The last host of this VM is UP and has enough capacity"); s_logger.debug("Now checking for suitable pools under zone: "+vm.getDataCenterId() +", pod: "+ vm.getPodId()+", cluster: "+ host.getClusterId()); //search for storage under the zone, pod, cluster of the last host. @@ -203,7 +208,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { HostPodVO pod = _podDao.findById(podIdSpecified); if (pod != null) { //list clusters under this pod by cpu and ram capacity - clusterList = listClustersByCapacity(podIdSpecified, cpu_requested, ram_requested, avoid, false); + clusterList = listClustersByCapacity(podIdSpecified, cpu_requested, ram_requested, avoid, false, cpuOverprovisioningFactor); if(!clusterList.isEmpty()){ if(avoid.getClustersToAvoid() != null){ if (s_logger.isDebugEnabled()) { @@ -241,7 +246,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { //consider all clusters under this zone. s_logger.debug("Searching all possible resources under this Zone: "+ plan.getDataCenterId()); //list clusters under this zone by cpu and ram capacity - List prioritizedClusterIds = listClustersByCapacity(plan.getDataCenterId(), cpu_requested, ram_requested, avoid, true); + List prioritizedClusterIds = listClustersByCapacity(plan.getDataCenterId(), cpu_requested, ram_requested, avoid, true, cpuOverprovisioningFactor); if(!prioritizedClusterIds.isEmpty()){ if(avoid.getClustersToAvoid() != null){ if (s_logger.isDebugEnabled()) { @@ -420,7 +425,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { return prioritizedPods; } - protected List listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone){ + protected List listClustersByCapacity(long id, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone, float cpuOverprovisioningFactor){ //look at the aggregate available cpu and ram per cluster //although an aggregate value may be false indicator that a cluster can host a vm, it will at the least eliminate those clusters which definitely cannot @@ -433,8 +438,11 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { if("RAM".equalsIgnoreCase(capacityTypeToOrder)){ capacityType = CapacityVO.CAPACITY_TYPE_MEMORY; } - - List clusterIdswithEnoughCapacity = _capacityDao.orderClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone); + + if (s_logger.isDebugEnabled()) { + s_logger.debug("CPUOverprovisioningFactor considered: " + cpuOverprovisioningFactor); + } + List clusterIdswithEnoughCapacity = _capacityDao.orderClustersInZoneOrPodByHostCapacities(id, requiredCpu, requiredRam, capacityType, isZone, cpuOverprovisioningFactor); if (s_logger.isDebugEnabled()) { s_logger.debug("ClusterId List having enough aggregate capacity: "+clusterIdswithEnoughCapacity ); } diff --git a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java index d18f45f7143..c633e25ef26 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade222to224.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade222to224.java @@ -66,6 +66,7 @@ public class Upgrade222to224 implements DbUpgrade { updateUserStatsWithNetwork(conn); dropIndexIfExists(conn); fixBasicZoneNicCount(conn); + updateTotalCPUInOpHostCapacity(conn); } @Override @@ -290,4 +291,52 @@ public class Upgrade222to224 implements DbUpgrade { throw new CloudRuntimeException("Unable to drop 'path' index for 'domain' table due to:", e); } } + + private void updateTotalCPUInOpHostCapacity(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + PreparedStatement pstmtUpdate = null; + try { + // Load all Routing hosts + s_logger.debug("Updating total CPU capacity entries in op_host_capacity"); + pstmt = conn.prepareStatement("SELECT id, cpus, speed FROM host WHERE type = 'Routing'"); + rs = pstmt.executeQuery(); + while (rs.next()) { + long hostId = rs.getLong(1); + int cpus = rs.getInt(2); + long speed = rs.getLong(3); + + long totalCapacity = cpus * speed; + + String updateSQL = "UPDATE op_host_capacity SET total_capacity = ? WHERE host_id = ? AND capacity_type = 1"; + pstmtUpdate = conn.prepareStatement(updateSQL); + pstmtUpdate.setLong(1, totalCapacity); + pstmtUpdate.setLong(2, hostId); + pstmtUpdate.executeUpdate(); + pstmtUpdate.close(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to update the total host CPU capacity in Op_Host_capacity table", e); + } finally { + if (pstmtUpdate != null) { + try { + pstmtUpdate.close(); + } catch (SQLException e) { + } + } + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + } + } + if (pstmt != null) { + try { + pstmt.close(); + } catch (SQLException e) { + } + } + + } + } }