diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index a5521ccd354..15cc36a3e65 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 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 = diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 84fe50a6783..75fcc260d1d 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); } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 30d856878d4..5cbb7f302e4 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);