use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateDataStoreDaoImpl method findByTemplateZoneReady.
@Override
public TemplateDataStoreVO findByTemplateZoneReady(final long templateId, final Long zoneId) {
List<DataStore> imgStores = null;
imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
if (imgStores != null) {
Collections.shuffle(imgStores);
for (final DataStore store : imgStores) {
final List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
if (sRes != null && sRes.size() > 0) {
return sRes.get(0);
}
}
}
return null;
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class StorageCacheReplacementAlgorithmLRU method chooseOneToBeReplaced.
@Override
public DataObject chooseOneToBeReplaced(final DataStore store) {
if (unusedTimeInterval == null) {
unusedTimeInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementLRUTimeInterval.key()), 30);
}
final Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.now());
cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue());
final Date bef = cal.getTime();
final QueryBuilder<TemplateDataStoreVO> sc = QueryBuilder.create(TemplateDataStoreVO.class);
sc.and(sc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
sc.and(sc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
sc.and(sc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
sc.and(sc.entity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole());
sc.and(sc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
final TemplateDataStoreVO template = sc.find();
if (template != null) {
return templateFactory.getTemplate(template.getTemplateId(), store);
}
final QueryBuilder<VolumeDataStoreVO> volSc = QueryBuilder.create(VolumeDataStoreVO.class);
volSc.and(volSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
volSc.and(volSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
volSc.and(volSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
volSc.and(volSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
final VolumeDataStoreVO volume = volSc.find();
if (volume != null) {
return volumeFactory.getVolume(volume.getVolumeId(), store);
}
final QueryBuilder<SnapshotDataStoreVO> snapshotSc = QueryBuilder.create(SnapshotDataStoreVO.class);
snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ, store.getRole());
snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
final SnapshotDataStoreVO snapshot = snapshotSc.find();
if (snapshot != null) {
return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
}
return null;
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateDataFactoryImpl method listTemplateOnCache.
@Override
public List<TemplateInfo> listTemplateOnCache(final long templateId) {
final List<TemplateDataStoreVO> cacheTmpls = templateStoreDao.listOnCache(templateId);
final List<TemplateInfo> tmplObjs = new ArrayList<>();
for (final TemplateDataStoreVO cacheTmpl : cacheTmpls) {
final long storeId = cacheTmpl.getDataStoreId();
final DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
final TemplateInfo tmplObj = getTemplate(templateId, store);
tmplObjs.add(tmplObj);
}
return tmplObjs;
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method handleSysTemplateDownload.
@Override
public void handleSysTemplateDownload(final HypervisorType hostHyper, final Long dcId) {
final Set<VMTemplateVO> toBeDownloaded = new HashSet<>();
final List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(dcId));
if (stores == null || stores.isEmpty()) {
return;
}
/* Download all the templates in zone with the same hypervisortype */
for (final DataStore store : stores) {
final List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
final List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
for (final VMTemplateVO rtngTmplt : rtngTmplts) {
if (rtngTmplt.getHypervisorType() == hostHyper) {
toBeDownloaded.add(rtngTmplt);
}
}
for (final VMTemplateVO builtinTmplt : defaultBuiltin) {
if (builtinTmplt.getHypervisorType() == hostHyper) {
toBeDownloaded.add(builtinTmplt);
}
}
for (final VMTemplateVO template : toBeDownloaded) {
final TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
associateTemplateToZone(template.getId(), dcId);
s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
final TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
createTemplateAsync(tmplt, store, null);
}
}
}
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method copyTemplate.
@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(final TemplateInfo srcTemplate, final DataStore destStore) {
// generate a URL from source template ssvm to download to destination data store
final String url = generateCopyUrl(srcTemplate);
if (url == null) {
s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
}
final TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting source template url to " + url);
}
tmplForCopy.setUrl(url);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Mark template_store_ref entry as Creating");
}
final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
final DataObject templateOnStore = destStore.create(tmplForCopy);
templateOnStore.processEvent(Event.CreateOnlyRequested);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
}
try {
final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
destStore.getDriver().createAsync(destStore, templateOnStore, caller);
} catch (final CloudRuntimeException ex) {
// clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
final TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
if (templateStoreVO != null) {
final TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
res.setResult(ex.getMessage());
future.complete(res);
}
return future;
}
Aggregations