Search in sources :

Example 11 with TemplateInfo

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());
            }
        }
    }
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 12 with TemplateInfo

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;
}
Also used : CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 13 with TemplateInfo

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;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Example 14 with TemplateInfo

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;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Example 15 with TemplateInfo

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;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint)

Aggregations

TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)11 VMTemplateVO (com.cloud.storage.VMTemplateVO)10 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)7 ExecutionException (java.util.concurrent.ExecutionException)7 DB (com.cloud.utils.db.DB)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)5 HashSet (java.util.HashSet)5 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)4 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)4 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3