Search in sources :

Example 6 with DataStoreLifeCycle

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

the class StorageManagerImpl method updateStoragePool.

@Override
public PrimaryDataStoreInfo updateStoragePool(final UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
    // Input validation
    final Long id = cmd.getId();
    final List<String> tags = cmd.getTags();
    final StoragePoolVO pool = _storagePoolDao.findById(id);
    if (pool == null) {
        throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
    }
    final Map<String, String> updatedDetails = new HashMap<>();
    if (tags != null) {
        final Map<String, String> existingDetails = _storagePoolDetailsDao.listDetailsKeyPairs(id);
        final Set<String> existingKeys = existingDetails.keySet();
        final Map<String, String> existingDetailsToKeep = new HashMap<>();
        for (final String existingKey : existingKeys) {
            final String existingValue = existingDetails.get(existingKey);
            if (!Boolean.TRUE.toString().equalsIgnoreCase(existingValue)) {
                existingDetailsToKeep.put(existingKey, existingValue);
            }
        }
        final Map<String, String> details = new HashMap<>();
        for (String tag : tags) {
            tag = tag.trim();
            if (tag.length() > 0 && !details.containsKey(tag)) {
                details.put(tag, "true");
            }
        }
        final Set<String> existingKeysToKeep = existingDetailsToKeep.keySet();
        for (final String existingKeyToKeep : existingKeysToKeep) {
            final String existingValueToKeep = existingDetailsToKeep.get(existingKeyToKeep);
            if (details.containsKey(existingKeyToKeep)) {
                throw new CloudRuntimeException("Storage tag '" + existingKeyToKeep + "' conflicts with a stored property of this primary storage. No changes were made.");
            }
            details.put(existingKeyToKeep, existingValueToKeep);
        }
        updatedDetails.putAll(details);
    }
    Long updatedCapacityBytes = null;
    final Long capacityBytes = cmd.getCapacityBytes();
    if (capacityBytes != null) {
        if (capacityBytes != pool.getCapacityBytes()) {
            updatedCapacityBytes = capacityBytes;
        }
    }
    Long updatedCapacityIops = null;
    final Long capacityIops = cmd.getCapacityIops();
    if (capacityIops != null) {
        if (!capacityIops.equals(pool.getCapacityIops())) {
            updatedCapacityIops = capacityIops;
        }
    }
    if (updatedCapacityBytes != null || updatedCapacityIops != null) {
        final StoragePoolVO storagePool = _storagePoolDao.findById(id);
        final DataStoreProvider dataStoreProvider = _dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
        final DataStoreLifeCycle dataStoreLifeCycle = dataStoreProvider.getDataStoreLifeCycle();
        if (dataStoreLifeCycle instanceof PrimaryDataStoreLifeCycle) {
            final Map<String, String> details = new HashMap<>();
            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);
        }
    }
    final Boolean enabled = cmd.getEnabled();
    if (enabled != null) {
        if (enabled) {
            enablePrimaryStoragePool(pool);
        } else {
            disablePrimaryStoragePool(pool);
        }
    } else if (updatedDetails.size() >= 0) {
        _storagePoolDao.updateDetails(id, updatedDetails);
    }
    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(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 7 with DataStoreLifeCycle

use of com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle 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)

Example 8 with DataStoreLifeCycle

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

the class StorageManagerImpl method discoverImageStore.

