Search in sources :

Example 11 with ZoneScope

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

the class PrimaryDataStoreImpl method getScope.

@Override
public Scope getScope() {
    final 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) {
        final 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(com.cloud.engine.subsystem.api.storage.ZoneScope) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) HostScope(com.cloud.engine.subsystem.api.storage.HostScope)

Example 12 with ZoneScope

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

the class ImageStoreProviderManagerImpl method listImageCacheStores.

@Override
public List<DataStore> listImageCacheStores(final Scope scope) {
    if (scope.getScopeType() != ScopeType.ZONE) {
        s_logger.debug("only support zone wide image cache stores");
        return null;
    }
    final List<ImageStoreVO> stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId()));
    final List<DataStore> imageStores = new ArrayList<>();
    for (final ImageStoreVO store : stores) {
        imageStores.add(getImageStore(store.getId()));
    }
    return imageStores;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO)

Example 13 with ZoneScope

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

the class AncientDataMotionStrategy method getZoneScope.

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

Example 14 with ZoneScope

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

the class AncientDataMotionStrategy method copyVolumeFromSnapshot.

protected Answer copyVolumeFromSnapshot(final DataObject snapObj, final DataObject volObj) {
    final SnapshotInfo snapshot = (SnapshotInfo) snapObj;
    final StoragePool pool = (StoragePool) volObj.getDataStore();
    final String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
    final DataStore store = snapObj.getDataStore();
    final DataStoreTO storTO = store.getTO();
    DataObject srcData = snapObj;
    try {
        if (!(storTO instanceof NfsTO)) {
            // cache snapshot to zone-wide staging store for the volume to be created
            srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
        }
        final String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
        final int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
        EndPoint ep = null;
        if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
            ep = selector.select(volObj);
        } else {
            ep = selector.select(srcData, volObj);
        }
        final CopyCommand cmd = new CopyCommand(srcData.getTO(), volObj.getTO(), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
        Answer answer = null;
        if (ep == null) {
            final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        return answer;
    } catch (final Exception e) {
        s_logger.error(basicErrMsg, e);
        throw new CloudRuntimeException(basicErrMsg);
    } finally {
        if (!(storTO instanceof NfsTO)) {
            // still keep snapshot on cache which may be migrated from previous secondary storage
            releaseSnapshotCacheChain((SnapshotInfo) srcData);
        }
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StoragePool(com.cloud.storage.StoragePool) CopyCommand(com.cloud.storage.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 15 with ZoneScope

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

the class StorageManagerImpl method cleanupSecondaryStorage.

@Override
@DB
public void cleanupSecondaryStorage(final boolean recurring) {
    // so here we don't need to issue DeleteCommand to resource anymore, only need to remove db entry.
    try {
        // Cleanup templates in template_store_ref
        final List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(null));
        for (final DataStore store : imageStores) {
            try {
                final long storeId = store.getId();
                final List<TemplateDataStoreVO> destroyedTemplateStoreVOs = _templateStoreDao.listDestroyed(storeId);
                s_logger.debug("Secondary storage garbage collector found " + destroyedTemplateStoreVOs.size() + " templates to cleanup on template_store_ref for store: " + store.getName());
                for (final TemplateDataStoreVO destroyedTemplateStoreVO : destroyedTemplateStoreVOs) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Deleting template store DB entry: " + destroyedTemplateStoreVO);
                    }
                    _templateStoreDao.remove(destroyedTemplateStoreVO.getId());
                }
            } catch (final Exception e) {
                s_logger.warn("problem cleaning up templates in template_store_ref for store: " + store.getName(), e);
            }
        }
        // CleanUp snapshots on snapshot_store_ref
        for (final DataStore store : imageStores) {
            try {
                final List<SnapshotDataStoreVO> destroyedSnapshotStoreVOs = _snapshotStoreDao.listDestroyed(store.getId());
                s_logger.debug("Secondary storage garbage collector found " + destroyedSnapshotStoreVOs.size() + " snapshots to cleanup on snapshot_store_ref for store: " + store.getName());
                for (final SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) {
                    // check if this snapshot has child
                    final SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store);
                    if (snap.getChild() != null) {
                        s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child");
                        continue;
                    }
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Deleting snapshot store DB entry: " + destroyedSnapshotStoreVO);
                    }
                    _snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId());
                    final SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
                    if (snapshotOnPrimary != null) {
                        _snapshotStoreDao.remove(snapshotOnPrimary.getId());
                    }
                    _snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId());
                }
            } catch (final Exception e2) {
                s_logger.warn("problem cleaning up snapshots in snapshot_store_ref for store: " + store.getName(), e2);
            }
        }
        // CleanUp volumes on volume_store_ref
        for (final DataStore store : imageStores) {
            try {
                final List<VolumeDataStoreVO> destroyedStoreVOs = _volumeStoreDao.listDestroyed(store.getId());
                s_logger.debug("Secondary storage garbage collector found " + destroyedStoreVOs.size() + " volumes to cleanup on volume_store_ref for store: " + store.getName());
                for (final VolumeDataStoreVO destroyedStoreVO : destroyedStoreVOs) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Deleting volume store DB entry: " + destroyedStoreVO);
                    }
                    _volumeStoreDao.remove(destroyedStoreVO.getId());
                }
            } catch (final Exception e2) {
                s_logger.warn("problem cleaning up volumes in volume_store_ref for store: " + store.getName(), e2);
            }
        }
    } catch (final Exception e3) {
        s_logger.warn("problem cleaning up secondary storage DB entries. ", e3);
    }
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) 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) DB(com.cloud.utils.db.DB)

Aggregations

ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)20 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)5 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)5 NfsTO (com.cloud.agent.api.to.NfsTO)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 Answer (com.cloud.agent.api.Answer)3 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 ConnectionException (com.cloud.exception.ConnectionException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 HostVO (com.cloud.host.HostVO)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)2 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)2 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)2