Skip to content

Commit cec3ac5

Browse files
committed
bug 12782 When host is put in maintenance remove the capacity entries in DB. When maintenance is cancelled repopulate the capacity entries in the DB. This is done to not account for the capacity of hosts in maintenance in the dashboard. Also for the capacity checker thread do not calaculate capacities for the hosts in maintenance.
Reviewed by : Kishan.
1 parent 3a6719a commit cec3ac5

4 files changed

Lines changed: 71 additions & 3 deletions

File tree

server/src/com/cloud/alert/AlertManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public void recalculateCapacity() {
289289

290290
// Calculate CPU and RAM capacities
291291
// get all hosts...even if they are not in 'UP' state
292-
List<HostVO> hosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
292+
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
293293
for (HostVO host : hosts) {
294294
_capacityMgr.updateCapacityForHost(host);
295295
}

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package com.cloud.capacity;
1919

20+
import java.net.URI;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -44,7 +45,9 @@
4445
import com.cloud.host.Status;
4546
import com.cloud.host.dao.HostDao;
4647
import com.cloud.offering.ServiceOffering;
48+
import com.cloud.resource.ResourceListener;
4749
import com.cloud.resource.ResourceManager;
50+
import com.cloud.resource.ServerResource;
4851
import com.cloud.service.ServiceOfferingVO;
4952
import com.cloud.service.dao.ServiceOfferingDao;
5053
import com.cloud.utils.DateUtil;
@@ -63,7 +66,7 @@
6366
import com.cloud.vm.dao.VMInstanceDao;
6467

6568
@Local(value = CapacityManager.class)
66-
public class CapacityManagerImpl implements CapacityManager, StateListener<State, VirtualMachine.Event, VirtualMachine>, Listener {
69+
public class CapacityManagerImpl implements CapacityManager, StateListener<State, VirtualMachine.Event, VirtualMachine>, Listener, ResourceListener {
6770
private static final Logger s_logger = Logger.getLogger(CapacityManagerImpl.class);
6871
String _name;
6972
@Inject
@@ -107,6 +110,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
107110

108111
@Override
109112
public boolean start() {
113+
_resourceMgr.registerResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, this);
114+
_resourceMgr.registerResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, this);
110115
return true;
111116
}
112117

@@ -698,4 +703,54 @@ public boolean processTimeout(long agentId, long seq) {
698703
return false;
699704
}
700705

706+
@Override
707+
public void processCancelMaintenaceEventAfter(Long hostId) {
708+
updateCapacityForHost(_hostDao.findById(hostId));
709+
}
710+
711+
@Override
712+
public void processCancelMaintenaceEventBefore(Long hostId) {
713+
// TODO Auto-generated method stub
714+
715+
}
716+
717+
@Override
718+
public void processDeletHostEventAfter(HostVO host) {
719+
// TODO Auto-generated method stub
720+
721+
}
722+
723+
@Override
724+
public void processDeleteHostEventBefore(HostVO host) {
725+
// TODO Auto-generated method stub
726+
727+
}
728+
729+
@Override
730+
public void processDiscoverEventAfter(
731+
Map<? extends ServerResource, Map<String, String>> resources) {
732+
// TODO Auto-generated method stub
733+
734+
}
735+
736+
@Override
737+
public void processDiscoverEventBefore(Long dcid, Long podId,
738+
Long clusterId, URI uri, String username, String password,
739+
List<String> hostTags) {
740+
// TODO Auto-generated method stub
741+
742+
}
743+
744+
@Override
745+
public void processPrepareMaintenaceEventAfter(Long hostId) {
746+
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_MEMORY, null, null, null, hostId);
747+
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_CPU, null, null, null, hostId);
748+
}
749+
750+
@Override
751+
public void processPrepareMaintenaceEventBefore(Long hostId) {
752+
// TODO Auto-generated method stub
753+
754+
}
755+
701756
}

server/src/com/cloud/resource/ResourceManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,6 @@ public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String,
131131
String getHostTags(long hostId);
132132

133133
List<PodCluster> listByDataCenter(long dcId);
134+
135+
List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId);
134136
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ public Host maintain(PrepareForMaintenanceCmd cmd) {
11001100
try {
11011101
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
11021102
if (maintain(hostId)) {
1103-
processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, hostId);
1103+
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, hostId);
11041104
return _hostDao.findById(hostId);
11051105
} else {
11061106
throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
@@ -1926,6 +1926,17 @@ public List<HostVO> listAllUpAndEnabledHostsInOneZoneByType(Type type, long dcId
19261926
return sc.list();
19271927
}
19281928

1929+
@Override
1930+
public List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId) {
1931+
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
1932+
if (dcId != null){
1933+
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
1934+
}
1935+
sc.addAnd(sc.getEntity().getType(), Op.EQ, type);
1936+
sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance, ResourceState.Error);
1937+
return sc.list();
1938+
}
1939+
19291940
@Override
19301941
public List<HostVO> listAllHostsInOneZoneByType(Type type, long dcId) {
19311942
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);

0 commit comments

Comments
 (0)