Search in sources :

Example 26 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class StorageManagerImpl method deleteImageStore.

@Override
public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
    final long storeId = cmd.getId();
    // Verify that image store exists
    ImageStoreVO store = _imageStoreDao.findById(storeId);
    if (store == null) {
        throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
    // Verify that there are no live snapshot, template, volume on the image
    // store to be deleted
    List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
    if (snapshots != null && snapshots.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
    }
    List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
    if (volumes != null && volumes.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
    }
    // search if there are user templates stored on this image store, excluding system, builtin templates
    List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
    if (templates != null && templates.size() > 0) {
        throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
    }
    // ready to delete
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // first delete from image_store_details table, we need to do that since
            // we are not actually deleting record from main
            // image_data_store table, so delete cascade will not work
            _imageStoreDetailsDao.deleteDetails(storeId);
            _snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
            _volumeStoreDao.deletePrimaryRecordsForStore(storeId);
            _templateStoreDao.deletePrimaryRecordsForStore(storeId);
            _imageStoreDao.remove(storeId);
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 27 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO 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 28 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class StorageManagerImpl method discoverImageStore.

@Override
public ImageStore discoverImageStore(String name, String url, String providerName, Long zoneId, 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;
    }
    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
    List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
    for (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
        DataCenterVO zone = _dcDao.findById(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Can't find zone by id " + zoneId);
        }
        Account account = CallContext.current().getCallingAccount();
        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
            PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
            ex.addProxyObject(zone.getUuid(), "dcId");
            throw ex;
        }
    }
    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);
    DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store;
    try {
        store = lifeCycle.initialize(params);
    } catch (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(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) ImageStoreProvider(org.apache.cloudstack.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.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) 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) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Example 29 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class SimulatorSecondaryDiscoverer method find.

@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List<String> hostTags) {
    if (!uri.getScheme().equalsIgnoreCase("sim")) {
        s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString());
        return null;
    }
    List<ImageStoreVO> stores = imageStoreDao.listImageStores();
    for (ImageStoreVO store : stores) {
        _mockStorageMgr.preinstallTemplates(store.getUrl(), dcId);
    }
    Map<SecondaryStorageResource, Map<String, String>> resources = new HashMap<SecondaryStorageResource, Map<String, String>>();
    resources.put(this.resource, new HashMap<String, String>());
    return resources;
}
Also used : HashMap(java.util.HashMap) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HashMap(java.util.HashMap) Map(java.util.Map) SecondaryStorageResource(org.apache.cloudstack.storage.resource.SecondaryStorageResource)

Example 30 with ImageStoreVO

use of org.apache.cloudstack.storage.datastore.db.ImageStoreVO in project cloudstack by apache.

the class StorageCacheManagerImpl method getCacheStores.

protected List<DataStore> getCacheStores() {
    QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class);
    sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
    List<ImageStoreVO> imageStoreVOs = sc.list();
    List<DataStore> stores = new ArrayList<DataStore>();
    for (ImageStoreVO vo : imageStoreVOs) {
        stores.add(dataStoreManager.getDataStore(vo.getId(), vo.getRole()));
    }
    return stores;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

ImageStoreVO (org.apache.cloudstack.storage.datastore.db.ImageStoreVO)38 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 Account (com.cloud.user.Account)10 DataCenterVO (com.cloud.dc.DataCenterVO)9 HashMap (java.util.HashMap)9 VMTemplateVO (com.cloud.storage.VMTemplateVO)8 ArrayList (java.util.ArrayList)8 ClusterVO (com.cloud.dc.ClusterVO)6 HostPodVO (com.cloud.dc.HostPodVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Map (java.util.Map)5 HostVO (com.cloud.host.HostVO)4 DataStoreRole (com.cloud.storage.DataStoreRole)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)3 URISyntaxException (java.net.URISyntaxException)3 DataStoreProvider (org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider)3 Test (org.testng.annotations.Test)3 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)2