Search in sources :

Example 11 with CopyCommand

use of com.cloud.storage.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.agent.api.to.DataStoreTO) StoragePool(com.cloud.storage.StoragePool) CopyCommand(com.cloud.storage.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

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