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.

(cherry picked from commit ade305be20)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

Conflicts:
	server/src/com/cloud/capacity/CapacityManagerImpl.java
This commit is contained in:
Nitin Mehta 2014-11-13 13:54:45 -08:00 committed by Rohit Yadav
parent 665aa6b522
commit be0882b19e
3 changed files with 21 additions and 25 deletions

View File

@ -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<VMInstanceVO> 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 =

View File

@ -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);
}

View File

@ -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);