Search in sources :

Example 11 with DataStoreProvider

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

the class StorageManagerImpl method connectHostToSharedPool.

@Override
public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException {
    StoragePool pool = (StoragePool) _dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    assert (pool.isShared()) : "Now, did you actually read the name of this method?";
    s_logger.debug("Adding pool " + pool.getName() + " to  host " + hostId);
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    HypervisorHostListener listener = hostListeners.get(provider.getName());
    listener.hostConnect(hostId, pool.getId());
}
Also used : HypervisorHostListener(org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)

Example 12 with DataStoreProvider

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

the class StorageManagerImpl method canHostAccessStoragePool.

@Override
public boolean canHostAccessStoragePool(Host host, StoragePool pool) {
    if (host == null || pool == null) {
        return false;
    }
    if (!pool.isManaged()) {
        return true;
    }
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
    if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver) storeDriver).canHostAccessStoragePool(host, pool)) {
        return true;
    }
    return false;
}
Also used : PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)

Example 13 with DataStoreProvider

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

the class StorageManagerImpl method disconnectHostFromSharedPool.

@Override
public void disconnectHostFromSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException {
    StoragePool pool = (StoragePool) _dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    assert (pool.isShared()) : "Now, did you actually read the name of this method?";
    s_logger.debug("Removing pool " + pool.getName() + " from  host " + hostId);
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
    HypervisorHostListener listener = hostListeners.get(provider.getName());
    listener.hostDisconnected(hostId, pool.getId());
}
Also used : HypervisorHostListener(org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)

Example 14 with DataStoreProvider

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

the class StorageManagerImpl method createPool.

@Override
public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
    String providerName = cmd.getStorageProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find storage provider: " + providerName);
        }
    }
    Long clusterId = cmd.getClusterId();
    Long podId = cmd.getPodId();
    Long zoneId = cmd.getZoneId();
    ScopeType scopeType = ScopeType.CLUSTER;
    String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
        } catch (Exception e) {
            throw new InvalidParameterValueException("invalid scope for pool " + scope);
        }
    }
    if (scopeType == ScopeType.CLUSTER && clusterId == null) {
        throw new InvalidParameterValueException("cluster id can't be null, if scope is cluster");
    } else if (scopeType == ScopeType.ZONE && zoneId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }
    HypervisorType hypervisorType = HypervisorType.KVM;
    if (scopeType == ScopeType.ZONE) {
        // ignore passed clusterId and podId
        clusterId = null;
        podId = null;
        String hypervisor = cmd.getHypervisor();
        if (hypervisor != null) {
            try {
                hypervisorType = HypervisorType.getType(hypervisor);
            } catch (Exception e) {
                throw new InvalidParameterValueException("invalid hypervisor type " + hypervisor);
            }
        } else {
            throw new InvalidParameterValueException("Missing parameter hypervisor. Hypervisor type is required to create zone wide primary storage.");
        }
        Set<HypervisorType> supportedHypervisorTypes = Sets.newHashSet(HypervisorType.KVM, HypervisorType.VMware, HypervisorType.Hyperv, HypervisorType.LXC, HypervisorType.Any, HypervisorType.Simulator);
        if (!supportedHypervisorTypes.contains(hypervisorType)) {
            throw new InvalidParameterValueException("Zone wide storage pool is not supported for hypervisor type " + hypervisor);
        }
    } else {
        ClusterVO clusterVO = _clusterDao.findById(clusterId);
        hypervisorType = clusterVO.getHypervisorType();
    }
    Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
    DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
    if (zone == null) {
        throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
    }
    // Check if zone is disabled
    Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("zoneId", zone.getId());
    params.put("clusterId", clusterId);
    params.put("podId", podId);
    params.put("hypervisorType", hypervisorType);
    params.put("url", cmd.getUrl());
    params.put("tags", cmd.getTags());
    params.put("name", cmd.getStoragePoolName());
    params.put("details", details);
    params.put("providerName", storeProvider.getName());
    params.put("managed", cmd.isManaged());
    params.put("capacityBytes", cmd.getCapacityBytes());
    params.put("capacityIops", cmd.getCapacityIops());
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = null;
    try {
        store = lifeCycle.initialize(params);
        if (scopeType == ScopeType.CLUSTER) {
            ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
            lifeCycle.attachCluster(store, clusterScope);
        } else if (scopeType == ScopeType.ZONE) {
            ZoneScope zoneScope = new ZoneScope(zoneId);
            lifeCycle.attachZone(store, zoneScope, hypervisorType);
        }
    } catch (Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        try {
            // not deleting data store.
            if (store != null) {
                lifeCycle.deleteDataStore(store);
            }
        } catch (Exception ex) {
            s_logger.debug("Failed to clean up storage pool: " + ex.getMessage());
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) 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) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 15 with DataStoreProvider

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

the class StorageManagerImpl method migrateToObjectStore.

@Override
public ImageStore migrateToObjectStore(String name, String url, String providerName, Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    // check if current cloud is ready to migrate, we only support cloud with only NFS secondary storages
    List<ImageStoreVO> imgStores = _imageStoreDao.listImageStores();
    List<ImageStoreVO> nfsStores = new ArrayList<ImageStoreVO>();
    if (imgStores != null && imgStores.size() > 0) {
        for (ImageStoreVO store : imgStores) {
            if (!store.getProviderName().equals(DataStoreProvider.NFS_IMAGE)) {
                throw new InvalidParameterValueException("We only support migrate NFS secondary storage to use object store!");
            } else {
                nfsStores.add(store);
            }
        }
    }
    // convert all NFS secondary storage to staging store
    if (nfsStores != null && nfsStores.size() > 0) {
        for (ImageStoreVO store : nfsStores) {
            long storeId = store.getId();
            _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
            DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(store.getProviderName());
            DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
            DataStore secStore = _dataStoreMgr.getDataStore(storeId, DataStoreRole.Image);
            lifeCycle.migrateToObjectStore(secStore);
            // update store_role in template_store_ref and snapshot_store_ref to ImageCache
            _templateStoreDao.updateStoreRoleToCachce(storeId);
            _snapshotStoreDao.updateStoreRoleToCache(storeId);
        }
    }
    // add object store
    return discoverImageStore(name, url, providerName, null, details);
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)33 DataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)13 PrimaryDataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 HashMap (java.util.HashMap)10 DataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver)10 PrimaryDataStoreDriver (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ArrayList (java.util.ArrayList)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 ConnectionException (com.cloud.exception.ConnectionException)4 DiscoveryException (com.cloud.exception.DiscoveryException)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4