You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2013/07/25 10:13:28 UTC

git commit: updated refs/heads/master to 0010fae

Updated Branches:
  refs/heads/master 80ac885e2 -> 0010faee4


Fix for CLOUDSTACK-2536

Removing memoryovercommitratio and cpuovercommitratio parameters from addCluster and updateCluster APIs,
since these can be configurable using updateConfiguration API at cluster level.
By default while creating cluster these values are taken from global configuration parameters.


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

Branch: refs/heads/master
Commit: 0010faee4bac8ebb32ceb95ca6ff6b02b4013cba
Parents: 80ac885
Author: Harikrishna Patnala <ha...@citrix.com>
Authored: Thu Jul 25 12:47:50 2013 +0530
Committer: Koushik Das <ko...@apache.org>
Committed: Thu Jul 25 13:42:08 2013 +0530

----------------------------------------------------------------------
 api/src/com/cloud/resource/ResourceService.java |  2 +-
 .../org/apache/cloudstack/api/ApiConstants.java |  2 --
 .../command/admin/cluster/AddClusterCmd.java    | 23 ------------
 .../command/admin/cluster/UpdateClusterCmd.java | 36 ++-----------------
 .../configuration/ConfigurationManagerImpl.java | 31 +++++++++++++---
 .../com/cloud/resource/ResourceManagerImpl.java | 37 ++++----------------
 .../cloud/resource/MockResourceManagerImpl.java |  2 +-
 7 files changed, 36 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0010faee/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 25298cc..f1080b8 100755
--- a/api/src/com/cloud/resource/ResourceService.java
+++ b/api/src/com/cloud/resource/ResourceService.java
@@ -64,7 +64,7 @@ public interface ResourceService {
 
     boolean deleteCluster(DeleteClusterCmd cmd);
 
-    Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate,Float memoryOvercommitRatio, Float cpuOvercommitRatio);
+    Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate);
 
     List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0010faee/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 0550a39..121403f 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -48,7 +48,6 @@ 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 CUSTOMIZED_IOPS = "customizediops";
@@ -142,7 +141,6 @@ 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/cloudstack/blob/0010faee/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 c6ca9bc6..c8b012a 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
@@ -81,12 +81,6 @@ 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 memory overcommit ratio, defaults to 1")
-    private String memoryOvercommitRatio;
-
     @Parameter(name = ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, type = CommandType.STRING, required = false, description = "Type of virtual switch used for guest traffic in the cluster. Allowed values are, vmwaresvs (for VMware standard vSwitch) and vmwaredvs (for VMware distributed vSwitch)")
     private String vSwitchTypeGuestTraffic;
 
@@ -181,26 +175,9 @@ public class AddClusterCmd extends BaseCmd {
         this.allocationState = allocationState;
     }
 
