Search in sources :

Example 6 with DataStoreLifeCycle

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

the class VolumeServiceTest method testCreatePrimaryStorage.

@Test
public void testCreatePrimaryStorage() {
    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
    Map<String, Object> params = new HashMap<String, Object>();
    URI uri = null;
    try {
        uri = new URI(this.getPrimaryStorageUrl());
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    params.put("url", this.getPrimaryStorageUrl());
    params.put("server", uri.getHost());
    params.put("path", uri.getPath());
    params.put("protocol", StoragePoolType.NetworkFilesystem);
    params.put("dcId", dcId.toString());
    params.put("clusterId", clusterId.toString());
    params.put("name", this.primaryName);
    params.put("port", "1");
    params.put("roles", DataStoreRole.Primary.toString());
    params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
    params.put("providerName", String.valueOf(provider.getName()));
    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    this.primaryStore = lifeCycle.initialize(params);
    ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
    lifeCycle.attachCluster(this.primaryStore, scope);
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 7 with DataStoreLifeCycle

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

the class VolumeServiceTest method createImageStore.

private DataStore createImageStore() {
    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample image data store provider");
    Map<String, Object> params = new HashMap<String, Object>();
    String name = UUID.randomUUID().toString();
    params.put("name", name);
    params.put("uuid", name);
    params.put("protocol", "http");
    params.put("scope", ScopeType.GLOBAL.toString());
    params.put("providerName", name);
    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = lifeCycle.initialize(params);
    return store;
}
Also used : DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject)

Example 8 with DataStoreLifeCycle

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

the class StorageManagerImpl method disablePrimaryStoragePool.

@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
private void disablePrimaryStoragePool(StoragePoolVO primaryStorage) {
    if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)) {
        throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. Storage pool state : " + primaryStorage.getStatus().toString());
    }
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).disableStoragePool(store);
}
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) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ActionEvent(com.cloud.event.ActionEvent)

Example 9 with DataStoreLifeCycle

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

Example 10 with DataStoreLifeCycle

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

the class StorageManagerImpl method updateStoragePool.

@Override
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
    // Input validation
    Long id = cmd.getId();
    StoragePoolVO pool = _storagePoolDao.findById(id);
    if (pool == null) {
        throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
    }
    final List<String> storagePoolTags = cmd.getTags();
    if (storagePoolTags != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Updating Storage Pool Tags to :" + storagePoolTags);
        }
        _storagePoolTagsDao.persist(pool.getId(), storagePoolTags);
    }
    Long updatedCapacityBytes = null;
    Long capacityBytes = cmd.getCapacityBytes();
    if (capacityBytes != null) {
        if (capacityBytes != pool.getCapacityBytes()) {
            updatedCapacityBytes = capacityBytes;
        }
    }
    Long updatedCapacityIops = null;
    Long capacityIops = cmd.getCapacityIops();
    if (capacityIops != null) {
        if (!capacityIops.equals(pool.getCapacityIops())) {
            updatedCapacityIops = capacityIops;
        }
    }
    if (updatedCapacityBytes != null || updatedCapacityIops != null) {
        StoragePoolVO storagePool = _storagePoolDao.findById(id);
        DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
        DataStoreLifeCycle dataStoreLifeCycle = dataStoreProvider.getDataStoreLifeCycle();
        if (dataStoreLifeCycle instanceof PrimaryDataStoreLifeCycle) {
            Map<String, String> details = new HashMap<String, String>();
            details.put(PrimaryDataStoreLifeCycle.CAPACITY_BYTES, updatedCapacityBytes != null ? String.valueOf(updatedCapacityBytes) : null);
            details.put(PrimaryDataStoreLifeCycle.CAPACITY_IOPS, updatedCapacityIops != null ? String.valueOf(updatedCapacityIops) : null);
            ((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).updateStoragePool(storagePool, details);
        }
    }
    Boolean enabled = cmd.getEnabled();
    if (enabled != null) {
        if (enabled) {
            enablePrimaryStoragePool(pool);
        } else {
            disablePrimaryStoragePool(pool);
        }
    }
    if (updatedCapacityBytes != null) {
        _storagePoolDao.updateCapacityBytes(id, capacityBytes);
    }
    if (updatedCapacityIops != null) {
        _storagePoolDao.updateCapacityIops(id, capacityIops);
    }
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) HashMap(java.util.HashMap) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Aggregations

DataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle)14 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)14 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 PrimaryDataStoreLifeCycle (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 HashMap (java.util.HashMap)8 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 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 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 ResourceInUseException (com.cloud.exception.ResourceInUseException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4