Search in sources :

Example 16 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class HypervStorageMotionStrategy method copyAsync.

@Override
public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
    Answer answer = null;
    String errMsg = null;
    try {
        VMInstanceVO instance = instanceDao.findById(vmTo.getId());
        if (instance != null) {
            answer = migrateVmWithVolumes(instance, vmTo, srcHost, destHost, volumeMap);
        } else {
            throw new CloudRuntimeException("Unsupported operation requested for moving data.");
        }
    } catch (Exception e) {
        s_logger.error("copy failed", e);
        errMsg = e.toString();
    }
    CopyCommandResult result = new CopyCommandResult(null, answer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : Answer(com.cloud.agent.api.Answer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException)

Example 17 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class DataObjectManagerImpl method copyAsync.

@Override
public void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CreateCmdResult> callback) {
    try {
        objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
    } catch (NoTransitionException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to change state: " + e.toString());
        callback.complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to change state: " + e.toString());
        callback.complete(res);
    }
    CopyContext<CreateCmdResult> anotherCall = new CopyContext<CreateCmdResult>(callback, srcData, destData);
    AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
    motionSrv.copyAsync(srcData, destData, caller);
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 18 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
    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.
            TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(Storage.ImageFormat.RAW);
            CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            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
            String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
            int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
            StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
            EndPoint ep = epSelector.select(srcData, destData);
            Answer answer = null;
            if (ep == null) {
                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);
            }
            CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 19 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method copyVolumeFromPrimaryToImage.

protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(VolumeInfo srcVolume, DataStore destStore) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    VolumeApiResult res = new VolumeApiResult(srcVolume);
    VolumeInfo destVolume = null;
    try {
        destVolume = (VolumeInfo) destStore.create(srcVolume);
        // this is just used for locking that src volume record in DB to avoid using lock
        srcVolume.processEvent(Event.MigrationRequested);
        destVolume.processEventOnly(Event.CreateOnlyRequested);
        CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<VolumeApiResult>(null, future, srcVolume, destVolume, destStore);
        AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
        return future;
    } catch (Exception e) {
        s_logger.error("failed to copy volume to image store", e);
        if (destVolume != null) {
            destVolume.getDataStore().delete(destVolume);
        }
        // unlock source volume record
        srcVolume.processEvent(Event.OperationFailed);
        res.setResult(e.toString());
        future.complete(res);
        return future;
    }
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method copyVolumeFromPrimaryToImageCallback.

protected Void copyVolumeFromPrimaryToImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CopyVolumeContext<VolumeApiResult> context) {
    VolumeInfo srcVolume = context.srcVolume;
    VolumeInfo destVolume = context.destVolume;
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<VolumeApiResult> future = context.future;
    VolumeApiResult res = new VolumeApiResult(destVolume);
    try {
        if (result.isFailed()) {
            // back to Ready state in Volume table
            srcVolume.processEvent(Event.OperationFailed);
            destVolume.processEventOnly(Event.OperationFailed);
            res.setResult(result.getResult());
            future.complete(res);
        } else {
            // back to Ready state in Volume table
            srcVolume.processEvent(Event.OperationSuccessed);
            destVolume.processEventOnly(Event.OperationSuccessed, result.getAnswer());
            future.complete(res);
        }
    } catch (Exception e) {
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)16 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)15 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)13 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)11 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)9 HashMap (java.util.HashMap)8 ExecutionException (java.util.concurrent.ExecutionException)8 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)8 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 CommandResult (org.apache.cloudstack.storage.command.CommandResult)7 Answer (com.cloud.agent.api.Answer)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)5 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)5