Search in sources :

Example 1 with Scope

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

the class AncientDataMotionStrategy method copySnapshot.

protected Answer copySnapshot(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.BackupSnapshotWait.toString());
    final int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
    DataObject cacheData = null;
    final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
    final Object payload = snapshotInfo.getPayload();
    Boolean fullSnapshot = true;
    if (payload != null) {
        fullSnapshot = (Boolean) payload;
    }
    final Map<String, String> options = new HashMap<>();
    options.put("fullSnapshot", fullSnapshot.toString());
    Answer answer = null;
    try {
        if (needCacheStorage(srcData, destData)) {
            final Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
            cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setCacheTO(cacheData.getTO());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, 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);
            }
        } else {
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
            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);
            }
        }
        // clean up cache entry
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("copy snasphot failed: " + e.toString());
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : HashMap(java.util.HashMap) CopyCommand(com.cloud.storage.command.CopyCommand) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataObject(com.cloud.engine.subsystem.api.storage.DataObject)

Example 2 with Scope

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

the class AncientDataMotionStrategy method copyObject.

protected Answer copyObject(final DataObject srcData, final DataObject destData, final Host destHost) {
    final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    Answer answer = null;
    DataObject cacheData = null;
    DataObject srcForCopy = srcData;
    try {
        if (needCacheStorage(srcData, destData)) {
            final Scope destScope = pickCacheScopeForCopy(srcData, destData);
            srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
        }
        final CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), destData.getTO(), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        final EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, 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 (cacheData != null) {
            final Long cacheId = cacheData.getId();
            final String cacheType = cacheData.getType().toString();
            final String cacheUuid = cacheData.getUuid().toString();
            if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
                // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
                // Delete cache in order to certainly transfer a latest image.
                s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                cacheMgr.deleteCacheObject(srcForCopy);
            } else {
                // for template, we want to leave it on cache for performance reason
                if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
                    // cache object created by this copy, not already there
                    s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.deleteCacheObject(srcForCopy);
                } else {
                    s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.releaseCacheObject(srcForCopy);
                }
            }
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("copy object failed: ", e);
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with Scope

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

the class DefaultEndPointSelector method findEndPointForImageMove.

protected EndPoint findEndPointForImageMove(final DataStore srcStore, final DataStore destStore) {
    // find any xenserver/kvm host in the scope
    final Scope srcScope = srcStore.getScope();
    final Scope destScope = destStore.getScope();
    Scope selectedScope = null;
    Long poolId = null;
    // scope
    if (srcScope.getScopeType() != ScopeType.ZONE) {
        selectedScope = srcScope;
        poolId = srcStore.getId();
    } else if (destScope.getScopeType() != ScopeType.ZONE) {
        selectedScope = destScope;
        poolId = destStore.getId();
    } else {
        // if both are zone scope
        if (srcStore.getRole() == DataStoreRole.Primary) {
            selectedScope = srcScope;
            poolId = srcStore.getId();
        } else if (destStore.getRole() == DataStoreRole.Primary) {
            selectedScope = destScope;
            poolId = destStore.getId();
        }
    }
    return findEndPointInScope(selectedScope, findOneHostOnPrimaryStorage, poolId);
}
Also used : Scope(com.cloud.engine.subsystem.api.storage.Scope)

Example 4 with Scope

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

the class DefaultEndPointSelector method findEndpointForImageStorage.

protected EndPoint findEndpointForImageStorage(final DataStore store) {
    Long dcId = null;
    final Scope storeScope = store.getScope();
    if (storeScope.getScopeType() == ScopeType.ZONE) {
        dcId = storeScope.getScopeId();
    }
    // find ssvm that can be used to download data to store. For zone-wide
    // image store, use SSVM for that zone. For region-wide store,
    // we can arbitrarily pick one ssvm to do that task
    final List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
    if (ssAHosts == null || ssAHosts.isEmpty()) {
        return null;
    }
    Collections.shuffle(ssAHosts);
    final HostVO host = ssAHosts.get(0);
    return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
}
Also used : Scope(com.cloud.engine.subsystem.api.storage.Scope) HostVO(com.cloud.host.HostVO)

Example 5 with Scope

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

the class VolumeServiceImpl method registerVolumeCallback.

protected Void registerVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
    final CreateCmdResult result = callback.getResult();
    final VolumeObject vo = (VolumeObject) context.volume;
    try {
        if (result.isFailed()) {
            vo.processEvent(Event.OperationFailed);
            // delete the volume entry from volumes table in case of failure
            final VolumeVO vol = volDao.findById(vo.getId());
            if (vol != null) {
                volDao.remove(vo.getId());
            }
        } else {
            vo.processEvent(Event.OperationSuccessed, result.getAnswer());
            if (vo.getSize() != null) {
                // publish usage events
                // get physical size from volume_store_ref table
                final DataStore ds = vo.getDataStore();
                final VolumeDataStoreVO volStore = _volumeStoreDao.findByStoreVolume(ds.getId(), vo.getId());
                if (volStore == null) {
                    s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!");
                }
                final Scope dsScope = ds.getScope();
                if (dsScope.getScopeType() == ScopeType.REGION) {
                    _resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
                }
            }
        }
        final VolumeApiResult res = new VolumeApiResult(vo);
        context.future.complete(res);
        return null;
    } catch (final Exception e) {
        s_logger.error("register volume failed: ", e);
        // delete the volume entry from volumes table in case of failure
        final VolumeVO vol = volDao.findById(vo.getId());
        if (vol != null) {
            volDao.remove(vo.getId());
        }
        final VolumeApiResult res = new VolumeApiResult(null);
        context.future.complete(res);
        return null;
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Scope(com.cloud.engine.subsystem.api.storage.Scope) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

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