Search in sources :

Example 21 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createVolumeAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final DataObject volumeOnStore = dataStore.create(volume);
    volumeOnStore.processEvent(Event.CreateOnlyRequested);
    try {
        final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
        dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
        if (volStoreVO != null) {
            final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
        volResult.setResult(ex.getMessage());
        future.complete(volResult);
    }
    return future;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 22 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO 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 23 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class BaseImageStoreDriverImpl method createVolumeAsyncCallback.

protected Void createVolumeAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
    final DownloadAnswer answer = callback.getResult();
    final DataObject obj = context.data;
    final DataStore store = obj.getDataStore();
    final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
    if (volStoreVO != null) {
        if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        final VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
        updateBuilder.setDownloadPercent(answer.getDownloadPct());
        updateBuilder.setDownloadState(answer.getDownloadStatus());
        updateBuilder.setLastUpdated(new Date());
        updateBuilder.setErrorString(answer.getErrorString());
        updateBuilder.setJobId(answer.getJobId());
        updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
        updateBuilder.setInstallPath(answer.getInstallPath());
        updateBuilder.setSize(answer.getTemplateSize());
        updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
        _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
        // update size in volume table
        final VolumeVO volUpdater = volumeDao.createForUpdate();
        volUpdater.setSize(answer.getTemplateSize());
        volumeDao.update(obj.getId(), volUpdater);
    }
    final AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
    if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
        final CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(answer.getErrorString());
        caller.complete(result);
        final String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg);
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        final CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 24 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeDataStoreDaoImpl method updateState.

@Override
public boolean updateState(final State currentState, final Event event, final State nextState, final DataObjectInStore vo, final Object data) {
    final VolumeDataStoreVO dataObj = (VolumeDataStoreVO) vo;
    final Long oldUpdated = dataObj.getUpdatedCount();
    final Date oldUpdatedTime = dataObj.getUpdated();
    final SearchCriteria<VolumeDataStoreVO> sc = updateStateSearch.create();
    sc.setParameters("id", dataObj.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", dataObj.getUpdatedCount());
    dataObj.incrUpdatedCount();
    final UpdateBuilder builder = getUpdateBuilder(dataObj);
    builder.set(dataObj, "state", nextState);
    builder.set(dataObj, "updated", new Date());
    if (nextState == State.Destroyed) {
        builder.set(dataObj, "destroyed", true);
    }
    final int rows = update(dataObj, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        final VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
        if (dbVol != null) {
            final StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
            str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
            str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount()).append("; updatedTime=").append(dataObj.getUpdated());
            str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 25 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeDataStoreDaoImpl method findByStoreVolume.

@Override
public VolumeDataStoreVO findByStoreVolume(final long storeId, final long volumeId) {
    final SearchCriteria<VolumeDataStoreVO> sc = storeVolumeSearch.create();
    sc.setParameters("store_id", storeId);
    sc.setParameters("volume_id", volumeId);
    sc.setParameters("destroyed", false);
    /*
        When we download volume then we create entry in volume_store_ref table.
        We mark the volume entry to ready state once download_url gets generated.
        When we migrate that volume, then again one more entry is created with same volume id.
        Its state is marked as allocated. Later we try to list only one dataobject in datastore
        for state transition during volume migration. If the listed volume's state is allocated
        then migration passes otherwise it fails.

         Below fix will remove the randomness and give priority to volume entry which is made for
         migration (download_url/extracturl will be null in case of migration). Giving priority to
         download volume case is not needed as there will be only one entry in that case so no randomness.
        */
    final List<VolumeDataStoreVO> vos = listBy(sc);
    if (vos.size() > 1) {
        for (final VolumeDataStoreVO vo : vos) {
            if (vo.getExtractUrl() == null) {
                return vo;
            }
        }
    }
    return vos.size() == 1 ? vos.get(0) : null;
}
Also used : VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Aggregations

VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)32 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 VolumeVO (com.cloud.storage.VolumeVO)9 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)8 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 Date (java.util.Date)7 ExecutionException (java.util.concurrent.ExecutionException)6 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)5 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 VolumeApiResult (com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)3 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)3 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)3 DB (com.cloud.utils.db.DB)3