Search in sources :

Example 21 with StoragePoolHostVO

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

the class CloudStackPrimaryDataStoreLifeCycleImpl method deleteDataStore.

@DB
@Override
public boolean deleteDataStore(DataStore store) {
    List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    StoragePool pool = (StoragePool) store;
    boolean deleteFlag = false;
    // find the hypervisor where the storage is attached to.
    HypervisorType hType = null;
    if (hostPoolRecords.size() > 0) {
        hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    // Remove the SR associated with the Xenserver
    for (StoragePoolHostVO host : hostPoolRecords) {
        DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(pool);
        final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd);
        if (answer != null && answer.getResult()) {
            deleteFlag = true;
            // if host is KVM hypervisor then send deleteStoragepoolcmd to all the kvm hosts.
            if (HypervisorType.KVM != hType) {
                break;
            }
        } else {
            if (answer != null) {
                s_logger.debug("Failed to delete storage pool: " + answer.getResult());
            }
        }
    }
    if (!hostPoolRecords.isEmpty() && !deleteFlag) {
        throw new CloudRuntimeException("Failed to delete storage pool on host");
    }
    return dataStoreHelper.deletePrimaryDataStore(store);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) DB(com.cloud.utils.db.DB)

Example 22 with StoragePoolHostVO

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

the class ScaleIOPrimaryDataStoreLifeCycle method deleteDataStore.

@Override
public boolean deleteDataStore(DataStore dataStore) {
    StoragePool storagePool = (StoragePool) dataStore;
    StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(storagePool.getId());
    if (storagePoolVO == null) {
        return false;
    }
    List<VMTemplateStoragePoolVO> unusedTemplatesInPool = templateMgr.getUnusedTemplatesInPool(storagePoolVO);
    for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) {
        if (templatePoolVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            templateMgr.evictTemplateFromStoragePool(templatePoolVO);
        }
    }
    List<StoragePoolHostVO> poolHostVOs = storagePoolHostDao.listByPoolId(dataStore.getId());
    for (StoragePoolHostVO poolHostVO : poolHostVOs) {
        DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand(storagePool);
        final Answer answer = agentMgr.easySend(poolHostVO.getHostId(), deleteStoragePoolCommand);
        if (answer != null && answer.getResult()) {
            LOGGER.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId());
        } else {
            if (answer != null) {
                LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult());
            } else {
                LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId());
            }
        }
    }
    ScaleIOGatewayClientConnectionPool.getInstance().removeClient(dataStore.getId());
    return dataStoreHelper.deletePrimaryDataStore(dataStore);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand)

Example 23 with StoragePoolHostVO

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

the class DeploymentPlanningManagerImpl method hostCanAccessSPool.

protected boolean hostCanAccessSPool(Host host, StoragePool pool) {
    boolean hostCanAccessSPool = false;
    StoragePoolHostVO hostPoolLinkage = _poolHostDao.findByPoolHost(pool.getId(), host.getId());
    if (hostPoolLinkage != null && _storageMgr.canHostAccessStoragePool(host, pool)) {
        hostCanAccessSPool = true;
    }
    s_logger.debug("Host: " + host.getId() + (hostCanAccessSPool ? " can" : " cannot") + " access pool: " + pool.getId());
    return hostCanAccessSPool;
}
Also used : StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 24 with StoragePoolHostVO

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

the class ElastistorPrimaryDataStoreLifeCycle method deleteDataStore.

@SuppressWarnings("finally")
@Override
public boolean deleteDataStore(DataStore store) {
    List<StoragePoolHostVO> hostPoolRecords = _storagePoolHostDao.listByPoolId(store.getId());
    StoragePool pool = (StoragePool) store;
    // find the hypervisor where the storage is attached to.
    HypervisorType hType = null;
    if (hostPoolRecords.size() > 0) {
        hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
    }
    StoragePoolVO storagePoolVO = _storagePoolDao.findById(store.getId());
    if (!(storagePoolVO.isManaged())) {
        // Remove the SR associated with the Xenserver
        for (StoragePoolHostVO host : hostPoolRecords) {
            DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(pool);
            final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd);
            if (answer != null && answer.getResult()) {
                // to all the kvm hosts.
                if (HypervisorType.KVM != hType) {
                    break;
                }
            } else {
                if (answer != null) {
                    s_logger.error("Failed to delete storage pool: " + answer.getResult());
                }
            }
        }
    }
    // delete the Elastistor volume at backend
    deleteElastistorVolume(pool, storagePoolVO.isManaged());
    return _dataStoreHelper.deletePrimaryDataStore(store);
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand)

Example 25 with StoragePoolHostVO

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

the class ElastistorHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long poolId) {
    StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
    HostVO host = _hostDao.findById(hostId);
    if (storagePoolHost == null) {
        storagePoolHost = new StoragePoolHostVO(poolId, hostId, "");
        storagePoolHostDao.persist(storagePoolHost);
    }
    StoragePoolVO poolVO = storagePoolDao.findById(pool.getId());
    if (poolVO.isManaged() && (host.getHypervisorType() != HypervisorType.KVM)) {
        return true;
    }
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    s_logger.info("Connection established between " + pool + " host + " + hostId);
    return true;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

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