bug 7525: Cleaning up primary storage stats from op_host_Capacity(reflected on dashboard) when primary storage is deleted.

status 7525 : resolved fixed
This commit is contained in:
nit 2011-01-20 20:38:43 +05:30
parent 75fa849324
commit d1aa043aba
3 changed files with 32 additions and 4 deletions

4
server/src/com/cloud/capacity/dao/CapacityDao.java Normal file → Executable file
View File

@ -18,14 +18,16 @@
package com.cloud.capacity.dao;
import java.util.List;
import com.cloud.capacity.CapacityVO;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VMInstanceVO;
public interface CapacityDao extends GenericDao<CapacityVO, Long> {
void clearNonStorageCapacities();
void clearStorageCapacities();
CapacityVO findByHostIdType(Long hostId, short capacityType);
void clearNonStorageCapacities2();
List<CapacityVO> findByHostorPoolId(Long hostorPoolId);
}

15
server/src/com/cloud/capacity/dao/CapacityDaoImpl.java Normal file → Executable file
View File

@ -25,13 +25,10 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.capacity.CapacityVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.vm.VMInstanceVO;
@Local(value = { CapacityDao.class })
public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements CapacityDao {
@ -43,12 +40,17 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
private static final String CLEAR_NON_STORAGE_CAPACITIES = "DELETE FROM `cloud`.`op_host_capacity` WHERE capacity_type<>2 AND capacity_type<>3 AND capacity_type<>6"; //clear non-storage and non-secondary_storage capacities
private static final String CLEAR_NON_STORAGE_CAPACITIES2 = "DELETE FROM `cloud`.`op_host_capacity` WHERE capacity_type<>2 AND capacity_type<>3 AND capacity_type<>6 AND capacity_type<>0 AND capacity_type<>1"; //clear non-storage and non-secondary_storage capacities
private SearchBuilder<CapacityVO> _hostIdTypeSearch;
private SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
public CapacityDaoImpl() {
_hostIdTypeSearch = createSearchBuilder();
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.done();
_hostOrPoolIdSearch = createSearchBuilder();
_hostOrPoolIdSearch.and("hostId", _hostOrPoolIdSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostOrPoolIdSearch.done();
}
public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) {
@ -130,4 +132,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
sc.setParameters("type", capacityType);
return findOneBy(sc);
}
@Override
public java.util.List<CapacityVO> findByHostorPoolId(Long hostorPoolId){
SearchCriteria<CapacityVO> sc = _hostOrPoolIdSearch.create();
sc.setParameters("hostId", hostorPoolId);
return listBy(sc);
}
}

View File

@ -73,6 +73,7 @@ import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
import com.cloud.api.commands.UpdateStoragePoolCmd;
import com.cloud.async.AsyncInstanceCreateStatus;
import com.cloud.async.AsyncJobManager;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
@ -1413,6 +1414,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
sPool.setUuid(null);
_storagePoolDao.update(id, sPool);
_storagePoolDao.remove(id);
deleteHostorPoolStats(id);
return true;
} else {
// 1. Check if the pool has associated volumes in the volumes table
@ -1462,6 +1464,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
sPool.setStatus(Status.Removed);
_storagePoolDao.update(id, sPool);
_storagePoolDao.remove(id);
deleteHostorPoolStats(id);
return true;
}
}
@ -1470,6 +1473,20 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
@DB
private boolean deleteHostorPoolStats(Long hostorPoolId){
List<CapacityVO> capacities = _capacityDao.findByHostorPoolId(hostorPoolId);
Transaction txn = Transaction.currentTxn();
txn.start();
for (CapacityVO capacity : capacities){
_capacityDao.remove(capacity.getId());
}
txn.commit();
return true;
}
@Override
public boolean addPoolToHost(long hostId, StoragePoolVO pool) {
s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId);