Search in sources :

Example 6 with CommandResult

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

the class VolumeServiceImpl method deleteVolumeCallback.

public Void deleteVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, final DeleteVolumeContext<VolumeApiResult> context) {
    final CommandResult result = callback.getResult();
    final VolumeObject vo = context.getVolume();
    final 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());
            }
        } else {
            vo.processEvent(Event.OperationFailed);
            apiResult.setResult(result.getResult());
        }
    } catch (final 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 : ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 7 with CommandResult

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

the class VolumeServiceImpl method expungeVolumeAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(final VolumeInfo volume) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final VolumeApiResult result = new VolumeApiResult(volume);
    if (volume.getDataStore() == null) {
        s_logger.info("Expunge volume with no data store specified");
        if (canVolumeBeRemoved(volume.getId())) {
            s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
            volDao.remove(volume.getId());
        }
        future.complete(result);
        return future;
    }
    // Find out if the volume is at state of download_in_progress on secondary storage
    final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
    if (volumeStore != null) {
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
            future.complete(result);
            return future;
        }
    }
    final VolumeVO vol = volDao.findById(volume.getId());
    if (vol == null) {
        s_logger.debug("Volume " + volume.getId() + " is not found");
        future.complete(result);
        return future;
    }
    final String volumePath = vol.getPath();
    final Long poolId = vol.getPoolId();
    if (poolId == null || volumePath == null || volumePath.trim().isEmpty()) {
        // not created on primary store
        if (volumeStore == null) {
            // also not created on secondary store
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Marking volume that was never created as destroyed: " + vol);
            }
            volDao.remove(vol.getId());
            future.complete(result);
            return future;
        }
    }
    final VolumeObject vo = (VolumeObject) volume;
    if (volume.getDataStore().getRole() == DataStoreRole.Image) {
        // no need to change state in volumes table
        volume.processEventOnly(Event.DestroyRequested);
    } else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
        volume.processEvent(Event.ExpungeRequested);
    }
    final DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<>(null, vo, future);
    final AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
    volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
    return future;
}
Also used : CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) DB(com.cloud.utils.db.DB)

Example 8 with CommandResult

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

the class VolumeServiceImpl method migrateVolumes.

@Override
public AsyncCallFuture<CommandResult> migrateVolumes(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost) {
    final AsyncCallFuture<CommandResult> future = new AsyncCallFuture<>();
    final CommandResult res = new CommandResult();
    try {
        // Check to make sure there are no snapshot operations on a volume
        // and
        // put it in the migrating state.
        final List<VolumeInfo> volumesMigrating = new ArrayList<>();
        for (final Map.Entry<VolumeInfo, DataStore> entry : volumeMap.entrySet()) {
            final 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 (final VolumeInfo volumeMigrating : volumesMigrating) {
                    volumeMigrating.processEvent(Event.OperationFailed);
                }
                return future;
            } else {
                volume.processEvent(Event.MigrationRequested);
                volumesMigrating.add(volume);
            }
        }
        final MigrateVmWithVolumesContext<CommandResult> context = new MigrateVmWithVolumesContext<>(null, future, volumeMap);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context);
        motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller);
    } catch (final 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(com.cloud.engine.subsystem.api.storage.VolumeInfo) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Map(java.util.Map) HashMap(java.util.HashMap) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 9 with CommandResult

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

the class CloudStackPrimaryDataStoreDriverImpl method deleteAsync.

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

Example 10 with CommandResult

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

the class CloudStackPrimaryDataStoreDriverImpl method revertSnapshot.

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

Aggregations

CommandResult (com.cloud.storage.command.CommandResult)18 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 ExecutionException (java.util.concurrent.ExecutionException)11 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)8 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)7 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)6 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)6 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)5 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)4 Answer (com.cloud.agent.api.Answer)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 PrimaryDataStoreDriver (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2