Search in sources :

Example 36 with CommandResult

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

the class VolumeServiceImpl method expungeVolumeAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    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
    VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
    if (volumeStore != null) {
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            String msg = "Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.";
            s_logger.debug(msg);
            result.setSuccess(false);
            result.setResult(msg);
            future.complete(result);
            return future;
        }
    }
    VolumeVO vol = volDao.findById(volume.getId());
    if (vol == null) {
        s_logger.debug("Volume " + volume.getId() + " is not found");
        future.complete(result);
        return future;
    }
    if (!volumeExistsOnPrimary(vol)) {
        // 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);
            }
            VMTemplateVO template = templateDao.findById(vol.getTemplateId());
            if (template != null && !template.isDeployAsIs()) {
                volDao.remove(vol.getId());
                future.complete(result);
                return future;
            }
        }
    }
    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);
    }
    DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<VolumeApiResult>(null, vo, future);
    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 : VMTemplateVO(com.cloud.storage.VMTemplateVO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) DB(com.cloud.utils.db.DB)

Example 37 with CommandResult

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

the class VolumeServiceImpl method migrateVmWithVolumesCallBack.

protected Void migrateVmWithVolumesCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, MigrateVmWithVolumesContext<CommandResult> context) {
    Map<VolumeInfo, DataStore> volumeToPool = context.volumeToPool;
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<CommandResult> future = context.future;
    CommandResult res = new CommandResult();
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                VolumeInfo volume = entry.getKey();
                volume.processEvent(Event.OperationFailed);
            }
            future.complete(res);
        } else {
            for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                VolumeInfo volume = entry.getKey();
                snapshotMgr.cleanupSnapshotsByVolume(volume.getId());
                volume.processEvent(Event.OperationSuccessed);
            }
            future.complete(res);
        }
    } catch (Exception e) {
        s_logger.error("Failed to process copy volume callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) Map(java.util.Map) HashMap(java.util.HashMap) 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)

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