bug 10774: On removing storage, local storage, cluster handle deletion of corresponding op_host_capacity rows.

This commit is contained in:
Nitin 2011-10-22 13:47:15 +05:30
parent 9ba4b7073e
commit 70aae9666b
6 changed files with 22 additions and 13 deletions

View File

@ -755,16 +755,14 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
storagePool.setClusterId(null);
_storagePoolDao.update(poolId, storagePool);
_storagePoolDao.remove(poolId);
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_LOCAL_STORAGE, null, null, null, poolId);
s_logger.debug("Local storage id=" + poolId + " is removed as a part of host removal id=" + hostId);
}
}
// delete the op_host_capacity entry
Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY };
SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
_capacityDao.remove(hostCapacitySC);
//Delete op_host_capacity entries
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_MEMORY, null, null, null, hostId);
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_CPU, null, null, null, hostId);
txn.commit();
return true;
} catch (Throwable t) {

View File

@ -28,7 +28,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
CapacityVO findByHostIdType(Long hostId, short capacityType);
List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor);
List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor);
boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId);
boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId);
List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId);
List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId,Long podId, Long clusterId);
List<Long> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor);

View File

@ -339,7 +339,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
@Override
public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId) {
public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId) {
SearchCriteria<CapacityVO> sc = _allFieldsSearch.create();
if (capacityType != null) {
@ -358,6 +358,10 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
sc.setParameters("clusterId", clusterId);
}
if (hostId != null) {
sc.setParameters("hostId", hostId);
}
return remove(sc) > 0;
}

View File

@ -692,7 +692,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
// Delete corresponding capacity record
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_PRIVATE_IP, null, podId, null);
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_PRIVATE_IP, null, podId, null, null);
}
// Delete link local ip addresses for the pod
@ -1161,7 +1161,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (success) {
//delete all capacity records for the zone
_capacityDao.removeBy(null, zoneId, null, null);
_capacityDao.removeBy(null, zoneId, null, null, null);
}
txn.commit();

View File

@ -43,6 +43,7 @@ import com.cloud.api.commands.PrepareForMaintenanceCmd;
import com.cloud.api.commands.ReconnectHostCmd;
import com.cloud.api.commands.UpdateHostCmd;
import com.cloud.api.commands.UpdateHostPasswordCmd;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ManagementServerNode;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterVO;
@ -110,6 +111,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
@Inject
protected ClusterDao _clusterDao;
@Inject
protected CapacityDao _capacityDao;
@Inject
protected HostDao _hostDao;
@Inject
protected HostDetailsDao _hostDetailsDao;
@ -667,7 +670,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
return false;
}
_clusterDao.remove(cmd.getId());
if (_clusterDao.remove(cmd.getId())){
_capacityDao.removeBy(null, null, null, cluster.getId(), null);
}
txn.commit();
return true;

View File

@ -1430,8 +1430,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
_storagePoolDao.update(id, sPool);
_storagePoolDao.remove(id);
deletePoolStats(id);
//Delete op_host_capacity entries
_capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, null, null, null, id);
txn.commit();
s_logger.debug("Storage pool id=" + id + " is removed successfully");
return true;
} else {