cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject git commit: updated refs/heads/master to 980b227
Date Wed, 31 Jul 2013 13:09:30 GMT
Updated Branches:
  refs/heads/master ce06d6542 -> 980b22781


recalculate the capacity after overcomit change.

Conflicts:
	server/src/com/cloud/capacity/CapacityManager.java
	server/src/com/cloud/capacity/CapacityManagerImpl.java
	server/src/com/cloud/resource/ResourceManagerImpl.java
	server/src/com/cloud/vm/VirtualMachineManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/980b2278
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/980b2278
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/980b2278

Branch: refs/heads/master
Commit: 980b227817d288bc2398342a32901b74afe8d532
Parents: ce06d65
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Fri Jul 26 12:18:12 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Wed Jul 31 18:39:14 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/capacity/CapacityManagerImpl.java | 41 ++++++++++++++++----
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 25 +++++++++++-
 2 files changed, 57 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/980b2278/server/src/com/cloud/capacity/CapacityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java
index 05a47dd..5486a48 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -48,6 +48,7 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.exception.ConnectionException;
@@ -82,16 +83,21 @@ import com.cloud.utils.db.Transaction;
 import com.cloud.utils.fsm.StateListener;
 import com.cloud.vm.UserVmDetailVO;
 import com.cloud.vm.UserVmVO;
+import com.cloud.vm.UserVmDetailVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.Event;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
 import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 @Component
 @Local(value = CapacityManager.class)
@@ -127,11 +133,11 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
     protected UserVmDao _userVMDao;
     @Inject
     protected UserVmDetailsDao _userVmDetailsDao;
+    @Inject
+    ClusterDao _clusterDao;
 
     @Inject
     ClusterDetailsDao _clusterDetailsDao;
-    @Inject
-    ClusterDao _clusterDao;
     private int _vmCapacityReleaseInterval;
     private ScheduledExecutorService _executor;
     private boolean _stopped;
@@ -547,10 +553,24 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             s_logger.debug("Found " + vms.size() + " VMs on host " + host.getId());
         }
 
+        ClusterVO cluster = _clusterDao.findById(host.getClusterId());
+        ClusterDetailsVO clusterDetailCpu = _clusterDetailsDao.findDetail(cluster.getId(),
"cpuOvercommitRatio");
+        ClusterDetailsVO clusterDetailRam = _clusterDetailsDao.findDetail(cluster.getId(),
"memoryOvercommitRatio");
+        Float clusterCpuOvercommitRatio = Float.parseFloat(clusterDetailCpu.getValue());
+        Float clusterRamOvercommitRatio = Float.parseFloat(clusterDetailRam.getValue());
+        Float cpuOvercommitRatio = 1f;
+        Float ramOvercommitRatio = 1f;
         for (VMInstanceVO vm : vms) {
+            UserVmDetailVO vmDetailCpu = _userVmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio");
+            UserVmDetailVO vmDetailRam = _userVmDetailsDao.findDetail(vm.getId(),"memoryOvercommitRatio");
+            if (vmDetailCpu != null ) {
+                //if vmDetail_cpu is not null it means it is running in a overcommited cluster.
+                cpuOvercommitRatio = Float.parseFloat(vmDetailCpu.getValue());
+                ramOvercommitRatio = Float.parseFloat(vmDetailRam.getValue());
+            }
             ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
-            usedMemory += so.getRamSize() * 1024L * 1024L;
-            usedCpu += so.getCpu() * so.getSpeed();
+            usedMemory += ((so.getRamSize() * 1024L * 1024L)/ramOvercommitRatio)*clusterRamOvercommitRatio;
+            usedCpu += ((so.getCpu() * so.getSpeed())/cpuOvercommitRatio)*clusterCpuOvercommitRatio;
         }
 
         List<VMInstanceVO> vmsByLastHostId = _vmDao.listByLastHostId(host.getId());
@@ -560,9 +580,16 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         for (VMInstanceVO vm : vmsByLastHostId) {
             long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime())