@Override
public ImageStore discoverImageStore(String name, final String url, String providerName, final Long zoneId, final Map details) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultImageDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find image store provider: " + providerName);
        }
        // ignored passed provider name and use default image store provider name
        providerName = storeProvider.getName();
    }
    ScopeType scopeType = ScopeType.ZONE;
    if (zoneId == null) {
        scopeType = ScopeType.REGION;
    }
    if (name == null) {
        name = url;
    }
    final ImageStoreVO imageStore = _imageStoreDao.findByName(name);
    if (imageStore != null) {
        throw new InvalidParameterValueException("The image store with name " + name + " already exists, try creating with another name");
    }
    // check if scope is supported by store provider
    if (!((ImageStoreProvider) storeProvider).isScopeSupported(scopeType)) {
        throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
    }
    // check if we have already image stores from other different providers,
    // we currently are not supporting image stores from different
    // providers co-existing
    final List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
    for (final ImageStoreVO store : imageStores) {
        if (!store.getProviderName().equalsIgnoreCase(providerName)) {
            throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName() + " already added");
        }
    }
    if (zoneId != null) {
        // Check if the zone exists in the system
        final DataCenterVO zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Can't find zone by id " + zoneId);
        }
        final Account account = CallContext.current().getCallingAccount();
        if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
            final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
            ex.addProxyObject(zone.getUuid(), "dcId");
            throw ex;
        }
    }
    final Map<String, Object> params = new HashMap();
    params.put("zoneId", zoneId);
    params.put("url", url);
    params.put("name", name);
    params.put("details", details);
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.Image);
    final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    final DataStore store;
    try {
        store = lifeCycle.initialize(params);
    } catch (final Exception e) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    if (((ImageStoreProvider) storeProvider).needDownloadSysTemplate()) {
        // trigger system vm template download
        _imageSrv.downloadBootstrapSysTemplate(store);
    } else {
        // populate template_store_ref table
        _imageSrv.addSystemVMTemplatesToSecondary(store);
    }
    // associate builtin template with zones associated with this image store
    associateCrosszoneTemplatesToZone(zoneId);
    // duplicate cache store records to region wide storage
    if (scopeType == ScopeType.REGION) {
        duplicateCacheStoreRecordsToRegionStore(store.getId());
    }
    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) ImageStoreProvider(com.cloud.engine.subsystem.api.storage.ImageStoreProvider) 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) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 9 with DataStoreLifeCycle

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

the class StorageManagerImpl method preparePrimaryStorageForMaintenance.

@Override
@DB
public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(final Long primaryStorageId) throws ResourceUnavailableException, InsufficientCapacityException {
    final StoragePoolVO primaryStorage;
    primaryStorage = _storagePoolDao.findById(primaryStorageId);
    if (primaryStorage == null) {
        final String msg = "Unable to obtain lock on the storage pool record in preparePrimaryStorageForMaintenance()";
        s_logger.error(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up) && !primaryStorage.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)) {
        throw new InvalidParameterValueException("Primary storage with id " + primaryStorageId + " is not ready for migration, as the status is:" + primaryStorage.getStatus().toString());
    }
    final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    lifeCycle.maintain(store);
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Example 10 with DataStoreLifeCycle

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

the class StorageManagerImpl method createSecondaryStagingStore.

@Override
public ImageStore createSecondaryStagingStore(final CreateSecondaryStagingStoreCmd cmd) {
    final String providerName = cmd.getProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultCacheDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find cache store provider: " + providerName);
        }
    }
    final Long dcId = cmd.getZoneId();
    ScopeType scopeType = null;
    final String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
        } catch (final Exception e) {
            throw new InvalidParameterValueException("invalid scope for cache store " + scope);
        }
        if (scopeType != ScopeType.ZONE) {
            throw new InvalidParameterValueException("Only zone wide cache storage is supported");
        }
    }
    if (scopeType == ScopeType.ZONE && dcId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }
    // Check if the zone exists in the system
    final DataCenterVO zone = _dcDao.findById(dcId);
    if (zone == null) {
        throw new InvalidParameterValueException("Can't find zone by id " + dcId);
    }
    final Account account = CallContext.current().getCallingAccount();
    if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }
    final Map<String, Object> params = new HashMap<>();
    params.put("zoneId", dcId);
    params.put("url", cmd.getUrl());
    params.put("name", cmd.getUrl());
    params.put("details", cmd.getDetails());
    params.put("scope", scopeType);
    params.put("providerName", storeProvider.getName());
    params.put("role", DataStoreRole.ImageCache);
    final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    final DataStore store;
    try {
        store = lifeCycle.initialize(params);
    } catch (final Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.ImageCache);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) 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) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)10 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)10 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)10 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)5 HashMap (java.util.HashMap)5 ExecutionException (java.util.concurrent.ExecutionException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 PrimaryDataStoreInfo (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo)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