Search in sources :

Example 51 with CopyCommandResult

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

the class TemplateServiceImpl method copyTemplateCallBack.

protected Void copyTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, TemplateOpContext<TemplateApiResult> context) {
    TemplateInfo destTemplate = context.getTemplate();
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (Exception e) {
        s_logger.debug("Failed to process copy template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 52 with CopyCommandResult

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

the class DataObjectManagerImpl method copyCallback.

protected Void copyCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, CopyContext<CreateCmdResult> context) {
    CopyCommandResult result = callback.getResult();
    DataObject destObj = context.destObj;
    if (result.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("Failed to update copying state", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("Failed to update copying state", e);
        }
        CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult(result.getResult());
        context.getParentCallback().complete(res);
    }
    try {
        objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (NoTransitionException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, 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 update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    } catch (ConcurrentOperationException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, 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 update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    }
    CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 53 with CopyCommandResult

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

the class VolumeServiceImpl method migrateVolumes.

@Override
public AsyncCallFuture<CommandResult> migrateVolumes(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost) {
    AsyncCallFuture<CommandResult> future = new AsyncCallFuture<CommandResult>();
    CommandResult res = new CommandResult();
    try {
        // Check to make sure there are no snapshot operations on a volume
        // and
        // put it in the migrating state.
        List<VolumeInfo> volumesMigrating = new ArrayList<VolumeInfo>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeMap.entrySet()) {
            VolumeInfo volume = entry.getKey();
            if (!snapshotMgr.canOperateOnVolume(volume)) {
                s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now.");
                res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now.");
                future.complete(res);
                // to be put back in ready state.
                for (VolumeInfo volumeMigrating : volumesMigrating) {
                    volumeMigrating.processEvent(Event.OperationFailed);
                }
                return future;
            } else {
                volume.processEvent(Event.MigrationRequested);
                volumesMigrating.add(volume);
            }
        }
        MigrateVmWithVolumesContext<CommandResult> context = new MigrateVmWithVolumesContext<CommandResult>(null, future, volumeMap);
        AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context);
        motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller);
    } catch (Exception e) {
        s_logger.debug("Failed to copy volume", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return future;
}
Also used : ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageAccessException(com.cloud.exception.StorageAccessException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Map(java.util.Map) HashMap(java.util.HashMap) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 54 with CopyCommandResult

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

the class VolumeServiceImpl method createManagedVolumeCloneTemplateAsync.

/**
 * Clones the template volume on managed storage to the ROOT volume
 *
 * @param volumeInfo ROOT volume to create
 * @param templateOnPrimary Template from which to clone the ROOT volume
 * @param destPrimaryDataStore Primary storage of the volume
 * @param future For async
 */
private void createManagedVolumeCloneTemplateAsync(VolumeInfo volumeInfo, TemplateInfo templateOnPrimary, PrimaryDataStore destPrimaryDataStore, AsyncCallFuture<VolumeApiResult> future) {
    VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId(), volumeInfo.getDeployAsIsConfiguration());
    if (templatePoolRef == null) {
        throw new CloudRuntimeException("Failed to find template " + templateOnPrimary.getUniqueName() + " in storage pool " + destPrimaryDataStore.getId());
    }
    // XXX: not sure if this the right thing to do here. We can always fallback to the "copy from sec storage"
    if (templatePoolRef.getDownloadState() == Status.NOT_DOWNLOADED) {
        throw new CloudRuntimeException("Template " + templateOnPrimary.getUniqueName() + " has not been downloaded to primary storage.");
    }
    try {
        volumeInfo.processEvent(Event.CreateOnlyRequested);
        CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, templateOnPrimary, future, null, volumeInfo.getDeployAsIsConfiguration());
        AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
        caller.setContext(context);
        motionSrv.copyAsync(templateOnPrimary, volumeInfo, caller);
    } catch (Throwable e) {
        s_logger.debug("Failed to clone template on primary storage", e);
        volumeInfo.processEvent(Event.OperationFailed);
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 55 with CopyCommandResult

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

the class VolumeServiceImpl method createVolumeFromBaseImageAsync.

@DB
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
    DataObject volumeOnPrimaryStorage = pd.create(volume, volume.getDeployAsIsConfiguration());
    volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
    CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null, volume.getDeployAsIsConfiguration());
    AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
    caller.setContext(context);
    motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
    return;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Aggregations

CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)68 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)48 ExecutionException (java.util.concurrent.ExecutionException)27 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)21 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)20 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)19 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)17 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 StorageAccessException (com.cloud.exception.StorageAccessException)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)14 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)14 HostVO (com.cloud.host.HostVO)12 Answer (com.cloud.agent.api.Answer)11 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)11 HashMap (java.util.HashMap)10 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)9 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)8 VMInstanceVO (com.cloud.vm.VMInstanceVO)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8