use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method syncTemplateToRegionStore.
// This routine is used to push templates currently on cache store, but not in region store to region store.
// used in migrating existing NFS secondary storage to S3.
@Override
public void syncTemplateToRegionStore(final long templateId, final DataStore store) {
if (_storeMgr.isRegionStore(store)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sync template " + templateId + " from cache to object store...");
}
// if template is on region wide object store, check if it is really downloaded there (by checking install_path). Sync template to region
// wide store if it is not there physically.
final TemplateInfo tmplOnStore = _templateFactory.getTemplate(templateId, store);
if (tmplOnStore == null) {
throw new CloudRuntimeException("Cannot find an entry in template_store_ref for template " + templateId + " on region store: " + store.getName());
}
if (tmplOnStore.getInstallPath() == null || tmplOnStore.getInstallPath().length() == 0) {
// template is not on region store yet, sync to region store
final TemplateInfo srcTemplate = _templateFactory.getReadyTemplateOnCache(templateId);
if (srcTemplate == null) {
throw new CloudRuntimeException("Cannot find template " + templateId + " on cache store");
}
final AsyncCallFuture<TemplateApiResult> future = syncToRegionStoreAsync(srcTemplate, store);
try {
final TemplateApiResult result = future.get();
if (result.isFailed()) {
throw new CloudRuntimeException("sync template from cache to region wide store failed for image store " + store.getName() + ":" + result.getResult());
}
// reduce reference count for template on cache, so it can recycled by schedule
_cacheMgr.releaseCacheObject(srcTemplate);
} catch (final Exception ex) {
throw new CloudRuntimeException("sync template from cache to region wide store failed for image store " + store.getName());
}
}
}
}
use of com.cloud.engine.subsystem.api.storage.TemplateInfo 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;
}
use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.
the class DefaultEndPointSelector method select.
@Override
public EndPoint select(final DataObject object) {
final DataStore store = object.getDataStore();
final EndPoint ep = select(store);
if (ep != null) {
return ep;
}
if (object instanceof TemplateInfo) {
final TemplateInfo tmplInfo = (TemplateInfo) object;
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) {
// for bootstrap system vm template downloading to region image store
return LocalHostEndpoint.getEndpoint();
}
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromTemplateAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(final VolumeInfo volume, final long dataStoreId, final TemplateInfo template) {
final PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
final TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId());
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
if (templateOnPrimaryStore == null) {
createBaseImageAsync(volume, pd, template, future);
return future;
}
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
return future;
}
use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method waitForTemplateDownloaded.
private TemplateInfo waitForTemplateDownloaded(final PrimaryDataStore store, final TemplateInfo template) {
final int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
final int sleepTime = 120;
int tries = storagePoolMaxWaitSeconds / sleepTime;
while (tries > 0) {
final TemplateInfo tmpl = store.getTemplate(template.getId());
if (tmpl != null) {
return tmpl;
}
try {
Thread.sleep(sleepTime * 1000);
} catch (final InterruptedException e) {
s_logger.debug("waiting for template download been interrupted: " + e.toString());
}
tries--;
}
return null;
}
Aggregations