cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject [1/2] git commit: updated refs/heads/master to b385cb4
Date Wed, 11 Dec 2013 08:50:51 GMT
Updated Branches:
  refs/heads/master d715058fa -> b385cb4f7


CLOUDSTACK-4498 we should not reserve memory and cpu for vmware VMs if the
vmware.reserve.cpu and vmware.reserve.mem are set to false while not overcommiting

Signed-off-by: Jayapal <jayapal@apache.org>


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

Branch: refs/heads/master
Commit: 36cbc2dfbff35bf909194cc17610cf70a86914a5
Parents: d715058
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Mon Dec 9 12:34:04 2013 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Wed Dec 11 13:07:56 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/hypervisor/guru/VMwareGuru.java   | 33 ++++++++++++++--
 .../vmware/manager/VmwareManagerImpl.java       |  2 -
 .../vmware/resource/VmwareResource.java         | 41 +++++++++++++++-----
 3 files changed, 60 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36cbc2df/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index 081c651..f9da9de 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -27,8 +27,12 @@ import java.util.UUID;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.vm.dao.VMInstanceDao;
 import org.apache.log4j.Logger;
 
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.storage.command.CopyCommand;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
@@ -92,8 +96,8 @@ import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VmDetailConstants;
 import com.cloud.vm.dao.NicDao;
 
-@Local(value = HypervisorGuru.class)
-public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
+@Local(value=HypervisorGuru.class)
+public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable
{
     private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
 
     @Inject
@@ -121,12 +125,21 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru
{
     @Inject
     PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
     @Inject
-    ClusterManager _clusterMgr;
+    VMInstanceDao _vmDao;
+    @Inject
+    ClusterDao _clusterDao;
+    @Inject ClusterManager _clusterMgr;
 
     protected VMwareGuru() {
         super();
     }
 
+    static final ConfigKey<Boolean> VmwareReserveCpu = new ConfigKey<Boolean>(Boolean.class,
"vmware.reserve.cpu", "Advanced", "false",
+            "Specify whether or not to reserve CPU when not overprovisioning, In case of
cpu overprovisioning we will always reserve cpu.", true, ConfigKey.Scope.Cluster, null);
+
+    static final ConfigKey<Boolean> VmwareReserveMemory = new ConfigKey<Boolean>(Boolean.class,
"vmware.reserve.cpu", "Advanced", "false",
+            "Specify whether or not to reserve memory when not overprovisioning, In case
of memory overprovisioning we will always reserve memory.", true, ConfigKey.Scope.Cluster,
null);
+
     @Override
     public HypervisorType getHypervisorType() {
         return HypervisorType.VMware;
@@ -187,7 +200,9 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru
{
                 break;
             }
         }
-
+        long clusterId = _hostDao.findById( _vmDao.findById(vm.getId()).getHostId()).getClusterId();
+        details.put(Config.VmwareReserveCpu.key(), VmwareReserveCpu.valueIn(clusterId).toString());
+        details.put(Config.VmwareReserveMem.key(), VmwareReserveMemory.valueIn(clusterId).toString());
         to.setDetails(details);
 
         if (vm.getVirtualMachine() instanceof DomainRouterVO) {
@@ -436,4 +451,14 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru
{
         }
         return commands;
     }
+
+    @Override
+    public String getConfigComponentName() {
+        return VMwareGuru.class.getSimpleName();
+    }
+
+    @Override
+    public ConfigKey<?>[] getConfigKeys() {
+        return new ConfigKey<?>[] {VmwareReserveCpu, VmwareReserveMemory};
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36cbc2df/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 066a395..e63999c 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
@@ -548,8 +548,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager,
Vmw
         params.put("vm.instancename.flag", _instanceNameFlag);
         params.put("service.console.name", _serviceConsoleName);
         params.put("management.portgroup.name", _managemetPortGroupName);
-        params.put("vmware.reserve.cpu", _reserveCpu);
-        params.put("vmware.reserve.mem", _reserveMem);
         params.put("vmware.root.disk.controller", _rootDiskController);
         params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
         params.put("ports.per.dvportgroup", _portsPerDvPortGroup);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36cbc2df/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 e34d5e1..71894a8 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
@@ -45,6 +45,9 @@ import java.util.concurrent.TimeUnit;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.configuration.Config;
+import com.cloud.agent.api.routing.*;
+
 import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
 
@@ -362,10 +365,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
     protected int _portsPerDvPortGroup;
     protected boolean _fullCloneFlag = false;
     protected boolean _instanceNameFlag = false;
+    protected boolean  _reserveCpu;
+    protected boolean  _reserveMem;
 
-    protected boolean _reserveCpu = false;
-
-    protected boolean _reserveMem = false;
     protected boolean _recycleHungWorker = false;
     protected DiskControllerType _rootDiskController = DiskControllerType.ide;
 
@@ -2700,7 +2702,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                         vmMo.tearDownDevices(new Class<?>[] {VirtualEthernetCard.class});
                     vmMo.ensureScsiDeviceController();
                 } else {
-                    int ramMb = (int)(vmSpec.getMinRam() / (1024 * 1024));
                     Pair<ManagedObjectReference, DatastoreMO> rootDiskDataStoreDetails
= null;
                     for (DiskTO vol : disks) {
                         if (vol.getType() == Volume.Type.ROOT) {
@@ -2717,9 +2718,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                             dcMo.getMor(), false);
                     }
 
-                    if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(),
vmSpec.getMaxSpeed().intValue(), vmSpec.getMinSpeed(),
-                        vmSpec.getLimitCpuUse(), (int)(vmSpec.getMaxRam() / (1024 * 1024)),
ramMb, translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(),
-                        rootDiskDataStoreDetails.first(), false)) {
+                    if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(),
vmSpec.getMaxSpeed().intValue(),
+                            getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)),
getReservedMemoryMb(vmSpec),
+                            translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(),
rootDiskDataStoreDetails.first(), false)) {
                         throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
                     }
                 }
