Search in sources :

Example 1 with StorageConflictException

use of com.cloud.exception.StorageConflictException in project cloudstack by apache.

the class CloudStackPrimaryDataStoreLifeCycleImpl method attachZone.

@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
    List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
    s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
    List<HostVO> poolHosts = new ArrayList<HostVO>();
    for (HostVO host : hosts) {
        try {
            storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
            poolHosts.add(host);
        } catch (StorageConflictException se) {
            primaryDataStoreDao.expunge(dataStore.getId());
            throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName());
        } catch (Exception e) {
            s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
        }
    }
    if (poolHosts.isEmpty()) {
        s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
        primaryDataStoreDao.expunge(dataStore.getId());
        throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
    }
    dataStoreHelper.attachZone(dataStore, hypervisorType);
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) StorageConflictException(com.cloud.exception.StorageConflictException) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageConflictException(com.cloud.exception.StorageConflictException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with StorageConflictException

use of com.cloud.exception.StorageConflictException in project cloudstack by apache.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
    StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    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;
    ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        String datastoreName = mspAnswer.getLocalDatastoreName();
        List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and 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) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 3 with StorageConflictException

use of com.cloud.exception.StorageConflictException in project cloudstack by apache.

the class CloudStackPrimaryDataStoreLifeCycleImpl method attachCluster.

@Override
public boolean attachCluster(DataStore store, ClusterScope scope) {
    PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo) store;
    // Check if there is host up in this cluster
    List<HostVO> allHosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, primarystore.getClusterId(), primarystore.getPodId(), primarystore.getDataCenterId());
    if (allHosts.isEmpty()) {
        primaryDataStoreDao.expunge(primarystore.getId());
        throw new CloudRuntimeException("No host up to associate a storage pool with in cluster " + primarystore.getClusterId());
    }
    if (primarystore.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(allHosts, primarystore)) {
        s_logger.warn("Can not create storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
        primaryDataStoreDao.expunge(primarystore.getId());
        return false;
    }
    boolean success = false;
    for (HostVO h : allHosts) {
        success = createStoragePool(h.getId(), primarystore);
        if (success) {
            break;
        }
    }
    s_logger.debug("In createPool Adding the pool to each of the hosts");
    List<HostVO> poolHosts = new ArrayList<HostVO>();
    for (HostVO h : allHosts) {
        try {
            storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId());
            poolHosts.add(h);
        } catch (StorageConflictException se) {
            primaryDataStoreDao.expunge(primarystore.getId());
            throw new CloudRuntimeException("Storage has already been added as local storage");
        } catch (Exception e) {
            s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e);
        }
    }
    if (poolHosts.isEmpty()) {
        s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
        primaryDataStoreDao.expunge(primarystore.getId());
        throw new CloudRuntimeException("Failed to access storage pool");
    }
    dataStoreHelper.attachCluster(store);
    return true;
}
Also used : PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) StorageConflictException(com.cloud.exception.StorageConflictException) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageConflictException(com.cloud.exception.StorageConflictException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

StorageConflictException (com.cloud.exception.StorageConflictException)3 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 HostVO (com.cloud.host.HostVO)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Answer (com.cloud.agent.api.Answer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)1 StoragePool (com.cloud.storage.StoragePool)1 PrimaryDataStoreInfo (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1