Search in sources :

Example 1 with HostScope

use of org.apache.cloudstack.engine.subsystem.api.storage.HostScope in project cloudstack by apache.

the class VolumeApiServiceImpl method needMoveVolume.

private boolean needMoveVolume(VolumeVO existingVolume, VolumeInfo newVolume) {
    if (existingVolume == null || existingVolume.getPoolId() == null || newVolume.getPoolId() == null) {
        return false;
    }
    DataStore storeForExistingVol = dataStoreMgr.getPrimaryDataStore(existingVolume.getPoolId());
    DataStore storeForNewVol = dataStoreMgr.getPrimaryDataStore(newVolume.getPoolId());
    Scope storeForExistingStoreScope = storeForExistingVol.getScope();
    if (storeForExistingStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForExistingVol.getId());
    }
    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) {
                HostScope hs = (HostScope) storeForExistingStoreScope;
                vmClusterId = hs.getClusterId();
            } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) {
                Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
                if (hostId != null) {
                    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)) {
            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(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) HostVO(com.cloud.host.HostVO)

Example 2 with HostScope

use of org.apache.cloudstack.engine.subsystem.api.storage.HostScope in project cloudstack by apache.

the class StorageManagerImpl method createLocalStorage.

@DB
@Override
public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws ConnectionException {
    DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    if (dc == null) {
        return null;
    }
    boolean useLocalStorageForSystemVM = false;
    Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
    if (isLocal != null) {
        useLocalStorageForSystemVM = isLocal.booleanValue();
    }
    if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
        return null;
    }
    DataStore store;
    try {
        String hostAddress = pInfo.getHost();
        if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
            hostAddress = "VMFS datastore: " + pInfo.getHostPath();
        }
        StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid());
        if (pool == null && host.getHypervisorType() == HypervisorType.VMware) {
            // need to perform runtime upgrade here
            if (pInfo.getHostPath().length() > 0) {
                pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, "", 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");
            }
        }
        DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        if (pool == null) {
            Map<String, Object> params = new HashMap<String, Object>();
            String name = createLocalStoragePoolName(host, pInfo);
            params.put("zoneId", host.getDataCenterId());
            params.put("clusterId", host.getClusterId());
            params.put("podId", host.getPodId());
            params.put("hypervisorType", host.getHypervisorType());
            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) {
            HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
            lifeCycle.attachHost(store, scope, pInfo);
        }
    } catch (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(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ConnectionException(com.cloud.exception.ConnectionException) DB(com.cloud.utils.db.DB)

Example 3 with HostScope

use of org.apache.cloudstack.engine.subsystem.api.storage.HostScope in project cloudstack by apache.

the class AncientDataMotionStrategy method getZoneScope.

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

Example 4 with HostScope

use of org.apache.cloudstack.engine.subsystem.api.storage.HostScope in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method getZoneScope.

private Scope getZoneScope(Scope scope) {
    ZoneScope zoneScope;
    if (scope instanceof ClusterScope) {
        ClusterScope clusterScope = (ClusterScope) scope;
        zoneScope = new ZoneScope(clusterScope.getZoneId());
    } else if (scope instanceof HostScope) {
        HostScope hostScope = (HostScope) scope;
        zoneScope = new ZoneScope(hostScope.getZoneId());
    } else {
        zoneScope = (ZoneScope) scope;
    }
    return zoneScope;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope)

Example 5 with HostScope

use of org.apache.cloudstack.engine.subsystem.api.storage.HostScope 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)

Aggregations

HostScope (org.apache.cloudstack.engine.subsystem.api.storage.HostScope)5 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)3 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)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 StorageConflictException (com.cloud.exception.StorageConflictException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 HostVO (com.cloud.host.HostVO)1 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)1