-    public Float getCpuOvercommitRatio (){
-        if(cpuOvercommitRatio != null){
-           return Float.parseFloat(cpuOvercommitRatio);
-        }
-        return 1.0f;
-    }
-
-    public Float getMemoryOvercommitRatio(){
-        if (memoryOvercommitRatio != null){
-            return Float.parseFloat(memoryOvercommitRatio);
-        }
-        return 1.0f;
-    }
-
     @Override
     public void execute(){
         try {
-            if (getMemoryOvercommitRatio().compareTo(1f) < 0 || getCpuOvercommitRatio().compareTo(1f) < 0) {
-                throw new InvalidParameterValueException("cpu and memory overcommit ratios should be greater than or equal to one");
-            }
             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/cloudstack/blob/0010faee/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 a14f905..34d05c0 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,12 +54,6 @@ 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 memory overcommit ratio")
-    private String memoryovercommitratio;
-
 
     public String getClusterName() {
         return clusterName;
@@ -107,40 +101,14 @@ public class UpdateClusterCmd extends BaseCmd {
         this.managedState = managedstate;
     }
 
-    public Float getCpuOvercommitRatio (){
-        if(cpuovercommitratio != null){
-            return Float.parseFloat(cpuovercommitratio);
-        }
-        return null;
-    }
-
-    public Float getMemoryOvercommitRaito (){
-        if (memoryovercommitratio != null){
-            return Float.parseFloat(memoryovercommitratio);
-        }
-        return null;
-    }
-
     @Override
     public void execute(){
         Cluster cluster = _resourceService.getCluster(getId());
         if (cluster == null) {
             throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
         }
-        if (getMemoryOvercommitRaito() !=null){
-            if ((getMemoryOvercommitRaito().compareTo(1f) < 0)) {
-                throw new InvalidParameterValueException("Memory overcommit ratio should be greater than or equal to one");
-            }
-        }
-
-        if (getCpuOvercommitRatio() !=null){
-            if (getCpuOvercommitRatio().compareTo(1f) < 0) {
-                throw new InvalidParameterValueException("Cpu overcommit ratio should be greater than or equal to one");
-            }
-        }
-
-        Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate(), getMemoryOvercommitRaito(), getCpuOvercommitRatio());
-        if (result != null) {
+       Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
+       if (result != null) {
                 ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
                 clusterResponse.setResponseName(getCommandName());
                 this.setResponseObject(clusterResponse);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0010faee/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 9bc8efd..b2dedb3 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -313,6 +313,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
     private long _defaultPageSize = Long.parseLong(Config.DefaultPageSize.getDefaultValue());
     protected Set<String> configValuesForValidation;
     private Set<String> weightBasedParametersForValidation;
+    private Set<String> overprovisioningFactorsForValidation;
 
     @Override
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
@@ -326,6 +327,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
 
         populateConfigValuesForValidationSet();
         weightBasedParametersForValidation();
+        overProvisioningFactorsForValidation();
         return true;
     }
 
@@ -373,6 +375,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
 
     }
 
+    private void overProvisioningFactorsForValidation() {
+        overprovisioningFactorsForValidation = new HashSet<String>();
+        overprovisioningFactorsForValidation.add(Config.MemOverprovisioningFactor.key());
+        overprovisioningFactorsForValidation.add(Config.CPUOverprovisioningFactor.key());
+        overprovisioningFactorsForValidation.add(Config.StorageOverprovisioningFactor.key());
+    }
+
     @Override
     public boolean start() {
 
@@ -688,11 +697,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                 s_logger.error("Invalid scope id provided for the parameter " + name);
                 return "Invalid scope id provided for the parameter " + name;
             }
-            if ((name.equalsIgnoreCase("cpu.overprovisioning.factor") || name
-                    .equalsIgnoreCase("mem.overprovisioning.factor")) && value == null) {
-                s_logger.error("value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor");
-                return "value cannot be null for cpu.overprovisioning.factor/mem.overprovisioning.factor";
-            }
         }
 
         Class<?> type = c.getType();
@@ -701,9 +705,26 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
             if (type.equals(Boolean.class)) {
                 return "Please enter either 'true' or 'false'.";
             }
+            if (overprovisioningFactorsForValidation.contains(name)) {
+                String msg = "value cannot be null for the parameter " + name;
+                s_logger.error(msg);
+                return msg;
+            }
             return null;
         }
+
         value = value.trim();
+        try {
+            if (overprovisioningFactorsForValidation.contains(name) && (Float.parseFloat(value) < 1f)) {
+                String msg = name + " should be greater than or equal to 1";
+                s_logger.error(msg);
+                throw new InvalidParameterValueException(msg);
+            }
+        } catch (NumberFormatException e) {
+            String msg = "There was an error trying to parse the float value for: " + name;
+            s_logger.error(msg);
+            throw new InvalidParameterValueException(msg);
+        }
 
         if (type.equals(Boolean.class)) {
             if (!(value.equals("true") || value.equals("false"))) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0010faee/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index 342b9fd..c018770 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -30,6 +30,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.server.ConfigurationServer;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -214,6 +215,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
     PlannerHostReservationDao _plannerHostReserveDao;
     @Inject
     protected DedicatedResourceDao           _dedicatedDao;
+    @Inject
+    protected ConfigurationServer _configServer;
 
     protected List<? extends Discoverer> _discoverers;
 
@@ -479,8 +482,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         clusterId = cluster.getId();
         result.add(cluster);
 
-        ClusterDetailsVO cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
-        ClusterDetailsVO cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRatio()));
+        ClusterDetailsVO cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", _configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), null, null));
+        ClusterDetailsVO cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", _configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), null, null));
         _clusterDetailsDao.persist(cluster_detail_cpu);
         _clusterDetailsDao.persist(cluster_detail_ram);
 
@@ -495,20 +498,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         details.put("password", password);
         _clusterDetailsDao.persist(cluster.getId(), details);
 
-        _clusterDetailsDao.persist(cluster_detail_cpu);
-        _clusterDetailsDao.persist(cluster_detail_ram);
-        // create a new entry only if the overcommit ratios are greater than 1.
-        if (cmd.getCpuOvercommitRatio().compareTo(1f) > 0) {
-            cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
-            _clusterDetailsDao.persist(cluster_detail_cpu);
-        }
-
-
-        if(cmd.getMemoryOvercommitRatio().compareTo(1f) > 0) {
-             cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRatio()));
-            _clusterDetailsDao.persist(cluster_detail_ram);
-        }
-
         boolean success = false;
         try {
             try {
@@ -998,8 +987,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
 
     @Override
     @DB
-    public Cluster updateCluster(Cluster clusterToUpdate, String clusterType, String hypervisor, String allocationState, String managedstate,
-            Float memoryovercommitratio, Float cpuovercommitratio) {
+    public Cluster updateCluster(Cluster clusterToUpdate, String clusterType, String hypervisor, String allocationState, String managedstate) {
 
         ClusterVO cluster = (ClusterVO) clusterToUpdate;
         // Verify cluster information and update the cluster if needed
@@ -1065,19 +1053,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
             }
         }
 
-
-       if (memoryovercommitratio != null) {
-           ClusterDetailsVO memory_detail = _clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio");
-           memory_detail.setValue(Float.toString(memoryovercommitratio));
-           _clusterDetailsDao.update(memory_detail.getId(),memory_detail);
-       }
-
-       if (cpuovercommitratio != null) {
-            ClusterDetailsVO cpu_detail = _clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio");
-            cpu_detail.setValue(Float.toString(cpuovercommitratio));
-            _clusterDetailsDao.update(cpu_detail.getId(),cpu_detail);
-       }
-
         if (doUpdate) {
             Transaction txn = Transaction.currentTxn();
             try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0010faee/server/test/com/cloud/resource/MockResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java
index 2c66134..6beb064 100644
--- a/server/test/com/cloud/resource/MockResourceManagerImpl.java
+++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java
@@ -107,7 +107,7 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana
      */
     @Override
     public Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState,
-                                 String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio) {
+                                 String managedstate) {
         // TODO Auto-generated method stub
         return null;
     }