Search in sources :

Example 6 with CopyCommand

use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(final DataObject srcdata, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final DataStore store = destData.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
            // For CLVM, we need to copy template to primary storage at all, just fake the copy result.
            final TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(ImageFormat.RAW);
            final CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            final CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        } else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
            // For CLVM, we need to pass template on secondary storage to hypervisor
            final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
            final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
            final StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            final DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            final DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
            final EndPoint ep = epSelector.select(srcData, 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);
            }
            final CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 7 with CopyCommand

use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(final SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        final SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        final AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        final VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    }
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    volumeInfo.processEvent(Event.MigrationRequested);
    volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        _volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        final Map<String, String> destDetails = getVolumeDetails(volumeInfo);
        copyCommand.setOptions2(destDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        try {
            _volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    String errMsg = null;
    if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
        if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
            errMsg = copyCmdAnswer.getDetails();
        } else {
            errMsg = "Unable to perform host-side operation";
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) HostVO(com.cloud.host.HostVO) SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 8 with CopyCommand

use of com.cloud.legacymodel.communication.command.CopyCommand 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.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.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.legacymodel.communication.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 9 with CopyCommand

use of com.cloud.legacymodel.communication.command.CopyCommand in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method createTemplateFromSnapshot.

@DB
protected Answer createTemplateFromSnapshot(DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.CreatePrivateTemplateFromSnapshotWait.toString());
    final int _createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait.getDefaultValue()));
    boolean needCache = false;
    if (needCacheStorage(srcData, destData)) {
        needCache = true;
        final SnapshotInfo snapshot = (SnapshotInfo) srcData;
        srcData = cacheSnapshotChain(snapshot, snapshot.getDataStore().getScope());
    }
    EndPoint ep = null;
    if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
        ep = selector.select(destData);
    } else {
        ep = selector.select(srcData, destData);
    }
    final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _createprivatetemplatefromsnapshotwait, 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);
    }
    // clean up snapshot copied to staging
    if (needCache && srcData != null) {
        // reduce ref count, but keep it there on cache which is converted from previous secondary storage
        cacheMgr.releaseCacheObject(srcData);
    }
    return answer;
}
Also used : MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) CopyCommand(com.cloud.legacymodel.communication.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) DB(com.cloud.utils.db.DB)

Example 10 with CopyCommand

use of com.cloud.legacymodel.communication.command.CopyCommand 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.legacymodel.to.DataStoreTO) StoragePool(com.cloud.legacymodel.storage.StoragePool) CopyCommand(com.cloud.legacymodel.communication.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.legacymodel.to.NfsTO) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Aggregations

CopyCommand (com.cloud.legacymodel.communication.command.CopyCommand)11 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)8 Answer (com.cloud.legacymodel.communication.answer.Answer)7 MigrateVolumeAnswer (com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer)6 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)6 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)6 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)5 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)4 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)3 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)3 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)3 Scope (com.cloud.engine.subsystem.api.storage.Scope)3 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)3 HostVO (com.cloud.host.HostVO)3 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)3 StorageSubSystemCommand (com.cloud.legacymodel.communication.command.StorageSubSystemCommand)2 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)2 DataTO (com.cloud.legacymodel.to.DataTO)2 NfsTO (com.cloud.legacymodel.to.NfsTO)2