cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject [2/50] [abbrv] git commit: refs/heads/cisco-vnmc-api-integration - Cloudstack-711: Cpu and Ram Overcommit Ratio.
Date Wed, 13 Mar 2013 06:25:05 GMT
Cloudstack-711: Cpu and Ram Overcommit Ratio.


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

Branch: refs/heads/cisco-vnmc-api-integration
Commit: 23e54bb0f4c64735bb34413ea26ea1804c846ff5
Parents: ea3db2f
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Fri Feb 22 17:31:06 2013 +0530
Committer: Abhinandan Prateek <aprateek@apache.org>
Committed: Fri Feb 22 17:31:06 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/agent/api/to/VirtualMachineTO.java   |   15 +-
 api/src/com/cloud/resource/ResourceService.java    |    2 +-
 api/src/com/cloud/vm/VirtualMachineProfile.java    |    6 +
 .../org/apache/cloudstack/api/ApiConstants.java    |    2 +
 .../api/command/admin/cluster/AddClusterCmd.java   |   27 ++
 .../command/admin/cluster/UpdateClusterCmd.java    |   27 ++-
 .../cloudstack/api/response/ClusterResponse.java   |   20 ++
 .../cloud/baremetal/manager/BareMetalPlanner.java  |   21 +-
 .../kvm/resource/LibvirtComputingResource.java     |   16 +-
 .../hypervisor/kvm/resource/LibvirtVMDef.java      |    8 +
 .../com/cloud/agent/manager/MockVmManagerImpl.java |    2 +-
 .../com/cloud/resource/AgentRoutingResource.java   |    6 +-
 .../vmware/manager/VmwareManagerImpl.java          |   12 -
 .../hypervisor/vmware/resource/VmwareResource.java |   44 +--
 .../xen/resource/CitrixResourceBase.java           |    8 +-
 .../hypervisor/xen/resource/XcpServerResource.java |   16 +-
 .../xen/resource/XenServer56FP1Resource.java       |    6 +-
 .../manager/allocator/impl/FirstFitAllocator.java  |   16 +-
 server/src/com/cloud/api/ApiDBUtils.java           |    7 +
 server/src/com/cloud/api/ApiResponseHelper.java    |   16 +-
 server/src/com/cloud/capacity/CapacityManager.java |    4 +-
 .../com/cloud/capacity/CapacityManagerImpl.java    |   72 +++--
 .../cloud/capacity/ComputeCapacityListener.java    |    5 +-
 server/src/com/cloud/capacity/dao/CapacityDao.java |   14 +-
 .../com/cloud/capacity/dao/CapacityDaoImpl.java    |  243 ++++++++-------
 server/src/com/cloud/deploy/FirstFitPlanner.java   |   87 +++---
 .../com/cloud/hypervisor/HypervisorGuruBase.java   |    8 +-
 .../com/cloud/resource/ResourceManagerImpl.java    |   18 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   14 +
 .../com/cloud/vm/VirtualMachineProfileImpl.java    |   28 ++-
 .../com/cloud/capacity/CapacityManagerTest.java    |   61 ++++
 .../cloud/resource/MockResourceManagerImpl.java    |    3 +-
 .../cloud/hypervisor/vmware/util/VmwareHelper.java |    7 +-
 33 files changed, 537 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/com/cloud/agent/api/to/VirtualMachineTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java
