Search in sources :

Example 1 with HostScope

use of com.cloud.engine.subsystem.api.storage.HostScope in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreImpl method getScope.

@Override
public Scope getScope() {
    final 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) {
        final 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(com.cloud.engine.subsystem.api.storage.ZoneScope) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) HostScope(com.cloud.engine.subsystem.api.storage.HostScope)

Example 2 with HostScope

use of com.cloud.engine.subsystem.api.storage.HostScope in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method getZoneScope.

private Scope getZoneScope(final Scope destScope) {
    ZoneScope zoneScope = null;
    if (destScope instanceof ClusterScope) {
        final ClusterScope clusterScope = (ClusterScope) destScope;
        zoneScope = new ZoneScope(clusterScope.getZoneId());
    } else if (destScope instanceof HostScope) {
        final HostScope hostScope = (HostScope) destScope;
        zoneScope = new ZoneScope(hostScope.getZoneId());
    } else {
        zoneScope = (ZoneScope) destScope;
    }
    return zoneScope;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope)

Example 3 with HostScope

use of com.cloud.engine.subsystem.api.storage.HostScope in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method needMoveVolume.

private boolean needMoveVolume(final VolumeVO existingVolume, final VolumeInfo newVolume) {
    if (existingVolume == null || existingVolume.getPoolId() == null || newVolume.getPoolId() == null) {
        return false;
    }
    final DataStore storeForExistingVol = dataStoreMgr.getPrimaryDataStore(existingVolume.getPoolId());
    final DataStore storeForNewVol = dataStoreMgr.getPrimaryDataStore(newVolume.getPoolId());
    final Scope storeForExistingStoreScope = storeForExistingVol.getScope();
    if (storeForExistingStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForExistingVol.getId());
    }
    final Scope storeForNewStoreScope = storeForNewVol.getScope();
    if (storeForNewStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForNewVol.getId());
    }
    if (storeForNewStoreScope.getScopeType() == ScopeType.ZONE) {
        return false;
    }
    if (storeForExistingStoreScope.getScopeType() != storeForNewStoreScope.getScopeType()) {
        if (storeForNewStoreScope.getScopeType() == ScopeType.CLUSTER) {
            Long vmClusterId = null;
            if (storeForExistingStoreScope.getScopeType() == ScopeType.HOST) {
                final HostScope hs = (HostScope) storeForExistingStoreScope;
                vmClusterId = hs.getClusterId();
            } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) {
                final Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
                if (hostId != null) {
                    final HostVO host = _hostDao.findById(hostId);
                    vmClusterId = host.getClusterId();
                }
            }
            if (storeForNewStoreScope.getScopeId().equals(vmClusterId)) {
                return false;
            } else {
                return true;
            }
        } else if (storeForNewStoreScope.getScopeType() == ScopeType.HOST && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) {
            final Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
            if (storeForNewStoreScope.getScopeId().equals(hostId)) {
                return false;
            }
        }
        throw new InvalidParameterValueException("Can't move volume between scope: " + storeForNewStoreScope.getScopeType() + " and " + storeForExistingStoreScope.getScopeType());
    }
    return !storeForExistingStoreScope.isSameScope(storeForNewStoreScope);
}
Also used : Scope(com.cloud.engine.subsystem.api.storage.Scope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) HostVO(com.cloud.host.HostVO)

Example 4 with HostScope

use of com.cloud.engine.subsystem.api.storage.HostScope in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method createLocalStorage.

@DB
@Override
public DataStore createLocalStorage(final Host host, final StoragePoolInfo pInfo) throws ConnectionException {
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    if (dc == null) {
        return null;
    }
    boolean useLocalStorageForSystemVM = false;
    final Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
    if (isLocal != null) {
        useLocalStorageForSystemVM = isLocal.booleanValue();
    }
    if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
        return null;
    }
    final DataStore store;
    try {
        final String hostAddress = pInfo.getHost();
        StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid());
        if (pool == null) {
            // the path can be different, but if they have the same uuid, assume they are the same storage
            pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid());
            if (pool != null) {
                s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool");
            }
        }
        final DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        if (pool == null) {
            final Map<String, Object> params = new HashMap<>();
            final String name = host.getName() + " Local Storage";
            params.put("zoneId", host.getDataCenterId());
            params.put("clusterId", host.getClusterId());
            params.put("podId", host.getPodId());
            params.put("url", pInfo.getPoolType().toString() + "://" + pInfo.getHost() + "/" + pInfo.getHostPath());
            params.put("name", name);
            params.put("localStorage", true);
            params.put("details", pInfo.getDetails());
            params.put("uuid", pInfo.getUuid());
            params.put("providerName", provider.getName());
            store = lifeCycle.initialize(params);
        } else {
            store = _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        }
        pool = _storagePoolDao.findById(store.getId());
        if (pool.getStatus() != StoragePoolStatus.Maintenance && pool.getStatus() != StoragePoolStatus.Removed) {
            final HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
            lifeCycle.attachHost(store, scope, pInfo);
        }
    } catch (final Exception e) {
        s_logger.warn("Unable to setup the local storage pool for " + host, e);
        throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
    }
    return _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConnectionException(com.cloud.exception.ConnectionException) DB(com.cloud.utils.db.DB)

Aggregations

HostScope (com.cloud.engine.subsystem.api.storage.HostScope)4 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)2 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)1 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)1 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)1 Scope (com.cloud.engine.subsystem.api.storage.Scope)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConnectionException (com.cloud.exception.ConnectionException)1 DiscoveryException (com.cloud.exception.DiscoveryException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceInUseException (com.cloud.exception.ResourceInUseException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1