mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
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:
parent
75fa849324
commit
d1aa043aba
4
server/src/com/cloud/capacity/dao/CapacityDao.java
Normal file → Executable file
4
server/src/com/cloud/capacity/dao/CapacityDao.java
Normal file → Executable file
@ -18,14 +18,16 @@
|
|||||||
|
|
||||||
package com.cloud.capacity.dao;
|
package com.cloud.capacity.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.capacity.CapacityVO;
|
import com.cloud.capacity.CapacityVO;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
import com.cloud.vm.VMInstanceVO;
|
|
||||||
|
|
||||||
public interface CapacityDao extends GenericDao<CapacityVO, Long> {
|
public interface CapacityDao extends GenericDao<CapacityVO, Long> {
|
||||||
void clearNonStorageCapacities();
|
void clearNonStorageCapacities();
|
||||||
void clearStorageCapacities();
|
void clearStorageCapacities();
|
||||||
CapacityVO findByHostIdType(Long hostId, short capacityType);
|
CapacityVO findByHostIdType(Long hostId, short capacityType);
|
||||||
void clearNonStorageCapacities2();
|
void clearNonStorageCapacities2();
|
||||||
|
List<CapacityVO> findByHostorPoolId(Long hostorPoolId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
Normal file → Executable file
15
server/src/com/cloud/capacity/dao/CapacityDaoImpl.java
Normal file → Executable file
@ -25,13 +25,10 @@ import javax.ejb.Local;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.capacity.CapacityVO;
|
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.GenericDaoBase;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.vm.VMInstanceVO;
|
|
||||||
|
|
||||||
@Local(value = { CapacityDao.class })
|
@Local(value = { CapacityDao.class })
|
||||||
public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements CapacityDao {
|
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_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 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> _hostIdTypeSearch;
|
||||||
|
private SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
|
||||||
|
|
||||||
public CapacityDaoImpl() {
|
public CapacityDaoImpl() {
|
||||||
_hostIdTypeSearch = createSearchBuilder();
|
_hostIdTypeSearch = createSearchBuilder();
|
||||||
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
|
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
|
||||||
_hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
|
_hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
|
||||||
_hostIdTypeSearch.done();
|
_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) {
|
public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) {
|
||||||
@ -129,5 +131,12 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
|||||||
sc.setParameters("hostId", hostId);
|
sc.setParameters("hostId", hostId);
|
||||||
sc.setParameters("type", capacityType);
|
sc.setParameters("type", capacityType);
|
||||||
return findOneBy(sc);
|
return findOneBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public java.util.List<CapacityVO> findByHostorPoolId(Long hostorPoolId){
|
||||||
|
SearchCriteria<CapacityVO> sc = _hostOrPoolIdSearch.create();
|
||||||
|
sc.setParameters("hostId", hostorPoolId);
|
||||||
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,6 +73,7 @@ import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
|
|||||||
import com.cloud.api.commands.UpdateStoragePoolCmd;
|
import com.cloud.api.commands.UpdateStoragePoolCmd;
|
||||||
import com.cloud.async.AsyncInstanceCreateStatus;
|
import com.cloud.async.AsyncInstanceCreateStatus;
|
||||||
import com.cloud.async.AsyncJobManager;
|
import com.cloud.async.AsyncJobManager;
|
||||||
|
import com.cloud.capacity.Capacity;
|
||||||
import com.cloud.capacity.CapacityVO;
|
import com.cloud.capacity.CapacityVO;
|
||||||
import com.cloud.capacity.dao.CapacityDao;
|
import com.cloud.capacity.dao.CapacityDao;
|
||||||
import com.cloud.configuration.Config;
|
import com.cloud.configuration.Config;
|
||||||
@ -1413,6 +1414,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
|||||||
sPool.setUuid(null);
|
sPool.setUuid(null);
|
||||||
_storagePoolDao.update(id, sPool);
|
_storagePoolDao.update(id, sPool);
|
||||||
_storagePoolDao.remove(id);
|
_storagePoolDao.remove(id);
|
||||||
|
deleteHostorPoolStats(id);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// 1. Check if the pool has associated volumes in the volumes table
|
// 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);
|
sPool.setStatus(Status.Removed);
|
||||||
_storagePoolDao.update(id, sPool);
|
_storagePoolDao.update(id, sPool);
|
||||||
_storagePoolDao.remove(id);
|
_storagePoolDao.remove(id);
|
||||||
|
deleteHostorPoolStats(id);
|
||||||
return true;
|
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
|
@Override
|
||||||
public boolean addPoolToHost(long hostId, StoragePoolVO pool) {
|
public boolean addPoolToHost(long hostId, StoragePoolVO pool) {
|
||||||
s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId);
|
s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user