Search in sources :

Example 6 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 7 with StoragePoolHostVO

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

the class StoragePoolHostDaoImpl method deletePrimaryRecordsForHost.

/**
     * This method deletes the primary records from the host
     *
     * @param hostId
     *            -- id of the host
     */
@Override
public void deletePrimaryRecordsForHost(long hostId) {
    SearchCriteria<StoragePoolHostVO> sc = HostSearch.create();
    sc.setParameters("host_id", hostId);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 8 with StoragePoolHostVO

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

the class StoragePoolHostDaoImpl method deleteStoragePoolHostDetails.

@Override
public void deleteStoragePoolHostDetails(long hostId, long poolId) {
    SearchCriteria<StoragePoolHostVO> sc = PoolHostSearch.create();
    sc.setParameters("host_id", hostId);
    sc.setParameters("pool_id", poolId);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 9 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)

Example 10 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());
    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)

Aggregations

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