Search in sources :

Example 1 with CopyCommand

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

the class StorageSystemDataMotionStrategy method handleCreateTemplateFromSnapshot.

private Void handleCreateTemplateFromSnapshot(final SnapshotInfo snapshotInfo, final TemplateInfo templateInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        snapshotInfo.processEvent(Event.CopyingRequested);
    } catch (final Exception ex) {
        throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
    }
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final DataStore srcDataStore = snapshotInfo.getDataStore();
    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(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        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";
            }
        }
        try {
            if (errMsg == null) {
                snapshotInfo.processEvent(Event.OperationSuccessed);
            } else {
                snapshotInfo.processEvent(Event.OperationFailed);
            }
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 2 with CopyCommand

use of com.cloud.storage.command.CopyCommand 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 3 with CopyCommand

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

the class AncientDataMotionStrategy method cloneVolume.

protected Answer cloneVolume(final DataObject template, final DataObject volume) {
    final CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0, VirtualMachineManager.ExecuteInSequence.value());
    try {
        final EndPoint ep = selector.select(volume.getDataStore());
        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.debug("Failed to send to storage pool", e);
        throw new CloudRuntimeException("Failed to send to storage pool", e);
    }
}
Also used : MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with CopyCommand

use of com.cloud.storage.command.CopyCommand 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 5 with CopyCommand

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

the class KVMGuru method getCommandHostDelegation.

@Override
public Pair<Boolean, Long> getCommandHostDelegation(final long hostId, final Command cmd) {
    if (cmd instanceof StorageSubSystemCommand) {
        final StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(false);
    }
    if (cmd instanceof CopyCommand) {
        final CopyCommand c = (CopyCommand) cmd;
        final DataTO srcData = c.getSrcTO();
        boolean inSeq = true;
        if (c.getSrcTO().getObjectType() == DataObjectType.SNAPSHOT || c.getDestTO().getObjectType() == DataObjectType.SNAPSHOT) {
            inSeq = false;
        } else if (c.getDestTO().getDataStore().getRole() == DataStoreRole.Image || c.getDestTO().getDataStore().getRole() == DataStoreRole.ImageCache) {
            inSeq = false;
        }
        c.setExecuteInSequence(inSeq);
        if (srcData.getHypervisorType() == HypervisorType.KVM) {
            return new Pair<>(true, new Long(hostId));
        }
    }
    return new Pair<>(false, new Long(hostId));
}
Also used : StorageSubSystemCommand(com.cloud.storage.command.StorageSubSystemCommand) DataTO(com.cloud.agent.api.to.DataTO) CopyCommand(com.cloud.storage.command.CopyCommand) Pair(com.cloud.utils.Pair)

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