You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2014/11/13 22:55:30 UTC

git commit: updated refs/heads/master to ade305b

Repository: cloudstack
Updated Branches:
  refs/heads/master 92d4a41a6 -> ade305be2


CLOUDSTACK-7909: Change the capacity_state in op_host_Capacity table only on explicit enabling/disabling of the host and remove the logic for changing it when cluster/pod/zone is enabled/disabled. Also add the logic in capacity checker thread so that previous  changes finally get consistent with this new model and also its good to have it for sanity reasons.


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

Branch: refs/heads/master
Commit: ade305be20021d20a881693625864f46a335ea98
Parents: 92d4a41
Author: Nitin Mehta <ni...@citrix.com>
Authored: Thu Nov 13 13:54:45 2014 -0800
Committer: Nitin Mehta <ni...@citrix.com>
Committed: Thu Nov 13 13:54:45 2014 -0800

----------------------------------------------------------------------
 .../com/cloud/capacity/CapacityManagerImpl.java | 24 ++++++++++++--------
 .../configuration/ConfigurationManagerImpl.java |  6 ++---
 .../com/cloud/resource/ResourceManagerImpl.java | 15 ++++--------
 3 files changed, 20 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ade305be/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 a5521cc..15cc36a 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -27,6 +27,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import com.cloud.resource.ResourceState;
 import com.cloud.utils.fsm.StateMachine2;
 import org.apache.log4j.Logger;
 
@@ -50,7 +51,6 @@ import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupRoutingCommand;
-import com.cloud.api.ApiDBUtils;
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
@@ -68,7 +68,6 @@ import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
 import com.cloud.offering.ServiceOffering;
-import com.cloud.org.Grouping.AllocationState;
 import com.cloud.resource.ResourceListener;
 import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ServerResource;
@@ -596,6 +595,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         long usedMemory = 0;
         long reservedMemory = 0;
         long reservedCpu = 0;
+        final CapacityState capacityState = (host.getResourceState() == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled;
 
         List<VMInstanceVO> vms = _vmDao.listUpByHostId(host.getId());
         if (s_logger.isDebugEnabled()) {
@@ -679,6 +679,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
                 cpuCap.setTotalCapacity(hostTotalCpu);
 
             }
+            // Set the capacity state as per the host allocation state.
+            if(capacityState != cpuCap.getCapacityState()){
+                s_logger.debug("Calibrate cpu capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
+                cpuCap.setCapacityState(capacityState);
+            }
+            memCap.setCapacityState(capacityState);
 
             if (cpuCap.getUsedCapacity() == usedCpu && cpuCap.getReservedCapacity() == reservedCpu) {
                 s_logger.debug("No need to calibrate cpu capacity, host:" + host.getId() + " usedCpu: " + cpuCap.getUsedCapacity() + " reservedCpu: " +
@@ -701,6 +707,11 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
                 memCap.setTotalCapacity(host.getTotalMemory());
 
             }
+            // Set the capacity state as per the host allocation state.
+            if(capacityState != memCap.getCapacityState()){
+                s_logger.debug("Calibrate memory capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
+                memCap.setCapacityState(capacityState);
+            }
 
             if (memCap.getUsedCapacity() == usedMemory && memCap.getReservedCapacity() == reservedMemory) {
                 s_logger.debug("No need to calibrate memory capacity, host:" + host.getId() + " usedMem: " + memCap.getUsedCapacity() + " reservedMem: " +
@@ -740,14 +751,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
                         new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemoryFinal, host.getTotalMemory(),
                             Capacity.CAPACITY_TYPE_MEMORY);
                     capacity.setReservedCapacity(reservedMemoryFinal);
-                    CapacityState capacityState = CapacityState.Enabled;
-                    if (host.getClusterId() != null) {
-                        ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId());
-                        if (cluster != null) {
-                            capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
-                            capacity.setCapacityState(capacityState);
-                        }
-                    }
+                    capacity.setCapacityState(capacityState);
                     _capacityDao.persist(capacity);
 
                     capacity =

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ade305be/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 84fe50a..75fcc26 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1206,9 +1206,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
             String ipRange = startIp + "-" + endIp;
             pod.setDescription(ipRange);
             Grouping.AllocationState allocationState = null;
-                    if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
-                        allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
-                        _capacityDao.updateCapacityState(null, pod.getId(), null, null, allocationStateStrFinal);
+            if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
+                allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
                 pod.setAllocationState(allocationState);
             }
 
@@ -1743,7 +1742,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                     throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
                 }
             }
-            _capacityDao.updateCapacityState(zone.getId(), null, null, null, allocationStateStr);
             zone.setAllocationState(allocationState);
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ade305be/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 30d8568..5cbb7f3 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.capacity.CapacityState;
 import com.cloud.vm.VirtualMachine;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
@@ -67,7 +68,6 @@ import com.cloud.agent.api.UpdateHostPasswordCommand;
 import com.cloud.agent.api.VgpuTypesInfo;
 import com.cloud.agent.api.to.GPUDeviceTO;
 import com.cloud.agent.transport.Request;
-import com.cloud.api.ApiDBUtils;
 import com.cloud.capacity.Capacity;
 import com.cloud.capacity.CapacityManager;
 import com.cloud.capacity.CapacityVO;
@@ -123,7 +123,6 @@ import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.org.Cluster;
 import com.cloud.org.Grouping;
-import com.cloud.org.Grouping.AllocationState;
 import com.cloud.org.Managed;
 import com.cloud.serializer.GsonHelper;
 import com.cloud.service.dao.ServiceOfferingDetailsDao;
@@ -1038,7 +1037,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
                 s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
                 throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
             } else {
-                _capacityDao.updateCapacityState(null, null, cluster.getId(), null, allocationState);
                 cluster.setAllocationState(newAllocationState);
                 doUpdate = true;
             }
@@ -1160,14 +1158,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
             throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event);
         }
 
-        // TO DO - Make it more granular and have better conversion into
-        // capacity type
-
-        if (host.getType() == Type.Routing && host.getClusterId() != null) {
-            AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId()));
-            if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled) {
-                capacityState = AllocationState.Disabled;
-            }
+        // TO DO - Make it more granular and have better conversion into capacity type
+        if(host.getType() == Type.Routing){
+            CapacityState capacityState =  (nextState == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled;
             _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString());
         }
         return _hostDao.updateResourceState(currentState, event, nextState, host);