diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index e5b7d191e2c..5ea7e3e4b71 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -27,6 +27,8 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.resource.ResourceState; + import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; @@ -49,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; @@ -67,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; @@ -597,6 +597,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()) { @@ -680,6 +681,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: " + @@ -702,6 +709,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: " + @@ -741,14 +753,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 d9ce3fd3689..b18e1541723 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1237,9 +1237,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); } @@ -1774,7 +1773,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 5a1b8ce3f0e..57231964388 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; @@ -68,7 +69,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; @@ -126,7 +126,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; @@ -1041,7 +1040,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; } @@ -1163,14 +1161,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);