Search in sources :

Example 6 with CopyCommand

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

the class XenServerGuru method getCommandHostDelegation.

@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
    LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
    if (cmd instanceof StorageSubSystemCommand) {
        final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(true);
    }
    if (cmd instanceof CopyCommand) {
        final CopyCommand cpyCommand = (CopyCommand) cmd;
        final DataTO srcData = cpyCommand.getSrcTO();
        final DataTO destData = cpyCommand.getDestTO();
        if (srcData.getHypervisorType() == HypervisorType.XenServer && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
            final DataStoreTO srcStore = srcData.getDataStore();
            final DataStoreTO destStore = destData.getDataStore();
            if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
                HostVO host = hostDao.findById(hostId);
                final EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
                host = hostDao.findById(ep.getId());
                hostDao.loadDetails(host);
                final String hypervisorVersion = host.getHypervisorVersion();
                final String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
                if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
                    if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") && !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
                        return new Pair<>(Boolean.TRUE, new Long(ep.getId()));
                    }
                }
            }
        }
    }
    return new Pair<>(Boolean.FALSE, new Long(hostId));
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StorageSubSystemCommand(com.cloud.storage.command.StorageSubSystemCommand) DataTO(com.cloud.agent.api.to.DataTO) CopyCommand(com.cloud.storage.command.CopyCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) HostVO(com.cloud.host.HostVO) Pair(com.cloud.utils.Pair)

Example 7 with CopyCommand

use of com.cloud.storage.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(Storage.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 : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 8 with CopyCommand

use of com.cloud.storage.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.storage.command.CopyCommand) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 9 with CopyCommand

use of com.cloud.storage.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.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) 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) DB(com.cloud.utils.db.DB)

Example 10 with CopyCommand

use of com.cloud.storage.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.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)

Aggregations

CopyCommand (com.cloud.storage.command.CopyCommand)11 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)8 Answer (com.cloud.agent.api.Answer)7 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)6 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)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.storage.command.CopyCmdAnswer)3 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)2 DataTO (com.cloud.agent.api.to.DataTO)2 NfsTO (com.cloud.agent.api.to.NfsTO)2 StorageSubSystemCommand (com.cloud.storage.command.StorageSubSystemCommand)2