/ 1000;
             if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
+                UserVmDetailVO vmDetailCpu = _userVmDetailsDao.findDetail(vm.getId(), "cpuOvercommitRatio");
+                UserVmDetailVO vmDetailRam = _userVmDetailsDao.findDetail(vm.getId(),"memoryOvercommitRatio");
+                if (vmDetailCpu != null ) {
+                    //if vmDetail_cpu is not null it means it is running in a overcommited
cluster.
+                    cpuOvercommitRatio = Float.parseFloat(vmDetailCpu.getValue());
+                    ramOvercommitRatio = Float.parseFloat(vmDetailRam.getValue());
+                }
                 ServiceOffering so = offeringsMap.get(vm.getServiceOfferingId());
-                reservedMemory += so.getRamSize() * 1024L * 1024L;
-                reservedCpu += so.getCpu() * so.getSpeed();
+                reservedMemory += ((so.getRamSize() * 1024L * 1024L)/ramOvercommitRatio)*clusterRamOvercommitRatio;
+                reservedCpu += (so.getCpu() * so.getSpeed()/cpuOvercommitRatio)*clusterCpuOvercommitRatio;
             } else {
                 // signal if not done already, that the VM has been stopped for skip.counting.hours,
                 // hence capacity will not be reserved anymore.
@@ -630,7 +657,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             capacity.setReservedCapacity(reservedMemory);
             CapacityState capacityState = CapacityState.Enabled;
             if (host.getClusterId() != null) {
-                ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId());
+                cluster = ApiDBUtils.findClusterById(host.getClusterId());
                 if (cluster != null) {
                     capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled
? CapacityState.Disabled
                             : CapacityState.Enabled;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/980b2278/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index a49a297..5b7aa5b 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -184,6 +184,12 @@ import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.snapshot.VMSnapshotManager;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
 
 @Local(value = VirtualMachineManager.class)
 public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager,
Listener {
@@ -857,8 +863,23 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 long destHostId = dest.getHost().getId();
                 vm.setPodId(dest.getPod().getId());
                 Long cluster_id = dest.getCluster().getId();
-                ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id,
"cpuOvercommitRatio");
-                ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id,
"memoryOvercommitRatio");
+                ClusterDetailsVO cluster_detail_cpu =  _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio");
+                ClusterDetailsVO cluster_detail_ram =  _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio");
+                //storing the value of overcommit in the vm_details table for doing a capacity
check in case the cluster overcommit ratio is changed.
+                if (_uservmDetailsDao.findDetail(vm.getId(),"cpuOvercommitRatio") == null
&& ((Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue())
> 1f)) ){
+                    UserVmDetailVO vmDetail_cpu = new UserVmDetailVO(vm.getId(), "cpuOvercommitRatio",
cluster_detail_cpu.getValue());
+                    UserVmDetailVO vmDetail_ram = new UserVmDetailVO(vm.getId(), "memoryOvercommitRatio",
cluster_detail_ram.getValue());
+                    _uservmDetailsDao.persist(vmDetail_cpu);
+                    _uservmDetailsDao.persist(vmDetail_ram);
+                }
+                else if (((Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue())
> 1f))) {
+                    UserVmDetailVO vmDetail_cpu = _uservmDetailsDao.findDetail(vm.getId(),
"cpuOvercommitRatio");
+                    vmDetail_cpu.setValue(cluster_detail_cpu.getValue());
+                    UserVmDetailVO vmDetail_ram = _uservmDetailsDao.findDetail(vm.getId(),
"memoryOvercommitRatio");
+                    vmDetail_ram.setValue(cluster_detail_ram.getValue());
+                    _uservmDetailsDao.update(vmDetail_cpu.getId(), vmDetail_cpu);
+                    _uservmDetailsDao.update(vmDetail_ram.getId(), vmDetail_ram);
+                }
                 vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
                 vmProfile.setMemoryOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));
                 StartAnswer startAnswer = null;


Mime
View raw message