Search in sources :

Example 6 with Scope

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

the class AncientDataMotionStrategy method copyVolumeBetweenPools.

protected Answer copyVolumeBetweenPools(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.CopyVolumeWait.key());
    final int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
    final Scope destScope = getZoneScope(destData.getDataStore().getScope());
    final DataStore cacheStore = cacheMgr.getCacheStorage(destScope);
    if (cacheStore == null) {
        // need to find a nfs or cifs image store, assuming that can't copy volume
        final ImageStoreEntity imageStore = (ImageStoreEntity) dataStoreMgr.getImageStore(destScope.getScopeId());
        if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
            s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
            return null;
        }
        final DataObject objOnImageStore = imageStore.create(srcData);
        objOnImageStore.processEvent(Event.CreateOnlyRequested);
        Answer answer = copyObject(srcData, objOnImageStore);
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to image store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed, answer);
        objOnImageStore.processEvent(Event.CopyingRequested);
        final CopyCommand cmd = new CopyCommand(objOnImageStore.getTO(), destData.getTO(), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        final EndPoint ep = selector.select(objOnImageStore, destData);
        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);
        }
        if (answer == null || !answer.getResult()) {
            if (answer != null) {
                s_logger.debug("copy to primary store failed: " + answer.getDetails());
            }
            objOnImageStore.processEvent(Event.OperationFailed);
            imageStore.delete(objOnImageStore);
            return answer;
        }
        objOnImageStore.processEvent(Event.OperationSuccessed);
        imageStore.delete(objOnImageStore);
        return answer;
    } else {
        final DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
        final CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
        final EndPoint ep = selector.select(cacheData, destData);
        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);
        }
        // delete volume on cache store
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    }
}
Also used : MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ImageStoreEntity(com.cloud.storage.image.datastore.ImageStoreEntity) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Example 7 with Scope

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

the class AncientDataMotionStrategy method pickCacheScopeForCopy.

private Scope pickCacheScopeForCopy(final DataObject srcData, final DataObject destData) {
    final Scope srcScope = srcData.getDataStore().getScope();
    final Scope destScope = destData.getDataStore().getScope();
    Scope selectedScope = null;
    if (srcScope.getScopeId() != null) {
        selectedScope = getZoneScope(srcScope);
    } else if (destScope.getScopeId() != null) {
        selectedScope = getZoneScope(destScope);
    } else {
        s_logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage");
    }
    return selectedScope;
}
Also used : ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope)

Example 8 with Scope

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

the class VolumeApiServiceImpl method needMoveVolume.

private boolean needMoveVolume(final VolumeVO existingVolume, final VolumeInfo newVolume) {
    if (existingVolume == null || existingVolume.getPoolId() == null || newVolume.getPoolId() == null) {
        return false;
    }
    final DataStore storeForExistingVol = dataStoreMgr.getPrimaryDataStore(existingVolume.getPoolId());
    final DataStore storeForNewVol = dataStoreMgr.getPrimaryDataStore(newVolume.getPoolId());
    final Scope storeForExistingStoreScope = storeForExistingVol.getScope();
    if (storeForExistingStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForExistingVol.getId());
    }
    final Scope storeForNewStoreScope = storeForNewVol.getScope();
    if (storeForNewStoreScope == null) {
        throw new CloudRuntimeException("Can't get scope of data store: " + storeForNewVol.getId());
    }
    if (storeForNewStoreScope.getScopeType() == ScopeType.ZONE) {
        return false;
    }
    if (storeForExistingStoreScope.getScopeType() != storeForNewStoreScope.getScopeType()) {
        if (storeForNewStoreScope.getScopeType() == ScopeType.CLUSTER) {
            Long vmClusterId = null;
            if (storeForExistingStoreScope.getScopeType() == ScopeType.HOST) {
                final HostScope hs = (HostScope) storeForExistingStoreScope;
                vmClusterId = hs.getClusterId();
            } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) {
                final Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
                if (hostId != null) {
                    final HostVO host = _hostDao.findById(hostId);
                    vmClusterId = host.getClusterId();
                }
            }
            if (storeForNewStoreScope.getScopeId().equals(vmClusterId)) {
                return false;
            } else {
                return true;
            }
        } else if (storeForNewStoreScope.getScopeType() == ScopeType.HOST && (storeForExistingStoreScope.getScopeType() == ScopeType.CLUSTER || storeForExistingStoreScope.getScopeType() == ScopeType.ZONE)) {
            final Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId();
            if (storeForNewStoreScope.getScopeId().equals(hostId)) {
                return false;
            }
        }
        throw new InvalidParameterValueException("Can't move volume between scope: " + storeForNewStoreScope.getScopeType() + " and " + storeForExistingStoreScope.getScopeType());
    }
    return !storeForExistingStoreScope.isSameScope(storeForNewStoreScope);
}
Also used : Scope(com.cloud.engine.subsystem.api.storage.Scope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) HostVO(com.cloud.host.HostVO)

Example 9 with Scope

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

the class TemplateManagerImpl method prepareIso.

// for ISO, we need to consider whether to copy to cache storage or not if it is not on NFS, since our hypervisor resource always assumes that they are in NFS
@Override
public TemplateInfo prepareIso(final long isoId, final long dcId) {
    final TemplateInfo tmplt = _tmplFactory.getTemplate(isoId, DataStoreRole.Image, dcId);
    if (tmplt == null || tmplt.getFormat() != ImageFormat.ISO) {
        s_logger.warn("ISO: " + isoId + " does not exist in vm_template table");
        return null;
    }
    if (tmplt.getDataStore() != null && !(tmplt.getDataStore().getTO() instanceof NfsTO)) {
        // if it is s3, need to download into cache storage first
        final Scope destScope = new ZoneScope(dcId);
        final TemplateInfo cacheData = (TemplateInfo) cacheMgr.createCacheObject(tmplt, destScope);
        if (cacheData == null) {
            s_logger.error("Failed in copy iso from S3 to cache storage");
            return null;
        }
        return cacheData;
    } else {
        return tmplt;
    }
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) PublishScope(com.cloud.framework.messagebus.PublishScope) NfsTO(com.cloud.agent.api.to.NfsTO)

Aggregations

Scope (com.cloud.engine.subsystem.api.storage.Scope)9 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)5 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Answer (com.cloud.agent.api.Answer)3 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)3 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)3 CopyCommand (com.cloud.storage.command.CopyCommand)3 HostVO (com.cloud.host.HostVO)2 NfsTO (com.cloud.agent.api.to.NfsTO)1 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)1 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)1 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)1 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1