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;
}
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();
}
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;
}
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;
}
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);
}
Aggregations