Skip to content

Commit ade305b

Browse files
committed
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.
1 parent 92d4a41 commit ade305b

3 files changed

Lines changed: 20 additions & 25 deletions

File tree

‎server/src/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import com.cloud.resource.ResourceState;
3031
import com.cloud.utils.fsm.StateMachine2;
3132
import org.apache.log4j.Logger;
3233

@@ -50,7 +51,6 @@
5051
import com.cloud.agent.api.Command;
5152
import com.cloud.agent.api.StartupCommand;
5253
import com.cloud.agent.api.StartupRoutingCommand;
53-
import com.cloud.api.ApiDBUtils;
5454
import com.cloud.capacity.dao.CapacityDao;
5555
import com.cloud.configuration.Config;
5656
import com.cloud.configuration.ConfigurationManager;
@@ -68,7 +68,6 @@
6868
import com.cloud.hypervisor.Hypervisor.HypervisorType;
6969
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
7070
import com.cloud.offering.ServiceOffering;
71-
import com.cloud.org.Grouping.AllocationState;
7271
import com.cloud.resource.ResourceListener;
7372
import com.cloud.resource.ResourceManager;
7473
import com.cloud.resource.ServerResource;
@@ -596,6 +595,7 @@ public void updateCapacityForHost(final Host host) {
596595
long usedMemory = 0;
597596
long reservedMemory = 0;
598597
long reservedCpu = 0;
598+
final CapacityState capacityState = (host.getResourceState() == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled;
599599

600600
List<VMInstanceVO> vms = _vmDao.listUpByHostId(host.getId());
601601
if (s_logger.isDebugEnabled()) {
@@ -679,6 +679,12 @@ public void updateCapacityForHost(final Host host) {
679679
cpuCap.setTotalCapacity(hostTotalCpu);
680680

681681
}
682+
// Set the capacity state as per the host allocation state.
683+
if(capacityState != cpuCap.getCapacityState()){
684+
s_logger.debug("Calibrate cpu capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
685+
cpuCap.setCapacityState(capacityState);
686+
}
687+
memCap.setCapacityState(capacityState);
682688

683689
if (cpuCap.getUsedCapacity() == usedCpu && cpuCap.getReservedCapacity() == reservedCpu) {
684690
s_logger.debug("No need to calibrate cpu capacity, host:" + host.getId() + " usedCpu: " + cpuCap.getUsedCapacity() + " reservedCpu: " +
@@ -701,6 +707,11 @@ public void updateCapacityForHost(final Host host) {
701707
memCap.setTotalCapacity(host.getTotalMemory());
702708

703709
}
710+
// Set the capacity state as per the host allocation state.
711+
if(capacityState != memCap.getCapacityState()){
712+
s_logger.debug("Calibrate memory capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu);
713+
memCap.setCapacityState(capacityState);
714+
}
704715

705716
if (memCap.getUsedCapacity() == usedMemory && memCap.getReservedCapacity() == reservedMemory) {
706717
s_logger.debug("No need to calibrate memory capacity, host:" + host.getId() + " usedMem: " + memCap.getUsedCapacity() + " reservedMem: " +
@@ -740,14 +751,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
740751
new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemoryFinal, host.getTotalMemory(),
741752
Capacity.CAPACITY_TYPE_MEMORY);
742753
capacity.setReservedCapacity(reservedMemoryFinal);
743-
CapacityState capacityState = CapacityState.Enabled;
744-
if (host.getClusterId() != null) {
745-
ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId());
746-
if (cluster != null) {
747-
capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
748-
capacity.setCapacityState(capacityState);
749-
}
750-
}
754+
capacity.setCapacityState(capacityState);
751755
_capacityDao.persist(capacity);
752756

753757
capacity =

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,9 +1206,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
12061206
String ipRange = startIp + "-" + endIp;
12071207
pod.setDescription(ipRange);
12081208
Grouping.AllocationState allocationState = null;
1209-
if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
1210-
allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
1211-
_capacityDao.updateCapacityState(null, pod.getId(), null, null, allocationStateStrFinal);
1209+
if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) {
1210+
allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal);
12121211
pod.setAllocationState(allocationState);
12131212
}
12141213

@@ -1743,7 +1742,6 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
17431742
throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage());
17441743
}
17451744
}
1746-
_capacityDao.updateCapacityState(zone.getId(), null, null, null, allocationStateStr);
17471745
zone.setAllocationState(allocationState);
17481746
}
17491747

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.inject.Inject;
3131
import javax.naming.ConfigurationException;
3232

33+
import com.cloud.capacity.CapacityState;
3334
import com.cloud.vm.VirtualMachine;
3435
import org.apache.cloudstack.api.ApiConstants;
3536
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
@@ -67,7 +68,6 @@
6768
import com.cloud.agent.api.VgpuTypesInfo;
6869
import com.cloud.agent.api.to.GPUDeviceTO;
6970
import com.cloud.agent.transport.Request;
70-
import com.cloud.api.ApiDBUtils;
7171
import com.cloud.capacity.Capacity;
7272
import com.cloud.capacity.CapacityManager;
7373
import com.cloud.capacity.CapacityVO;
@@ -123,7 +123,6 @@
123123
import com.cloud.network.dao.IPAddressVO;
124124
import com.cloud.org.Cluster;
125125
import com.cloud.org.Grouping;
126-
import com.cloud.org.Grouping.AllocationState;
127126
import com.cloud.org.Managed;
128127
import com.cloud.serializer.GsonHelper;
129128
import com.cloud.service.dao.ServiceOfferingDetailsDao;
@@ -1038,7 +1037,6 @@ public Cluster updateCluster(Cluster clusterToUpdate, String clusterType, String
10381037
s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State");
10391038
throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state");
10401039
} else {
1041-
_capacityDao.updateCapacityState(null, null, cluster.getId(), null, allocationState);
10421040
cluster.setAllocationState(newAllocationState);
10431041
doUpdate = true;
10441042
}
@@ -1160,14 +1158,9 @@ public boolean resourceStateTransitTo(Host host, ResourceState.Event event, long
11601158
throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event);
11611159
}
11621160

1163-
// TO DO - Make it more granular and have better conversion into
1164-
// capacity type
1165-
1166-
if (host.getType() == Type.Routing && host.getClusterId() != null) {
1167-
AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId()));
1168-
if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled) {
1169-
capacityState = AllocationState.Disabled;
1170-
}
1161+
// TO DO - Make it more granular and have better conversion into capacity type
1162+
if(host.getType() == Type.Routing){
1163+
CapacityState capacityState = (nextState == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled;
11711164
_capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString());
11721165
}
11731166
return _hostDao.updateResourceState(currentState, event, nextState, host);

0 commit comments

Comments
 (0)