index 8f3f0eb..bdd636e 100644
--- a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java
+++ b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java
@@ -28,7 +28,8 @@ public class VirtualMachineTO {
     private BootloaderType bootloader;
     Type type;
     int cpus;
-    Integer speed;
+    Integer minSpeed;
+    Integer maxSpeed;
     long minRam;
     long maxRam;
     String hostName;
@@ -47,12 +48,13 @@ public class VirtualMachineTO {
     VolumeTO[] disks;
     NicTO[] nics;
 
-    public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) {
+    public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer minSpeed, Integer maxSpeed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) {
         this.id = id;
         this.name = instanceName;
         this.type = type;
         this.cpus = cpus;
-        this.speed = speed;
+        this.minSpeed = minSpeed;
+        this.maxSpeed = maxSpeed;
         this.minRam = minRam;
         this.maxRam = maxRam;
         this.bootloader = bootloader;
@@ -101,10 +103,13 @@ public class VirtualMachineTO {
         this.cpus = cpus;
     }
 
-    public Integer getSpeed() {
-        return speed;
+    public Integer getMinSpeed() {
+        return minSpeed;
     }
 
+    public Integer getMaxSpeed() {
+        return maxSpeed;
+    }
     public boolean getLimitCpuUse() {
     	return limitCpuUse;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/com/cloud/resource/ResourceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java
index 1e77cc8..83718d4 100755
--- a/api/src/com/cloud/resource/ResourceService.java
+++ b/api/src/com/cloud/resource/ResourceService.java
@@ -71,7 +71,7 @@ public interface ResourceService {
 
     boolean deleteCluster(DeleteClusterCmd cmd);
 
-    Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate);
+    Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio);
 
     List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/com/cloud/vm/VirtualMachineProfile.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/VirtualMachineProfile.java b/api/src/com/cloud/vm/VirtualMachineProfile.java
index 0fab443..33a9171 100644
--- a/api/src/com/cloud/vm/VirtualMachineProfile.java
+++ b/api/src/com/cloud/vm/VirtualMachineProfile.java
@@ -136,4 +136,10 @@ public interface VirtualMachineProfile<T extends VirtualMachine> {
     BootloaderType getBootLoaderType();
 
     Map<Param, Object> getParameters();
+
+    Float getCpuOvercommitRatio();
+
+    Float getMemoryOvercommitRatio();
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index b12e4cd..8b4bb98 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -46,6 +46,7 @@ public class ApiConstants {
     public static final String COMPONENT = "component";
     public static final String CPU_NUMBER = "cpunumber";
     public static final String CPU_SPEED = "cpuspeed";
+    public static final String CPU_OVERCOMMIT_RATIO="cpuovercommitratio";
     public static final String CREATED = "created";
     public static final String CUSTOMIZED = "customized";
     public static final String DESCRIPTION = "description";
@@ -119,6 +120,7 @@ public class ApiConstants {
     public static final String MAX = "max";
     public static final String MAX_SNAPS = "maxsnaps";
     public static final String MEMORY = "memory";
+    public static final String MEMORY_OVERCOMMIT_RATIO="memoryovercommitratio";
     public static final String MODE = "mode";
     public static final String NAME = "name";
     public static final String METHOD_NAME = "methodname";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
index 912c396..7b1cd06 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
@@ -20,6 +20,10 @@ package org.apache.cloudstack.api.command.admin.cluster;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.cloud.exception.InvalidParameterValueException;
+import org.apache.cloudstack.api.*;
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
@@ -81,6 +85,12 @@ public class AddClusterCmd extends BaseCmd {
     @Parameter(name = ApiConstants.VSM_IPADDRESS, type = CommandType.STRING, required = false, description = "the ipaddress of the VSM associated with this cluster")
     private String vsmipaddress;
 
+    @Parameter (name=ApiConstants.CPU_OVERCOMMIT_RATIO, type = CommandType.STRING, required = false , description = "value of the cpu overcommit ratio, defaults to 1")
+    private String  cpuovercommitRatio;
+
+    @Parameter(name = ApiConstants.MEMORY_OVERCOMMIT_RATIO, type = CommandType.STRING, required = false ,description = "value of the default ram overcommit ratio, defaults to 1")
+    private String  memoryovercommitratio;
+
     public String getVSMIpaddress() {
         return vsmipaddress;
     }
@@ -147,9 +157,26 @@ public class AddClusterCmd extends BaseCmd {
         this.allocationState = allocationState;
     }
 
+    public Float getCpuOvercommitRatio (){
+        if(cpuovercommitRatio != null){
+           return Float.parseFloat(cpuovercommitRatio);
+        }
+        return 1.0f;
+    }
+
+    public Float getMemoryOvercommitRaito (){
+        if (memoryovercommitratio != null){
+            return Float.parseFloat(memoryovercommitratio);
+        }
+        return 1.0f;
+    }
+
     @Override
     public void execute(){
         try {
+            if ((getMemoryOvercommitRaito().compareTo(1f) < 0) | (getCpuOvercommitRatio().compareTo(1f) < 0)) {
+                throw new InvalidParameterValueException("Cpu and ram overcommit ratios  should not be less than 1");
+            }
             List<? extends Cluster> result = _resourceService.discoverCluster(this);
             ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
             List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java
index 058c7eb..95728dd 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java
@@ -54,6 +54,13 @@ public class UpdateClusterCmd extends BaseCmd {
     @Parameter(name=ApiConstants.MANAGED_STATE, type=CommandType.STRING, description="whether this cluster is managed by cloudstack")
     private String managedState;
 
+    @Parameter(name=ApiConstants.CPU_OVERCOMMIT_RATIO, type = CommandType.STRING, description = "Value of cpu overcommit ratio")
+    private String cpuovercommitratio;
+
+    @Parameter(name=ApiConstants.MEMORY_OVERCOMMIT_RATIO, type = CommandType.STRING, description = "Value of ram overcommit ratio")
+    private String memoryovercommitratio;
+
+
     public String getClusterName() {
         return clusterName;
     }
@@ -100,6 +107,20 @@ public class UpdateClusterCmd extends BaseCmd {
         this.managedState = managedstate;
     }
 
+    public Float getCpuOvercommitRatio (){
+        if(cpuovercommitratio != null){
+            return Float.parseFloat(cpuovercommitratio);
+        }
+        return 1.0f;
+    }
+
+    public Float getMemoryOvercommitRaito (){
+        if (memoryovercommitratio != null){
+            return Float.parseFloat(memoryovercommitratio);
+        }
+        return 1.0f;
+    }
+
     @Override
     public void execute(){
         Cluster cluster = _resourceService.getCluster(getId());
@@ -107,7 +128,11 @@ public class UpdateClusterCmd extends BaseCmd {
             throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
         }
 
-        Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
+        if ((getMemoryOvercommitRaito().compareTo(1f) < 0) | (getCpuOvercommitRatio().compareTo(1f) < 0)) {
+            throw new InvalidParameterValueException("Cpu and ram overcommit ratios  should be greater than one");
+        }
+
+        Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate(), getMemoryOvercommitRaito(), getCpuOvercommitRatio());
         if (result != null) {
                 ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                 clusterResponse.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/api/src/org/apache/cloudstack/api/response/ClusterResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/ClusterResponse.java b/api/src/org/apache/cloudstack/api/response/ClusterResponse.java
index 551e530..a90acde 100644
--- a/api/src/org/apache/cloudstack/api/response/ClusterResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ClusterResponse.java
@@ -62,6 +62,12 @@ public class ClusterResponse extends BaseResponse {
     @SerializedName("capacity")  @Param(description="the capacity of the Cluster", responseObject = CapacityResponse.class)
     private List<CapacityResponse> capacitites;
 
+    @SerializedName("cpuovercommitratio") @Param(description = "The cpu overcommit ratio of the cluster")
+    private String cpuovercommitratio;
+
+    @SerializedName("memoryovercommitratio") @Param (description = "The ram overcommit ratio of the cluster")
+    private String memoryovercommitratio;
+
     public String getId() {
         return id;
     }
@@ -149,4 +155,18 @@ public class ClusterResponse extends BaseResponse {
     public void setCapacitites(ArrayList<CapacityResponse> arrayList) {
         this.capacitites = arrayList;
     }
+    public void setCpuovercommitratio(String cpuovercommitratio){
+        this.cpuovercommitratio= cpuovercommitratio;
+    }
+    public void setRamovercommitratio (String memoryOvercommitRatio){
+        this.memoryovercommitratio= memoryOvercommitRatio;
+    }
+
+    public String getCpuovercommitratio (){
+        return cpuovercommitratio;
+    }
+
+    public String getRamovercommitratio (){
+        return memoryovercommitratio;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
index fe51eb0..97b2840 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
@@ -23,14 +23,13 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.dc.*;
+import com.cloud.dc.ClusterDetailsDao;
 import org.apache.log4j.Logger;
 
 import com.cloud.capacity.CapacityManager;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.Pod;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
@@ -61,16 +60,14 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner {
 	@Inject protected ConfigurationDao _configDao;
 	@Inject protected CapacityManager _capacityMgr;
 	@Inject protected ResourceManager _resourceMgr;
+    @Inject protected ClusterDetailsDao _clusterDetailsDao;
 	
 	@Override
 	public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
 		VirtualMachine vm = vmProfile.getVirtualMachine();
-		ServiceOffering offering = vmProfile.getServiceOffering();	
+		ServiceOffering offering = vmProfile.getServiceOffering();
 		String hostTag = null;
-		
-        String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
-        
+
         String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
         
 		if (vm.getLastHostId() != null && haVmTag == null) {
@@ -126,7 +123,13 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner {
 		        return null;
 		    }
 			for (HostVO h : hosts) {
-				if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOverprovisioningFactor, true)) {
+                long cluster_id = h.getClusterId();
+                ClusterDetailsVO cluster_detail_cpu =  _clusterDetailsDao.findDetail(cluster_id,"cpuOvercommitRatio") ;
+                ClusterDetailsVO cluster_detail_ram =  _clusterDetailsDao.findDetail(cluster_id,"memoryOvercommitRatio");
+                Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
+                Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
+
+				if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) {
 					s_logger.debug("Find host " + h.getId() + " has enough capacity");
 					DataCenter dc = _dcDao.findById(h.getDataCenterId());
 					Pod pod = _podDao.findById(h.getPodId());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 9472ea2..f7d1b4a 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -2921,12 +2921,24 @@ ServerResource {
         vm.addComp(guest);
 
         GuestResourceDef grd = new GuestResourceDef();
-        grd.setMemorySize(vmTO.getMinRam() / 1024);
+        //check if overcommit should be considered.
+        if(vmTO.getMinSpeed() == vmTO.getMaxSpeed()){
+
+
+        }
+        if (vmTO.getMinRam() != vmTO.getMaxRam()){
+             grd.setMemBalloning(true);
+             grd.setCurrentMem((int)vmTO.getMinRam()/1024);
+             grd.setMemorySize((int)vmTO.getMaxRam()/1024);
+        }
+        else{
+            grd.setMemorySize(vmTO.getMaxRam() / 1024);
+        }
         grd.setVcpuNum(vmTO.getCpus());
         vm.addComp(grd);
 
         CpuTuneDef ctd = new CpuTuneDef();
-        ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
+        ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed());
         vm.addComp(ctd);
 
         FeaturesDef features = new FeaturesDef();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
index acfd9cf..5ab3770 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
@@ -116,6 +116,7 @@ public class LibvirtVMDef {
         private int _currentMem = -1;
         private String _memBacking;
         private int _vcpu = -1;
+        private boolean _memBalloning= false;
 
         public void setMemorySize(long mem) {
             _mem = mem;
@@ -133,6 +134,10 @@ public class LibvirtVMDef {
             _vcpu = vcpu;
         }
 
+        public void setMemBalloning(boolean turnon){
+              _memBalloning = turnon;
+        }
+
         @Override
         public String toString() {
             StringBuilder resBuidler = new StringBuilder();
@@ -145,6 +150,9 @@ public class LibvirtVMDef {
                 resBuidler.append("<memoryBacking>" + "<" + _memBacking + "/>"
                         + "</memoryBacking>\n");
             }
+            if (_memBalloning){
+                resBuidler.append("<devices>\n" + "<memballoon model='virtio'/>\n" + "</devices>\n");
+            }
             if (_vcpu != -1) {
                 resBuidler.append("<vcpu>" + _vcpu + "</vcpu>\n");
             }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
index 40a5b98..c0ccbe4 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -348,7 +348,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
     @Override
     public Answer startVM(StartCommand cmd, SimulatorInfo info) {
         VirtualMachineTO vm = cmd.getVirtualMachine();
-        String result = startVM(vm.getName(), vm.getNics(), vm.getCpus()* vm.getSpeed(), vm.getMaxRam(), vm.getBootArgs(), info.getHostUuid());
+        String result = startVM(vm.getName(), vm.getNics(), vm.getCpus()* vm.getMaxSpeed(), vm.getMaxRam(), vm.getBootArgs(), info.getHostUuid());
         if (result != null) {
             return new StartAnswer(cmd, result);
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
index 721e5f7..46df50c 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
@@ -184,7 +184,7 @@ public class AgentRoutingResource extends AgentStorageResource {
 			throws IllegalArgumentException {
 		VirtualMachineTO vmSpec = cmd.getVirtualMachine();
 		String vmName = vmSpec.getName();
-		if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getSpeed() + this.usedCpu) ||
+		if (this.totalCpu < (vmSpec.getCpus() * vmSpec.getMaxSpeed() + this.usedCpu) ||
 			this.totalMem < (vmSpec.getMaxRam() + this.usedMem)) {
 			return new StartAnswer(cmd, "Not enough resource to start the vm");
 		}
@@ -199,9 +199,9 @@ public class AgentRoutingResource extends AgentStorageResource {
 		        return new StartAnswer(cmd, result.getDetails());
 		    }
 
-		    this.usedCpu += vmSpec.getCpus() * vmSpec.getSpeed();
+		    this.usedCpu += vmSpec.getCpus() * vmSpec.getMaxSpeed();
 		    this.usedMem += vmSpec.getMaxRam();
-		    _runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getSpeed()), vmSpec.getMaxRam()));
+		    _runningVms.put(vmName, new Pair<Long, Long>(Long.valueOf(vmSpec.getCpus() * vmSpec.getMaxSpeed()), vmSpec.getMaxRam()));
 		    state = State.Running;
 
 		} finally {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 70f98cc..6b6bf19 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -138,10 +138,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
     int _additionalPortRangeSize;
     int _routerExtraPublicNics = 2;
 
-    String _cpuOverprovisioningFactor = "1";
     String _reserveCpu = "false";
 
-    String _memOverprovisioningFactor = "1";
     String _reserveMem = "false";
 
     String _rootDiskController = DiskControllerType.ide.toString();
@@ -262,14 +260,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
 
         _routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
 
-        _cpuOverprovisioningFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        if(_cpuOverprovisioningFactor == null || _cpuOverprovisioningFactor.isEmpty())
-            _cpuOverprovisioningFactor = "1";
-
-        _memOverprovisioningFactor = _configDao.getValue(Config.MemOverprovisioningFactor.key());
-        if(_memOverprovisioningFactor == null || _memOverprovisioningFactor.isEmpty())
-            _memOverprovisioningFactor = "1";
-
         _reserveCpu = _configDao.getValue(Config.VmwareReserveCpu.key());
         if(_reserveCpu == null || _reserveCpu.isEmpty())
             _reserveCpu = "false";
@@ -507,9 +497,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
         params.put("vmware.use.nexus.vswitch", _nexusVSwitchActive);
         params.put("service.console.name", _serviceConsoleName);
         params.put("management.portgroup.name", _managemetPortGroupName);
-        params.put("cpu.overprovisioning.factor", _cpuOverprovisioningFactor);
         params.put("vmware.reserve.cpu", _reserveCpu);
-        params.put("mem.overprovisioning.factor", _memOverprovisioningFactor);
         params.put("vmware.reserve.mem", _reserveMem);
         params.put("vmware.root.disk.controller", _rootDiskController);
         params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 5cac253..f754c58 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -289,10 +289,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
     protected VirtualSwitchType _vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
     protected boolean _nexusVSwitch = false;
 
-    protected float _cpuOverprovisioningFactor = 1;
     protected boolean _reserveCpu = false;
 
-    protected float _memOverprovisioningFactor = 1;
     protected boolean _reserveMem = false;
     protected boolean _recycleHungWorker = false;
     protected DiskControllerType _rootDiskController = DiskControllerType.ide;    
@@ -2089,10 +2087,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                         }
                     }
 
-                    assert (vmSpec.getSpeed() != null) && (rootDiskDataStoreDetails != null);
-                    if (!hyperHost.createBlankVm(vmName, vmSpec.getCpus(), vmSpec.getSpeed().intValue(), 
-                            getReserveCpuMHz(vmSpec.getSpeed().intValue()), vmSpec.getLimitCpuUse(), ramMb, getReserveMemMB(ramMb),
-                            translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), rootDiskDataStoreDetails.first(), false)) {
+                    assert (vmSpec.getMinSpeed() != null) && (rootDiskDataStoreDetails != null);
+                    if (!hyperHost.createBlankVm(vmName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
+                    vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
+                    translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), rootDiskDataStoreDetails.first(), false)) {
                         throw new Exception("Failed to create VM. vmName: " + vmName);
                     }
                 }
@@ -2122,10 +2120,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
 
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
             int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
-            VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getSpeed().intValue(), 
-                    getReserveCpuMHz(vmSpec.getSpeed().intValue()), ramMb, getReserveMemMB(ramMb),
-                    translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), vmSpec.getLimitCpuUse());
-
+            VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
+            vmSpec.getMinSpeed(),(int) (vmSpec.getMaxRam()/(1024*1024)), ramMb,
+            translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).toString(), vmSpec.getLimitCpuUse());
+            
             VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[totalChangeDevices];
             int i = 0;
             int ideControllerKey = vmMo.getIDEDeviceControllerKey();
@@ -2375,22 +2373,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         return validatedDetails;
     }
 
-    private int getReserveCpuMHz(int cpuMHz) {
-        if(this._reserveCpu) {
-            return (int)(cpuMHz / this._cpuOverprovisioningFactor);
-        }
-
-        return 0;
-    }
-
-    private int getReserveMemMB(int memMB) {
-        if(this._reserveMem) {
-            return (int)(memMB / this._memOverprovisioningFactor);
-        }
-
-        return 0;
-    }
 
+    
     private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
 
         List<NicTO> listForSort = new ArrayList<NicTO>();
@@ -4882,11 +4866,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             _guestNetworkVSwitchName = (String) params.get("guest.network.vswitch.name");
         }
 
-        String value = (String) params.get("cpu.overprovisioning.factor");
-        if(value != null)
-            _cpuOverprovisioningFactor = Float.parseFloat(value);
-
-        value = (String) params.get("vmware.reserve.cpu");
+        String value = (String) params.get("vmware.reserve.cpu");
         if(value != null && value.equalsIgnoreCase("true"))
             _reserveCpu = true;
 
@@ -4894,10 +4874,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         if(value != null && value.equalsIgnoreCase("true"))
             _recycleHungWorker = true;
 
-        value = (String) params.get("mem.overprovisioning.factor");
-        if(value != null)
-            _memOverprovisioningFactor = Float.parseFloat(value);
-
         value = (String) params.get("vmware.reserve.mem");
         if(value != null && value.equalsIgnoreCase("true"))
             _reserveMem = true;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 33ad18d..4a89806 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -1114,13 +1114,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         vm.setAffinity(conn, host);
         vm.removeFromOtherConfig(conn, "disks");
         vm.setNameLabel(conn, vmSpec.getName());
-        setMemory(conn, vm, vmSpec.getMinRam());
+        setMemory(conn, vm, vmSpec.getMinRam(),vmSpec.getMaxRam());
         vm.setVCPUsMax(conn, (long)vmSpec.getCpus());
         vm.setVCPUsAtStartup(conn, (long)vmSpec.getCpus());
 
         Map<String, String> vcpuParams = new HashMap<String, String>();
 
-        Integer speed = vmSpec.getSpeed();
+        Integer speed = vmSpec.getMinSpeed();
         if (speed != null) {
 
             int cpuWeight = _maxWeight; //cpu_weight
@@ -3253,8 +3253,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
         }
     }
 
-    protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
-        vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
+    protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
+        vm.setMemoryLimits(conn, maxMemsize, maxMemsize, minMemsize, maxMemsize);
     }
 
     private void waitForTask(Connection c, Task task, long pollInterval, long timeout) throws XenAPIException, XmlRpcException {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java
index 0ce91bc..7a95870 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpServerResource.java
@@ -72,17 +72,17 @@ public class XcpServerResource extends CitrixResourceBase {
     }
 
     @Override
-    protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
+    protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
 
         vm.setMemoryStaticMin(conn, 33554432L);
-        vm.setMemoryDynamicMin(conn, 33554432L);
-        vm.setMemoryDynamicMax(conn, 33554432L);
+        //vm.setMemoryDynamicMin(conn, 33554432L);
+        //vm.setMemoryDynamicMax(conn, 33554432L);
         vm.setMemoryStaticMax(conn, 33554432L);
 
-        vm.setMemoryStaticMax(conn, memsize);
-        vm.setMemoryDynamicMax(conn, memsize);
-        vm.setMemoryDynamicMin(conn, memsize);
-        vm.setMemoryStaticMin(conn, memsize);
+        //vm.setMemoryStaticMax(conn, maxMemsize );
+        vm.setMemoryDynamicMax(conn, maxMemsize );
+        vm.setMemoryDynamicMin(conn, minMemsize );
+        //vm.setMemoryStaticMin(conn,  maxMemsize );
     }
     
 
@@ -99,7 +99,7 @@ public class XcpServerResource extends CitrixResourceBase {
             return answer;
         } catch (Exception ex) {
             s_logger.warn("Failed to get network usage stats due to ", ex);
-            return new NetworkUsageAnswer(cmd, ex); 
+            return new NetworkUsageAnswer(cmd, ex);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java
index 58b8a03..7040311 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java
@@ -136,9 +136,9 @@ public class XenServer56FP1Resource extends XenServer56Resource {
         record.nameLabel = vmSpec.getName();
         record.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY;
         record.actionsAfterShutdown = Types.OnNormalExit.DESTROY;
-        record.memoryDynamicMax = vmSpec.getMinRam();
+        record.memoryDynamicMax = vmSpec.getMaxRam();
         record.memoryDynamicMin = vmSpec.getMinRam();
-        record.memoryStaticMax = vmSpec.getMinRam();
+        record.memoryStaticMax = vmSpec.getMaxRam();
         record.memoryStaticMin = vmSpec.getMinRam();
         record.VCPUsMax = (long) vmSpec.getCpus();
         record.VCPUsAtStartup = (long) vmSpec.getCpus();
@@ -152,7 +152,7 @@ public class XenServer56FP1Resource extends XenServer56Resource {
 
         Map<String, String> vcpuParams = new HashMap<String, String>();
 
-        Integer speed = vmSpec.getSpeed();
+        Integer speed = vmSpec.getMinSpeed();
         if (speed != null) {
 
             int cpuWeight = _maxWeight; // cpu_weight

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
----------------------------------------------------------------------
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 a25e401..0091e43 100755
--- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
+++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java
@@ -26,6 +26,10 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.org.Cluster;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -78,6 +82,8 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
     @Inject GuestOSCategoryDao _guestOSCategoryDao = null;
     @Inject VMInstanceDao _vmInstanceDao = null;
     @Inject ResourceManager _resourceMgr;
+    @Inject ClusterDao _clusterDao;
+    @Inject ClusterDetailsDao _clusterDetailsDao;
     float _factor = 1;
     boolean _checkHvm = true;
     protected String _allocationAlgorithm = "random";
@@ -214,8 +220,14 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator {
             boolean numCpusGood = host.getCpus().intValue() >= offering.getCpu();
             boolean cpuFreqGood = host.getSpeed().intValue() >= offering.getSpeed();
     		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, _factor, considerReservedCapacity);
+    		long ram_requested = offering.getRamSize() * 1024L * 1024L;
+            Cluster cluster = _clusterDao.findById(host.getClusterId());
+            ClusterDetailsVO clusterDetailsCpuOvercommit = _clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio");
+            ClusterDetailsVO clusterDetailsRamOvercommmt = _clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio");
+            Float cpuOvercommitRatio = Float.parseFloat(clusterDetailsCpuOvercommit.getValue());
+            Float memoryOvercommitRatio = Float.parseFloat(clusterDetailsRamOvercommmt.getValue());
+
+            boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false,cpuOvercommitRatio,memoryOvercommitRatio, considerReservedCapacity);
 
             if (numCpusGood && cpuFreqGood && hostHasCapacity) {
                 if (s_logger.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index c28daef..ffee22f 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -318,6 +318,7 @@ public class ApiDBUtils {
     static AsyncJobDao _asyncJobDao;
     static HostDetailsDao _hostDetailsDao;
     static VMSnapshotDao _vmSnapshotDao;
+    static ClusterDetailsDao _clusterDetailsDao;
 
     @Inject private ManagementServer ms;
     @Inject public AsyncJobManager asyncMgr;
@@ -418,6 +419,7 @@ public class ApiDBUtils {
     @Inject private SnapshotPolicyDao snapshotPolicyDao;
     @Inject private AsyncJobDao asyncJobDao;
     @Inject private HostDetailsDao hostDetailsDao;
+    @Inject private ClusterDetailsDao clusterDetailsDao;
     @Inject private VMSnapshotDao vmSnapshotDao;
     @PostConstruct
     void init() {
@@ -517,6 +519,7 @@ public class ApiDBUtils {
         _snapshotPolicyDao = snapshotPolicyDao;
         _asyncJobDao = asyncJobDao;
         _hostDetailsDao = hostDetailsDao;
+        _clusterDetailsDao = clusterDetailsDao;
         _vmSnapshotDao = vmSnapshotDao;
         // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
         _statsCollector = StatsCollector.getInstance();
@@ -681,6 +684,10 @@ public class ApiDBUtils {
         return _clusterDao.findById(clusterId);
     }
 
+    public static ClusterDetailsVO findClusterDetails(long clusterId, String name){
+         return _clusterDetailsDao.findDetail(clusterId,name);
+    }
+
     public static DiskOfferingVO findDiskOfferingById(Long diskOfferingId) {
         return _diskOfferingDao.findByIdIncludingRemoved(diskOfferingId);
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/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 41cf96e..eafee8a 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -690,14 +690,12 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (showCapacities != null && showCapacities) {
             List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
             Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
-            float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
-
             for (SummedCapacity capacity : capacities) {
                 CapacityResponse capacityResponse = new CapacityResponse();
                 capacityResponse.setCapacityType(capacity.getCapacityType());
                 capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
                 if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
-                    capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
+                    capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity())));
                 } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                     List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId(), null);
                     capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
@@ -827,12 +825,15 @@ public class ApiResponseHelper implements ResponseGenerator {
         clusterResponse.setClusterType(cluster.getClusterType().toString());
         clusterResponse.setAllocationState(cluster.getAllocationState().toString());
         clusterResponse.setManagedState(cluster.getManagedState().toString());
+        String cpuOvercommitRatio=ApiDBUtils.findClusterDetails(cluster.getId(),"cpuOvercommitRatio").getValue();
+        String memoryOvercommitRatio=ApiDBUtils.findClusterDetails(cluster.getId(),"memoryOvercommitRatio").getValue();
+        clusterResponse.setCpuovercommitratio(cpuOvercommitRatio);
+        clusterResponse.setRamovercommitratio(memoryOvercommitRatio);
 
 
         if (showCapacities != null && showCapacities) {
             List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, null, cluster.getId());
             Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
-            float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
 
             for (SummedCapacity capacity : capacities) {
                 CapacityResponse capacityResponse = new CapacityResponse();
@@ -840,8 +841,11 @@ public class ApiResponseHelper implements ResponseGenerator {
                 capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
 
                 if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
-                    capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor)));
-                } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
+                    capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(cpuOvercommitRatio))));
+                }else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_MEMORY){
+                    capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(memoryOvercommitRatio))));
+                }
+                else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                     List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, null, cluster.getId());
                     capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
                     capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/capacity/CapacityManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/CapacityManager.java b/server/src/com/cloud/capacity/CapacityManager.java
index 656e744..bdd9ccd 100755
--- a/server/src/com/cloud/capacity/CapacityManager.java
+++ b/server/src/com/cloud/capacity/CapacityManager.java
@@ -39,8 +39,8 @@ public interface CapacityManager extends Manager {
      * @param ram required RAM
      * @param cpuOverprovisioningFactor factor to apply to the actual host cpu
      */
-    boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor, boolean considerReservedCapacity);
-    
+    boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor, float memoryOvercommitRatio, boolean considerReservedCapacity);
+
 	void updateCapacityForHost(HostVO host);
     
 	/**

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/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 74152ff..292ef0a 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -28,6 +28,12 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.resource.ResourceState;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -119,26 +125,25 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
     @Inject
     protected UserVmDao _userVMDao;
     
+    @Inject
+    ClusterDetailsDao _clusterDetailsDao;
+    @Inject
+    ClusterDao _clusterDao;
     private int _vmCapacityReleaseInterval;
     private ScheduledExecutorService _executor;
     private boolean _stopped;
     long _extraBytesPerVolume = 0;
     private float _storageOverProvisioningFactor = 1.0f;
-    private float _cpuOverProvisioningFactor = 1.0f;
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
         _vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600);
         _storageOverProvisioningFactor = NumbersUtil.parseFloat(_configDao.getValue(Config.StorageOverprovisioningFactor.key()), 1.0f);
-        _cpuOverProvisioningFactor = NumbersUtil.parseFloat(_configDao.getValue(Config.CPUOverprovisioningFactor.key()), 1.0f);
 
-        if (_cpuOverProvisioningFactor < 1.0f) {
-            _cpuOverProvisioningFactor = 1.0f;
-        }
         _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("HostCapacity-Checker"));
         VirtualMachine.State.getStateMachine().registerListener(this);
         _agentManager.registerForHostEvents(new StorageCapacityListener(_capacityDao, _storageOverProvisioningFactor), true, false, false);
-        _agentManager.registerForHostEvents(new ComputeCapacityListener(_capacityDao, this, _cpuOverProvisioningFactor), true, false, false);
+        _agentManager.registerForHostEvents(new ComputeCapacityListener(_capacityDao, this), true, false, false);
 
         return true;
     }
@@ -163,7 +168,11 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         ServiceOfferingVO svo = _offeringsDao.findById(vm.getServiceOfferingId());
         CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
         CapacityVO capacityMemory = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
-
+        Long clusterId=null;
+        if (hostId != null) {
+        HostVO host = _hostDao.findById(hostId);
+        clusterId= host.getClusterId();
+        }
         if (capacityCpu == null || capacityMemory == null || svo == null) {
             return false;
         }
@@ -172,9 +181,6 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         try {
             txn.start();
 
-            int vmCPU = svo.getCpu() * svo.getSpeed();
-            long vmMem = svo.getRamSize() * 1024L * 1024L;
-
             capacityCpu = _capacityDao.lockRow(capacityCpu.getId(), true);
             capacityMemory = _capacityDao.lockRow(capacityMemory.getId(), true);
 
@@ -183,13 +189,18 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             long reservedCpu = capacityCpu.getReservedCapacity();
             long reservedMem = capacityMemory.getReservedCapacity();
             long actualTotalCpu = capacityCpu.getTotalCapacity();
-            String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-            float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
-            long totalCpu = (long) (actualTotalCpu * cpuOverprovisioningFactor);
+            float cpuOvercommitRatio =Float.parseFloat(_clusterDetailsDao.findDetail(clusterId,"cpuOvercommitRatio").getValue());
+            float memoryOvercommitRatio = Float.parseFloat(_clusterDetailsDao.findDetail(clusterId,"memoryOvercommitRatio").getValue());
+            int vmCPU = (int) (svo.getCpu() * svo.getSpeed());
+            long vmMem = (long) (svo.getRamSize() * 1024L * 1024L);
+            long actualTotalMem = capacityMemory.getTotalCapacity();
+            long totalMem = (long) (actualTotalMem * memoryOvercommitRatio);
+            long totalCpu = (long) (actualTotalCpu * cpuOvercommitRatio);
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
+                s_logger.debug("Hosts's actual total RAM: " + actualTotalMem + " and RAM after applying overprovisioning: " + totalMem);
             }
-            long totalMem = capacityMemory.getTotalCapacity();
+
 
             if (!moveFromReserved) {
                 /* move resource from used */
@@ -241,6 +252,10 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
     public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
 
         long hostId = vm.getHostId();
+        HostVO host = _hostDao.findById(hostId);
+        long clusterId = host.getClusterId();
+        float cpuOvercommitRatio =Float.parseFloat(_clusterDetailsDao.findDetail(clusterId,"cpuOvercommitRatio").getValue());
+        float memoryOvercommitRatio = Float.parseFloat(_clusterDetailsDao.findDetail(clusterId,"memoryOvercommitRatio").getValue());
 
         ServiceOfferingVO svo = _offeringsDao.findById(vm.getServiceOfferingId());
 
@@ -251,11 +266,9 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             return;
         }
 
-        int cpu = svo.getCpu() * svo.getSpeed();
-        long ram = svo.getRamSize() * 1024L * 1024L;
+        int cpu = (int) (svo.getCpu() * svo.getSpeed());
+        long ram = (long) (svo.getRamSize() * 1024L * 1024L);
 
-        String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
-        float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
 
         Transaction txn = Transaction.currentTxn();
 
@@ -269,11 +282,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             long reservedCpu = capacityCpu.getReservedCapacity();
             long reservedMem = capacityMem.getReservedCapacity();
             long actualTotalCpu = capacityCpu.getTotalCapacity();
-            long totalCpu = (long) (actualTotalCpu * cpuOverprovisioningFactor);
+            long actualTotalMem = capacityMem.getTotalCapacity();
+            long totalCpu = (long) (actualTotalCpu * cpuOvercommitRatio);
+            long totalMem = (long) (actualTotalMem * memoryOvercommitRatio);
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
             }
-            long totalMem = capacityMem.getTotalCapacity();
 
             long freeCpu = totalCpu - (reservedCpu + usedCpu);
             long freeMem = totalMem - (reservedMem + usedMem);
@@ -325,12 +339,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
     }
 
     @Override
