Search in sources :

Example 11 with StoragePoolHostVO

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

the class SolidFireSharedPrimaryDataStoreLifeCycle method deleteDataStore.

// invoked to delete primary storage that is based on the SolidFire plug-in
@Override
public boolean deleteDataStore(DataStore dataStore) {
    List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(dataStore.getId());
    HypervisorType hypervisorType = null;
    if (hostPoolRecords.size() > 0) {
        hypervisorType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    if (!isSupportedHypervisorType(hypervisorType)) {
        throw new CloudRuntimeException(hypervisorType + " is not a supported hypervisor type.");
    }
    StoragePool storagePool = (StoragePool) dataStore;
    StoragePoolVO storagePoolVO = _primaryDataStoreDao.findById(storagePool.getId());
    List<VMTemplateStoragePoolVO> unusedTemplatesInPool = _tmpltMgr.getUnusedTemplatesInPool(storagePoolVO);
    for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) {
        _tmpltMgr.evictTemplateFromStoragePool(templatePoolVO);
    }
    Long clusterId = null;
    for (StoragePoolHostVO host : hostPoolRecords) {
        DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(storagePool);
        if (HypervisorType.VMware.equals(hypervisorType)) {
            deleteCmd.setRemoveDatastore(true);
            Map<String, String> details = new HashMap<String, String>();
            StoragePoolDetailVO storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.DATASTORE_NAME);
            details.put(DeleteStoragePoolCommand.DATASTORE_NAME, storagePoolDetail.getValue());
            storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.IQN);
            details.put(DeleteStoragePoolCommand.IQN, storagePoolDetail.getValue());
            storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.STORAGE_VIP);
            details.put(DeleteStoragePoolCommand.STORAGE_HOST, storagePoolDetail.getValue());
            storagePoolDetail = _storagePoolDetailsDao.findDetail(storagePool.getId(), SolidFireUtil.STORAGE_PORT);
            details.put(DeleteStoragePoolCommand.STORAGE_PORT, storagePoolDetail.getValue());
            deleteCmd.setDetails(details);
        }
        final Answer answer = _agentMgr.easySend(host.getHostId(), deleteCmd);
        if (answer != null && answer.getResult()) {
            s_logger.info("Successfully deleted storage pool using Host ID " + host.getHostId());
            HostVO hostVO = _hostDao.findById(host.getHostId());
            if (hostVO != null) {
                clusterId = hostVO.getClusterId();
            }
            break;
        } else {
            s_logger.error("Failed to delete storage pool using Host ID " + host.getHostId() + ": " + answer.getResult());
        }
    }
    if (clusterId != null) {
        ClusterVO cluster = _clusterDao.findById(clusterId);
        GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
        if (!lock.lock(SolidFireUtil.s_lockTimeInSeconds)) {
            String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid();
            s_logger.debug(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        try {
            removeVolumeFromVag(storagePool.getId(), clusterId);
        } finally {
            lock.unlock();
            lock.releaseRef();
        }
    }
    deleteSolidFireVolume(storagePool.getId());
    return _primaryDataStoreHelper.deletePrimaryDataStore(dataStore);
}
Also used : StoragePool(com.cloud.storage.StoragePool) ClusterVO(com.cloud.dc.ClusterVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HashMap(java.util.HashMap) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) GlobalLock(com.cloud.utils.db.GlobalLock) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 12 with StoragePoolHostVO

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

the class SolidFireHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long storagePoolId) {
    HostVO host = _hostDao.findById(hostId);
    StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId);
    if (storagePoolHost == null) {
        storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, "");
        storagePoolHostDao.persist(storagePoolHost);
    }
    if (host.getHypervisorType().equals(HypervisorType.XenServer)) {
        handleXenServer(host.getClusterId(), host.getId(), storagePoolId);
    } else if (host.getHypervisorType().equals(HypervisorType.KVM)) {
        handleKVM(hostId, storagePoolId);
    }
    return true;
}
Also used : StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 13 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 14 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 15 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)

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