Search in sources :

Example 11 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotOnPrimaryStore == null) {
        throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools");
    }
    PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context);
    ((PrimaryDataStoreDriver) store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 12 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class DataObjectManagerImpl method deleteAsynCallback.

protected Void deleteAsynCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CommandResult> callback, DeleteContext<CommandResult> context) {
    DataObject destObj = context.obj;
    CommandResult res = callback.getResult();
    if (res.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    } else {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationSuccessed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    }
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Example 13 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class VolumeServiceImpl method deleteVolumeCallback.

public Void deleteVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, DeleteVolumeContext<VolumeApiResult> context) {
    CommandResult result = callback.getResult();
    VolumeObject vo = context.getVolume();
    VolumeApiResult apiResult = new VolumeApiResult(vo);
    try {
        if (result.isSuccess()) {
            vo.processEvent(Event.OperationSuccessed);
            if (canVolumeBeRemoved(vo.getId())) {
                s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table");
                volDao.remove(vo.getId());
            }
            SnapshotDataStoreVO snapStoreVo = _snapshotStoreDao.findByVolume(vo.getId(), DataStoreRole.Primary);
            if (snapStoreVo != null) {
                long storagePoolId = snapStoreVo.getDataStoreId();
                StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
                if (storagePoolVO.isManaged()) {
                    DataStore primaryDataStore = dataStoreMgr.getPrimaryDataStore(storagePoolId);
                    Map<String, String> mapCapabilities = primaryDataStore.getDriver().getCapabilities();
                    String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
                    Boolean supportsStorageSystemSnapshots = new Boolean(value);
                    if (!supportsStorageSystemSnapshots) {
                        _snapshotStoreDao.remove(snapStoreVo.getId());
                    }
                } else {
                    _snapshotStoreDao.remove(snapStoreVo.getId());
                }
            }
        } else {
            vo.processEvent(Event.OperationFailed);
            apiResult.setResult(result.getResult());
        }
    } catch (Exception e) {
        s_logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e);
    }
    context.getFuture().complete(apiResult);
    return null;
}
Also used : PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) 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)

Example 14 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CommandResult> callback) {
    DeleteCommand cmd = new DeleteCommand(data.getTO());
    cmd.setBypassHostMaintenance(commandCanBypassHostMaintenance(data));
    CommandResult result = new CommandResult();
    try {
        EndPoint ep = null;
        if (data.getType() == DataObjectType.VOLUME) {
            ep = epSelector.select(data, StorageAction.DELETEVOLUME);
        } else {
            ep = epSelector.select(data);
        }
        if (ep == null) {
            String errMsg = "No remote endpoint to send DeleteCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            result.setResult(errMsg);
        } else {
            Answer answer = ep.sendMessage(cmd);
            if (answer != null && !answer.getResult()) {
                result.setResult(answer.getDetails());
            }
        }
    } catch (Exception ex) {
        s_logger.debug("Unable to destoy volume" + data.getId(), ex);
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 15 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class CloudStackPrimaryDataStoreDriverImpl method revertSnapshot.

@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
    RevertSnapshotCommand cmd = new RevertSnapshotCommand(snapshotTO);
    CommandResult result = new CommandResult();
    try {
        EndPoint ep = epSelector.select(snapshotOnPrimaryStore);
        if (ep == null) {
            String errMsg = "No remote endpoint to send RevertSnapshotCommand, check if host or ssvm is down?";
            s_logger.error(errMsg);
            result.setResult(errMsg);
        } else {
            Answer answer = ep.sendMessage(cmd);
            if (answer != null && !answer.getResult()) {
                result.setResult(answer.getDetails());
            }
        }
    } catch (Exception ex) {
        s_logger.debug("Unable to revert snapshot " + snapshot.getId(), ex);
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RevertSnapshotCommand(org.apache.cloudstack.storage.command.RevertSnapshotCommand) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CommandResult (org.apache.cloudstack.storage.command.CommandResult)37 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 ExecutionException (java.util.concurrent.ExecutionException)11 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)7 VolumeVO (com.cloud.storage.VolumeVO)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 HashMap (java.util.HashMap)6 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 Answer (com.cloud.agent.api.Answer)4 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)4 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 Host (com.cloud.host.Host)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)4