Search in sources :

Example 31 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.

the class StoragePoolHostDaoImpl method listByHostStatus.

@Override
public List<StoragePoolHostVO> listByHostStatus(long poolId, Status hostStatus) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    String sql = HOST_FOR_POOL_SEARCH;
    List<StoragePoolHostVO> result = new ArrayList<StoragePoolHostVO>();
    try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
        pstmt.setLong(1, poolId);
        pstmt.setString(2, hostStatus.toString());
        try (ResultSet rs = pstmt.executeQuery()) {
            while (rs.next()) {
                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
                // GenericDaoBase for hand constructed queries
                // ID column
                long id = rs.getLong(1);
                result.add(findById(id));
            }
        } catch (SQLException e) {
            s_logger.warn("listByHostStatus:Exception: ", e);
        }
    } catch (Exception e) {
        s_logger.warn("listByHostStatus:Exception: ", e);
    }
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 32 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.

the class PrimaryDataStoreHelper method deletePrimaryDataStore.

public boolean deletePrimaryDataStore(DataStore store) {
    List<StoragePoolHostVO> hostPoolRecords = this.storagePoolHostDao.listByPoolId(store.getId());
    StoragePoolVO poolVO = this.dataStoreDao.findById(store.getId());
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    for (StoragePoolHostVO host : hostPoolRecords) {
        storagePoolHostDao.deleteStoragePoolHostDetails(host.getHostId(), host.getPoolId());
    }
    poolVO.setUuid(null);
    this.dataStoreDao.update(poolVO.getId(), poolVO);
    dataStoreDao.remove(poolVO.getId());
    dataStoreDao.deletePoolTags(poolVO.getId());
    annotationDao.removeByEntityType(AnnotationService.EntityType.PRIMARY_STORAGE.name(), poolVO.getUuid());
    deletePoolStats(poolVO.getId());
    // Delete op_host_capacity entries
    this._capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, null, null, null, poolVO.getId());
    txn.commit();
    s_logger.debug("Storage pool id=" + poolVO.getId() + " is removed successfully");
    return true;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 33 with StoragePoolHostVO

use of com.cloud.storage.StoragePoolHostVO in project cloudstack by apache.

the class PrimaryDataStoreImpl method getScope.

@Override
public Scope getScope() {
    StoragePoolVO vo = dataStoreDao.findById(pdsv.getId());
    if (vo.getScope() == ScopeType.CLUSTER) {
        return new ClusterScope(vo.getClusterId(), vo.getPodId(), vo.getDataCenterId());
    } else if (vo.getScope() == ScopeType.ZONE) {
        return new ZoneScope(vo.getDataCenterId());
    } else if (vo.getScope() == ScopeType.HOST) {
        List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId());
        if (poolHosts.size() > 0) {
            return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId());
        }
        s_logger.debug("can't find a local storage in pool host table: " + vo.getId());
    }
    return null;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope)

Aggregations

StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)33 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 StoragePool (com.cloud.storage.StoragePool)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)8 Answer (com.cloud.agent.api.Answer)7 HostVO (com.cloud.host.HostVO)7 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)7 DB (com.cloud.utils.db.DB)6 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)5 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)5 ArrayList (java.util.ArrayList)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)4 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 ClusterVO (com.cloud.dc.ClusterVO)3 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2