-    public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor, boolean considerReservedCapacity) {
+    public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOvercommitRatio,float memoryOvercommitRatio, boolean considerReservedCapacity) {
         boolean hasCapacity = false;
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Checking if host: " + hostId + " has enough capacity for requested CPU: " + cpu + " and requested RAM: " + ram
-                    + " , cpuOverprovisioningFactor: " + cpuOverprovisioningFactor);
+                    + " , cpuOverprovisioningFactor: " + cpuOvercommitRatio);
         }
 
         CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
@@ -356,13 +370,13 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         long reservedCpu = capacityCpu.getReservedCapacity();
         long reservedMem = capacityMem.getReservedCapacity();
         long actualTotalCpu = capacityCpu.getTotalCapacity();
-        long totalCpu = (long) (actualTotalCpu * cpuOverprovisioningFactor);
+        long actualTotalMem = capacityMem.getTotalCapacity();
+        long totalCpu = (long) (actualTotalCpu * cpuOvercommitRatio );
+        long totalMem = (long) (actualTotalMem *memoryOvercommitRatio );
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
         }
 
-        long totalMem = capacityMem.getTotalCapacity();
-
         String failureReason = "";
         if (checkFromReservedCapacity) {
             long freeCpu = reservedCpu;
@@ -695,10 +709,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
             capacityCPU.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
             capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU);
             List<CapacityVO> capacityVOCpus = _capacityDao.search(capacitySC, null);