@@ -2743,11 +2744,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             }
 
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
-            int ramMb = (int)(vmSpec.getMinRam() / (1024 * 1024));
             String guestOsId = translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value();
 
-            VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
vmSpec.getMinSpeed(), (int)(vmSpec.getMaxRam() / (1024 * 1024)), ramMb,
-                guestOsId, vmSpec.getLimitCpuUse());
+            VmwareHelper.setBasicVmConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(),
+                    getReservedCpuMHZ(vmSpec),(int) (vmSpec.getMaxRam()/(1024*1024)), getReservedMemoryMb(vmSpec),
+                    guestOsId, vmSpec.getLimitCpuUse());
 
             // Check for hotadd settings
             vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId));
@@ -3003,6 +3004,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         }
     }
 
+    int getReservedMemoryMb(VirtualMachineTO vmSpec) {
+        if (vmSpec.getDetails().get(Config.VmwareReserveMem.key()).equalsIgnoreCase("true"))
{
+              return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+        }  else if (vmSpec.getMinRam() != vmSpec.getMaxRam()) {
+              s_logger.warn("memory overprovisioning factor is set to "+ (vmSpec.getMaxRam()/vmSpec.getMinRam())+"
ignoring the flag vmware.reserve.mem");
+              return  (int) (vmSpec.getMinRam() / (1024 * 1024));
+        }
+        return 0;
+    }
+
+    int getReservedCpuMHZ(VirtualMachineTO vmSpec) {
+         if (vmSpec.getDetails().get(Config.VmwareReserveCpu.key()).equalsIgnoreCase("true"))
{
+              return vmSpec.getMinSpeed();
+         }else if (vmSpec.getMinSpeed().intValue() != vmSpec.getMaxSpeed().intValue()) {
+              s_logger.warn("cpu overprovisioning factor is set to "+ (vmSpec.getMaxSpeed().intValue()/vmSpec.getMinSpeed().intValue())+"
ignoring the flag vmware.reserve.cpu");
+              return vmSpec.getMinSpeed();
+         }
+         return 0;
+    }
+
     // return the finalized disk chain for startup, from top to bottom
     private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO
vmSpec, DiskTO vol, VirtualMachineDiskInfo diskInfo,
         HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails)
throws Exception {


Mime
View raw message