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.
This commit is contained in:
Nitin Mehta 2012-01-03 17:21:05 +05:30
parent 3a6719aa1b
commit cec3ac5e38
4 changed files with 71 additions and 3 deletions

View File

@ -289,7 +289,7 @@ public class AlertManagerImpl implements AlertManager {
// Calculate CPU and RAM capacities
// get all hosts...even if they are not in 'UP' state
List<HostVO> hosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
for (HostVO host : hosts) {
_capacityMgr.updateCapacityForHost(host);
}

View File

@ -17,6 +17,7 @@
*/
package com.cloud.capacity;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -44,7 +45,9 @@ import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceListener;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ServerResource;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.utils.DateUtil;
@ -63,7 +66,7 @@ import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.VMInstanceDao;
@Local(value = CapacityManager.class)
public class CapacityManagerImpl implements CapacityManager, StateListener<State, VirtualMachine.Event, VirtualMachine>, Listener {
public class CapacityManagerImpl implements CapacityManager, StateListener<State, VirtualMachine.Event, VirtualMachine>, Listener, ResourceListener {
private static final Logger s_logger = Logger.getLogger(CapacityManagerImpl.class);
String _name;
@Inject
@ -107,6 +110,8 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
@Override
public boolean start() {
_resourceMgr.registerResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, this);
_resourceMgr.registerResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, this);
return true;
}
@ -698,4 +703,54 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
return false;
}
@Override
public void processCancelMaintenaceEventAfter(Long hostId) {
updateCapacityForHost(_hostDao.findById(hostId));
}
@Override
public void processCancelMaintenaceEventBefore(Long hostId) {
// TODO Auto-generated method stub
}
@Override
public void processDeletHostEventAfter(HostVO host) {
// TODO Auto-generated method stub
}
@Override
public void processDeleteHostEventBefore(HostVO host) {
// TODO Auto-generated method stub
}
@Override
public void processDiscoverEventAfter(
Map<? extends ServerResource, Map<String, String>> resources) {
// TODO Auto-generated method stub
}
@Override
public void processDiscoverEventBefore(Long dcid, Long podId,
Long clusterId, URI uri, String username, String password,
List<String> hostTags) {
// TODO Auto-generated method stub
}
@Override
public void processPrepareMaintenaceEventAfter(Long hostId) {
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_MEMORY, null, null, null, hostId);
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_CPU, null, null, null, hostId);
}
@Override
public void processPrepareMaintenaceEventBefore(Long hostId) {
// TODO Auto-generated method stub
}
}

View File

@ -131,4 +131,6 @@ public interface ResourceManager extends ResourceService{
String getHostTags(long hostId);
List<PodCluster> listByDataCenter(long dcId);
List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId);
}

View File

@ -1100,7 +1100,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
try {
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_BEFORE, hostId);
if (maintain(hostId)) {
processResourceEvent(ResourceListener.EVENT_CANCEL_MAINTENANCE_AFTER, hostId);
processResourceEvent(ResourceListener.EVENT_PREPARE_MAINTENANCE_AFTER, hostId);
return _hostDao.findById(hostId);
} else {
throw new CloudRuntimeException("Unable to prepare for maintenance host " + hostId);
@ -1926,6 +1926,17 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
return sc.list();
}
@Override
public List<HostVO> listAllNotInMaintenanceHostsInOneZone(Type type, Long dcId) {
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
if (dcId != null){
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
}
sc.addAnd(sc.getEntity().getType(), Op.EQ, type);
sc.addAnd(sc.getEntity().getResourceState(), Op.NIN, ResourceState.Maintenance, ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance, ResourceState.Error);
return sc.list();
}
@Override
public List<HostVO> listAllHostsInOneZoneByType(Type type, long dcId) {
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);