+            Float cpuovercommitratio = Float.parseFloat(_clusterDetailsDao.findDetail(server.getClusterId(),"cpuOvercommitRatio").getValue());
+            Float memoryOvercommitRatio = Float.parseFloat(_clusterDetailsDao.findDetail(server.getClusterId(),"memoryOvercommitRatio").getValue());
 
             if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
                 CapacityVO CapacityVOCpu = capacityVOCpus.get(0);
-                long newTotalCpu = (long) (server.getCpus().longValue() * server.getSpeed().longValue() * _cpuOverProvisioningFactor);
+                long newTotalCpu = (long) (server.getCpus().longValue() * server.getSpeed().longValue() * cpuovercommitratio);
                 if ((CapacityVOCpu.getTotalCapacity() <= newTotalCpu)
                         || ((CapacityVOCpu.getUsedCapacity() + CapacityVOCpu.getReservedCapacity()) <= newTotalCpu)) {
                     CapacityVOCpu.setTotalCapacity(newTotalCpu);
@@ -713,7 +729,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
                 _capacityDao.update(CapacityVOCpu.getId(), CapacityVOCpu);
             } else {
                 CapacityVO capacity = new CapacityVO(server.getId(), server.getDataCenterId(), server.getPodId(), server.getClusterId(), 0L,
-                        (long) (server.getCpus().longValue() * server.getSpeed().longValue() * _cpuOverProvisioningFactor),
+                        (long) (server.getCpus().longValue() * server.getSpeed().longValue()),
                         CapacityVO.CAPACITY_TYPE_CPU);
                 _capacityDao.persist(capacity);
             }
