Updated Branches:
  refs/heads/4.2 5deefb1ec -> 738e7257c

Cloudstack-5077:  reserve cpu and memory only when
 vmware.reserve.cpu/mem are set to true. Insted of setting
 the ovecommit values to one on upgrade, we popultate them
 from the global values.
Signed off by : nitin mehta<[email protected]>


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

Branch: refs/heads/4.2
Commit: 738e7257c2844957a35788792be6277931ada4a5
Parents: 5deefb1
Author: bharat kumar <[email protected]>
Authored: Tue Nov 12 22:54:57 2013 -0800
Committer: Nitin Mehta <[email protected]>
Committed: Tue Nov 12 22:55:06 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade410to420.java  |  2 +-
 .../com/cloud/upgrade/dao/Upgrade420to421.java  | 60 +++++++++++++++-----
 .../vmware/resource/VmwareResource.java         |  6 --
 server/src/com/cloud/configuration/Config.java  |  4 +-
 setup/db/db/schema-420to421.sql                 |  3 +-
 5 files changed, 52 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/738e7257/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 646b406..a876802 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -937,7 +937,7 @@ public class Upgrade410to420 implements DbUpgrade {
                 }else {
                     //update cluster_details table with the default overcommit 
ratios.
                     pstmt1.setLong(1,id);
-                    pstmt1.setString(2,"1");
+                    pstmt1.setString(2,global_cpu_overprovisioning_factor);
                     pstmt1.execute();
                     pstmt2.setLong(1,id);
                     pstmt2.setString(2,"1");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/738e7257/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
index d37c0a1..a105ce5 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
@@ -23,6 +23,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import com.cloud.hypervisor.Hypervisor;
 import org.apache.log4j.Logger;
 
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -68,6 +69,8 @@ public class Upgrade420to421 implements DbUpgrade {
         updateCpuOverprovisioning(conn);
     }
 
+
+
     private void updateCpuOverprovisioning(Connection conn) {
         PreparedStatement pstmt1 = null;
         PreparedStatement pstmt2 = null;
@@ -80,27 +83,49 @@ public class Upgrade420to421 implements DbUpgrade {
         try {
             pstmt1 = conn.prepareStatement("select value from 
`cloud`.`configuration` where name='cpu.overprovisioning.factor'");
             result1 = pstmt1.executeQuery();
-            String overprov = "1";
+            String cpuoverprov = "1";
             if(result1.next()){
-                overprov = result1.getString(1);
+                cpuoverprov = result1.getString(1);
             }
+            pstmt1 = conn.prepareStatement("select value from 
`cloud`.`configuration` where name='mem.overprovisioning.factor'");
+            result1 = pstmt1.executeQuery();
+            String memoverprov = "1";
+            if(result1.next()){
+                memoverprov = result1.getString(1);
+            }
+
             // Need to populate only when overprovisioning factor doesn't pre 
exist.
             s_logger.debug("Starting updating user_vm_details with cpu/memory 
overprovisioning factors");
-            pstmt2 = conn.prepareStatement("select id from 
`cloud`.`vm_instance` where removed is null and id not in (select vm_id from  
`cloud`.`user_vm_details` where name='cpuOvercommitRatio')");
+            pstmt2 = conn.prepareStatement("select id, hypervisor_type from 
`cloud`.`vm_instance` where removed is null and id not in (select vm_id from  
`cloud`.`user_vm_details` where name='cpuOvercommitRatio')");
             pstmt3 = conn.prepareStatement("INSERT IGNORE INTO 
cloud.user_vm_details (vm_id, name, value) VALUES (?, ?, ?)");
             result2 = pstmt2.executeQuery();
             while (result2.next()) {
-                //For cpu
-                pstmt3.setLong(1, result2.getLong(1));
-                pstmt3.setString(2, "cpuOvercommitRatio");
-                pstmt3.setString(3, overprov);
-                pstmt3.executeUpdate();
+                String hypervisor_type = result2.getString(2);
+                if 
(hypervisor_type.equalsIgnoreCase(Hypervisor.HypervisorType.VMware.name())) {
+                    //For cpu
+                    pstmt3.setLong(1, result2.getLong(1));
+                    pstmt3.setString(2, "cpuOvercommitRatio");
+                    pstmt3.setString(3, cpuoverprov);
+                    pstmt3.executeUpdate();
 
-                // For memory
-                pstmt3.setLong(1, result2.getLong(1));
-                pstmt3.setString(2, "memoryOvercommitRatio");
-                pstmt3.setString(3, "1"); // memory overprovisioning didn't 
exist earlier.
-                pstmt3.executeUpdate();
+                    // For memory
+                    pstmt3.setLong(1, result2.getLong(1));
+                    pstmt3.setString(2, "memoryOvercommitRatio");
+                    pstmt3.setString(3, memoverprov); // memory 
overprovisioning was used to reserve memory in case of VMware.
+                    pstmt3.executeUpdate();
+                } else {
+                    //For cpu
+                    pstmt3.setLong(1, result2.getLong(1));
+                    pstmt3.setString(2, "cpuOvercommitRatio");
+                    pstmt3.setString(3, cpuoverprov);
+                    pstmt3.executeUpdate();
+
+                    // For memory
+                    pstmt3.setLong(1, result2.getLong(1));
+                    pstmt3.setString(2, "memoryOvercommitRatio");
+                    pstmt3.setString(3, "1"); // memory overprovisioning 
didn't exist earlier.
+                    pstmt3.executeUpdate();
+                }
             }
             s_logger.debug("Done updating user_vm_details with cpu/memory 
overprovisioning factors");
 
@@ -108,7 +133,16 @@ public class Upgrade420to421 implements DbUpgrade {
         } catch (SQLException e) {
             throw new CloudRuntimeException("Unable to update cpu/memory 
overprovisioning factors", e);
         } finally {
+            try {
+                if (result1 != null) {
+                    result1.close();
+                }
+                if (result2 != null) {
+                   result2.close();
+                }
+            }catch (SQLException e){
 
+            }
         }
 
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/738e7257/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 4921925..d198adb 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
@@ -3007,9 +3007,6 @@ 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;
     }
@@ -3017,9 +3014,6 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
     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;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/738e7257/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java 
b/server/src/com/cloud/configuration/Config.java
index f06b463..4d5c0c0 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -298,8 +298,8 @@ public enum Config {
     VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, 
Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port 
number of additional VNC port range", null),
     VmwareAdditionalVncPortRangeSize("Advanced", ManagementServer.class, 
Integer.class, "vmware.additional.vnc.portrange.size", "1000", "Start port 
number of additional VNC port range", null),
     //VmwareGuestNicDeviceType("Advanced", ManagementServer.class, 
String.class, "vmware.guest.nic.device.type", "E1000", "Ethernet card type used 
in guest VM, valid values are E1000, PCNet32, Vmxnet2, Vmxnet3", null),
-    VmwareReserveCpu("Advanced", ManagementServer.class, Boolean.class, 
"vmware.reserve.cpu", "false", "Specify whether or not to reserve CPU when not 
overprovisioning, In case of cpu overprovisioning we will always reserve cpu", 
null, ConfigurationParameterScope.cluster.toString()),
-    VmwareReserveMem("Advanced", ManagementServer.class, Boolean.class, 
"vmware.reserve.mem", "false", "Specify whether or not to reserve memory when 
not overprovisioning, In case of memory overprovisioning we will always reserve 
memory", null, ConfigurationParameterScope.cluster.toString()),
+    VmwareReserveCpu("Advanced", ManagementServer.class, Boolean.class, 
"vmware.reserve.cpu", "false", "Specify whether or not to reserve CPU based on 
CPU overprovisioning factor", null),
+    VmwareReserveMem("Advanced", ManagementServer.class, Boolean.class, 
"vmware.reserve.mem", "false", "Specify whether or not to reserve memory based 
on memory overprovisioning factor", null),
     VmwareRootDiskControllerType("Advanced", ManagementServer.class, 
String.class, "vmware.root.disk.controller", "ide", "Specify the default disk 
controller for root volumes, valid values are scsi, ide", null),
     VmwareSystemVmNicDeviceType("Advanced", ManagementServer.class, 
String.class, "vmware.systemvm.nic.device.type", "E1000", "Specify the default 
network device type for system VMs, valid values are E1000, PCNet32, Vmxnet2, 
Vmxnet3", null),
     VmwareRecycleHungWorker("Advanced", ManagementServer.class, Boolean.class, 
"vmware.recycle.hung.wokervm", "false", "Specify whether or not to recycle hung 
worker VMs", null),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/738e7257/setup/db/db/schema-420to421.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-420to421.sql b/setup/db/db/schema-420to421.sql
index 302d44a..c09a1bb 100644
--- a/setup/db/db/schema-420to421.sql
+++ b/setup/db/db/schema-420to421.sql
@@ -24,7 +24,8 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES 
('Advanced', 'DEFAULT', 'manag
     'The maximum size limit for S3 single part upload API(in GB). If it is set 
to 0, then it means always use multi-part upload to upload object to S3. If it 
is set to -1, then it means always use single-part upload to upload object to 
S3.');
 
 INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Storage", 'DEFAULT', 
'management-server', "enable.ha.storage.migration", "true", "Enable/disable 
storage migration across primary storage during HA"); 
-
+UPDATE `cloud`.`configuration` SET description="Specify whether or not to 
reserve CPU based on CPU overprovisioning factor" where 
name="vmware.reserve.cpu";
+UPDATE `cloud`.`configuration` SET description="Specify whether or not to 
reserve memory based on memory overprovisioning factor" where 
name="vmware.reserve.mem";
 -- Remove Windows Server 8 from guest_os_type dropdown to use Windows Server 
2012
 DELETE FROM `cloud`.`guest_os_hypervisor` where guest_os_id=168;
 DELETE FROM `cloud`.`guest_os` where id=168;

Reply via email to