Search in sources :

Example 6 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<TemplateApiResult> syncToRegionStoreAsync(final TemplateInfo template, final DataStore store) {
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    // no need to create entry on template_store_ref here, since entries are already created when prepareSecondaryStorageForMigration is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    final TemplateInfo templateOnStore = _templateFactory.getTemplate(template, store);
    final String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + template.getAccountId() + "/" + template.getId() + "/" + template.getUniqueName();
    ((TemplateObject) templateOnStore).setInstallPath(installPath);
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(template, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 7 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method copyAsync.

@Override
public Void copyAsync(final DataObject srcData, final DataObject destData, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
    if (srcData instanceof SnapshotInfo) {
        final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
        validate(snapshotInfo);
        final boolean canHandleSrc = canHandle(srcData.getDataStore());
        if (canHandleSrc && destData instanceof TemplateInfo && (destData.getDataStore().getRole() == DataStoreRole.Image || destData.getDataStore().getRole() == DataStoreRole.ImageCache)) {
            return handleCreateTemplateFromSnapshot(snapshotInfo, (TemplateInfo) destData, callback);
        }
        if (destData instanceof VolumeInfo) {
            final VolumeInfo volumeInfo = (VolumeInfo) destData;
            final boolean canHandleDest = canHandle(destData.getDataStore());
            if (canHandleSrc && canHandleDest) {
                return handleCreateVolumeFromSnapshotBothOnStorageSystem(snapshotInfo, volumeInfo, callback);
            }
            if (canHandleSrc) {
                throw new UnsupportedOperationException("This operation is not supported (DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT " + "not supported by destination storage plug-in).");
            }
            if (canHandleDest) {
                throw new UnsupportedOperationException("This operation is not supported (DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT " + "not supported by source storage plug-in).");
            }
        }
    }
    throw new UnsupportedOperationException("This operation is not supported.");
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo)

Example 8 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method needCacheStorage.

protected boolean needCacheStorage(final DataObject srcData, final DataObject destData) {
    final DataTO srcTO = srcData.getTO();
    final DataStoreTO srcStoreTO = srcTO.getDataStore();
    if (srcStoreTO instanceof NfsTO || srcStoreTO.getRole() == DataStoreRole.ImageCache) {
        // (srcStoreTO instanceof PrimaryDataStoreTO && ((PrimaryDataStoreTO)srcStoreTO).getPoolType() == StoragePoolType.NetworkFilesystem)) {
        return false;
    }
    final DataTO destTO = destData.getTO();
    final DataStoreTO destStoreTO = destTO.getDataStore();
    if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) {
        return false;
    }
    if (srcData.getType() == DataObjectType.TEMPLATE) {
        final TemplateInfo template = (TemplateInfo) srcData;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString());
    }
    return true;
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataTO(com.cloud.agent.api.to.DataTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 9 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo 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;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 10 with TemplateInfo

use of com.cloud.engine.subsystem.api.storage.TemplateInfo 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);
            }
        }
    }
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) HashSet(java.util.HashSet)

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