@@ -727,7 +743,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
 
             if (capacityVOMems != null && !capacityVOMems.isEmpty()) {
                 CapacityVO CapacityVOMem = capacityVOMems.get(0);
-                long newTotalMem = server.getTotalMemory();
+                long newTotalMem = (long)((server.getTotalMemory())* memoryOvercommitRatio);
                 if (CapacityVOMem.getTotalCapacity() <= newTotalMem
                         || (CapacityVOMem.getUsedCapacity() + CapacityVOMem.getReservedCapacity() <= newTotalMem)) {
                     CapacityVOMem.setTotalCapacity(newTotalMem);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/capacity/ComputeCapacityListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/ComputeCapacityListener.java b/server/src/com/cloud/capacity/ComputeCapacityListener.java
index 8ea695a..16e154a 100755
--- a/server/src/com/cloud/capacity/ComputeCapacityListener.java
+++ b/server/src/com/cloud/capacity/ComputeCapacityListener.java
@@ -42,12 +42,11 @@ public class ComputeCapacityListener implements Listener {
 
 
     public ComputeCapacityListener(CapacityDao _capacityDao,
-    		CapacityManager _capacityMgr,
-            float _overProvisioningFactor) {
+    		CapacityManager _capacityMgr
+           ) {
         super();
         this._capacityDao = _capacityDao;
         this._capacityMgr = _capacityMgr;
-        this._cpuOverProvisioningFactor = _overProvisioningFactor;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23e54bb0/server/src/com/cloud/capacity/dao/CapacityDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/dao/CapacityDao.java b/server/src/com/cloud/capacity/dao/CapacityDao.java
index 0c0723b..0132f69 100755
--- a/server/src/com/cloud/capacity/dao/CapacityDao.java
+++ b/server/src/com/cloud/capacity/dao/CapacityDao.java
@@ -26,20 +26,20 @@ import com.cloud.utils.db.GenericDao;
 
 public interface CapacityDao extends GenericDao<CapacityVO, Long> {
 	CapacityVO findByHostIdType(Long hostId, short capacityType);
-	List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor);
-	List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor);	
+	List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone);
+	List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType);
 	boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId);
 	List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId);
 	List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId,Long podId, Long clusterId);
-	Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor);
+	Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone);
 	List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId);
 	
-    List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType, float cpuOverprovisioningFactor);
-    Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityType, float cpuOverprovisioningFactor);
+    List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType);
+    Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityType);
     List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId,
             Long podId, Long clusterId, String resourceState);
     List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit);  
     void updateCapacityState(Long dcId, Long podId, Long clusterId,
             Long hostId, String capacityState);
-	List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long computeRequested, Float overProvFactor);
-}
+	List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long computeRequested);
+}


Mime
View raw message