Search in sources :

Example 26 with TemplateDataStoreVO

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

the class BaseImageStoreDriverImpl method createTemplateAsyncCallback.

protected Void createTemplateAsyncCallback(final AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, final CreateContext<CreateCmdResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing image store createTemplate async callback");
    }
    final DownloadAnswer answer = callback.getResult();
    final DataObject obj = context.data;
    final DataStore store = obj.getDataStore();
    final TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
    if (tmpltStoreVO != null) {
        if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        final TemplateDataStoreVO updateBuilder = _templateStoreDao.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());
        _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
        // update size in vm_template table
        final VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
        tmlptUpdater.setSize(answer.getTemplateSize());
        _templateDao.update(obj.getId(), tmlptUpdater);
    }
    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 register template: " + obj.getUuid() + " with error: " + answer.getErrorString();
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        if (answer.getCheckSum() != null) {
            final VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate();
            templateDaoBuilder.setChecksum(answer.getCheckSum());
            _templateDao.update(obj.getId(), templateDaoBuilder);
        }
        final CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 27 with TemplateDataStoreVO

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

the class TemplateDataStoreDaoImpl method deletePrimaryRecordsForStore.

@Override
public void deletePrimaryRecordsForStore(final long id) {
    final SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
    sc.setParameters("store_id", id);
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 28 with TemplateDataStoreVO

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

the class TemplateDataStoreDaoImpl method updateState.

@Override
public boolean updateState(final State currentState, final Event event, final State nextState, final DataObjectInStore vo, final Object data) {
    final TemplateDataStoreVO dataObj = (TemplateDataStoreVO) vo;
    final Long oldUpdated = dataObj.getUpdatedCount();
    final Date oldUpdatedTime = dataObj.getUpdated();
    final SearchCriteria<TemplateDataStoreVO> 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 TemplateDataStoreVO 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 : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Example 29 with TemplateDataStoreVO

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

the class TemplateDataFactoryImpl method getTemplate.

@Override
public TemplateInfo getTemplate(final long templateId, final DataStore store) {
    final VMTemplateVO templ = imageDataDao.findById(templateId);
    if (store == null) {
        final TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
        return tmpl;
    }
    // verify if the given input parameters are consistent with our db data.
    boolean found = false;
    if (store.getRole() == DataStoreRole.Primary) {
        final VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId);
        if (templatePoolVO != null) {
            found = true;
        }
    } else {
        final TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(store.getId(), templateId);
        if (templateStoreVO != null) {
            found = true;
        }
    }
    if (s_logger.isDebugEnabled()) {
        if (!found) {
            s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
        } else {
            s_logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole());
        }
    }
    final TemplateObject tmpl = TemplateObject.getTemplate(templ, store);
    return tmpl;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 30 with TemplateDataStoreVO

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

the class TemplateDataFactoryImpl method getTemplate.

@Override
public TemplateInfo getTemplate(final long templateId, final DataStoreRole storeRole, final Long zoneId) {
    final TemplateDataStoreVO tmplStore = templateStoreDao.findByTemplateZone(templateId, zoneId, storeRole);
    DataStore store = null;
    if (tmplStore != null) {
        store = storeMgr.getDataStore(tmplStore.getDataStoreId(), storeRole);
    }
    return this.getTemplate(templateId, store);
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Aggregations

TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)39 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)17 VMTemplateVO (com.cloud.storage.VMTemplateVO)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)11 Date (java.util.Date)9 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)6 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)5 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 URISyntaxException (java.net.URISyntaxException)5 ExecutionException (java.util.concurrent.ExecutionException)5 ConfigurationException (javax.naming.ConfigurationException)5 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)3