@Override public TemplateInfo getTemplate(long templateId) { VMTemplateStoragePoolVO template = templatePoolDao.findByPoolTemplate(getId(), templateId); if (template == null || template.getState() != ObjectInDataStoreStateMachine.State.Ready) { return null; } return imageDataFactory.getTemplate(templateId, this); }
@Override public DataObjectInStore findObject(long objId, DataObjectType type, long dataStoreId, DataStoreRole role) { DataObjectInStore vo = null; if (role == DataStoreRole.Image || role == DataStoreRole.ImageCache) { switch (type) { case TEMPLATE: vo = templateDataStoreDao.findByStoreTemplate(dataStoreId, objId); break; case SNAPSHOT: vo = snapshotDataStoreDao.findByStoreSnapshot(role, dataStoreId, objId); break; case VOLUME: vo = volumeDataStoreDao.findByStoreVolume(dataStoreId, objId); break; } } else if (type == DataObjectType.TEMPLATE && role == DataStoreRole.Primary) { vo = templatePoolDao.findByPoolTemplate(dataStoreId, objId); } else if (type == DataObjectType.SNAPSHOT && role == DataStoreRole.Primary) { vo = snapshotDataStoreDao.findByStoreSnapshot(role, dataStoreId, objId); } else { s_logger.debug("Invalid data or store type: " + type + " " + role); throw new CloudRuntimeException("Invalid data or store type: " + type + " " + role); } return vo; }
@Override public TemplateInfo getTemplate(long templateId, DataStore store) { VMTemplateVO templ = imageDataDao.findById(templateId); if (store == null) { 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) { VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId); if (templatePoolVO != null) { found = true; } } else { 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()); } } TemplateObject tmpl = TemplateObject.getTemplate(templ, store); return tmpl; }
TemplateDataStoreVO templateStoreRef = null; templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId); if (templateStoragePoolRef != null) { templateStoragePoolRef.setMarkedForGC(false); return _tmpltPoolDao.findByPoolTemplate(poolId, templateId); } catch (Exception ex) { s_logger.debug("failed to copy template from image store:" + srcSecStore.getName() + " to primary storage");
DataObject templateOnPrimaryStoreObj = dataStore.create(template); VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId()); if (templatePoolRef == null) { throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId()); s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId()); if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { s_logger.info(
templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId()); if (templateStoragePoolRef == null) { s_logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t); templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId()); if (templateStoragePoolRef == null) { throw new CloudRuntimeException("Failed to create template storage pool entry");
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId());
private SolidFireUtil.SolidFireVolume createClone(SolidFireUtil.SolidFireConnection sfConnection, long dataObjectId, VolumeInfo volumeInfo, long sfAccountId, long storagePoolId, DataObjectType dataObjectType) { String sfNewVolumeName = volumeInfo.getName(); long sfVolumeId = Long.MIN_VALUE; long sfSnapshotId = Long.MIN_VALUE; if (dataObjectType == DataObjectType.SNAPSHOT) { SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.SNAPSHOT_ID); if (snapshotDetails != null && snapshotDetails.getValue() != null) { sfSnapshotId = Long.parseLong(snapshotDetails.getValue()); } snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, SolidFireUtil.VOLUME_ID); sfVolumeId = Long.parseLong(snapshotDetails.getValue()); } else if (dataObjectType == DataObjectType.TEMPLATE) { // get the cached template on this storage VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId); if (templatePoolRef != null) { sfVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath()); } } if (sfVolumeId <= 0) { throw new CloudRuntimeException("Unable to find SolidFire volume for the following data-object ID: " + dataObjectId + " and data-object type: " + dataObjectType); } final long newSfVolumeId = SolidFireUtil.createClone(sfConnection, sfVolumeId, sfSnapshotId, sfAccountId, SolidFireUtil.getSolidFireVolumeName(sfNewVolumeName), getVolumeAttributes(volumeInfo)); final Iops iops = getIops(volumeInfo.getMinIops(), volumeInfo.getMaxIops(), storagePoolId); SolidFireUtil.modifyVolume(sfConnection, newSfVolumeId, null, null, iops.getMinIops(), iops.getMaxIops(), iops.getBurstIops()); return SolidFireUtil.getVolume(sfConnection, newSfVolumeId); }
if (dataStore.getRole() == DataStoreRole.Primary) { if (dataObj.getType() == DataObjectType.TEMPLATE) { VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId); if (destTmpltPool != null) { return templatePoolDao.remove(destTmpltPool.getId());
/** * Clones the template volume on managed storage to the ROOT volume * * @param volumeInfo ROOT volume to create * @param templateOnPrimary Template from which to clone the ROOT volume * @param destPrimaryDataStore Primary storage of the volume * @param future For async */ private void createManagedVolumeCloneTemplateAsync(VolumeInfo volumeInfo, TemplateInfo templateOnPrimary, PrimaryDataStore destPrimaryDataStore, AsyncCallFuture<VolumeApiResult> future) { VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId()); if (templatePoolRef == null) { throw new CloudRuntimeException("Failed to find template " + templateOnPrimary.getUniqueName() + " in storage pool " + destPrimaryDataStore.getId()); } //XXX: not sure if this the right thing to do here. We can always fallback to the "copy from sec storage" if (templatePoolRef.getDownloadState() == Status.NOT_DOWNLOADED) { throw new CloudRuntimeException("Template " + templateOnPrimary.getUniqueName() + " has not been downloaded to primary storage."); } try { volumeInfo.processEvent(Event.CreateOnlyRequested); CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, templateOnPrimary, future, null); AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null)); caller.setContext(context); motionSrv.copyAsync(templateOnPrimary, volumeInfo, caller); } catch (Throwable e) { s_logger.debug("Failed to clone template on primary storage", e); volumeInfo.processEvent(Event.OperationFailed); throw new CloudRuntimeException(e.getMessage()); } }
@Override public TemplateInfo getReadyBypassedTemplateOnPrimaryStore(long templateId, Long poolId, Long hostId) { VMTemplateVO templateVO = imageDataDao.findById(templateId); if (templateVO == null || !templateVO.isDirectDownload()) { return null; } Long pool = poolId; if (poolId == null) { //Get ISO from existing pool ref HostVO host = hostDao.findById(hostId); List<StoragePoolVO> pools = getStoragePoolsFromClusterOrZone(host.getClusterId(), host.getDataCenterId(), host.getHypervisorType()); List<VMTemplateStoragePoolVO> existingRefs = templatePoolDao.listByTemplateId(templateId); pool = getOneMatchingPoolIdFromRefs(existingRefs, pools); } if (pool == null) { throw new CloudRuntimeException("No storage pool found where to download template: " + templateId); } VMTemplateStoragePoolVO spoolRef = templatePoolDao.findByPoolTemplate(pool, templateId); if (spoolRef == null) { directDownloadManager.downloadTemplate(templateId, pool, hostId); } DataStore store = storeMgr.getDataStore(pool, DataStoreRole.Primary); return this.getTemplate(templateId, store); }
private String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId) { verifySufficientBytesForStoragePool(templateInfo, storagePoolId); SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); long sfAccountId = getCreateSolidFireAccountId(sfConnection, templateInfo.getAccountId(), storagePoolId); SolidFireUtil.SolidFireVolume sfVolume = createSolidFireVolume(sfConnection, templateInfo, storagePoolId, sfAccountId); String iqn = sfVolume.getIqn(); VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, templateInfo.getId()); templatePoolRef.setInstallPath(iqn); templatePoolRef.setLocalDownloadPath(Long.toString(sfVolume.getId())); templatePoolRef.setTemplateSize(sfVolume.getTotalSize()); tmpltPoolDao.update(templatePoolRef.getId(), templatePoolRef); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); long capacityBytes = storagePool.getCapacityBytes(); // getUsedBytes(StoragePool) will include the bytes of the newly created template volume because // _tmpltPoolDao.update(Long, VMTemplateStoragePoolVO) has already been invoked long usedBytes = getUsedBytes(storagePool); storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes); storagePoolDao.update(storagePoolId, storagePool); return iqn; }
if (tmplOnPrimary != null) { s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try"); VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId()); if (templatePoolRef != null) { long templatePoolRefId = templatePoolRef.getId();
if (dataStore.getRole() == DataStoreRole.Primary) { if (dataObj.getType() == DataObjectType.TEMPLATE) { VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId); if (destTmpltPool != null && destTmpltPool.getState() != ObjectInDataStoreStateMachine.State.Ready) { return templatePoolDao.remove(destTmpltPool.getId());
VMTemplateStoragePoolVO sPoolRef = vmTemplatePoolDao.findByPoolTemplate(poolId, templateId); if (sPoolRef == null) { if (s_logger.isDebugEnabled()) {
TemplateInfo templateOnPrimary = (TemplateInfo)destPrimaryDataStore.create(srcTemplateInfo); VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId());
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData(); VMTemplateStoragePoolVO templatePoolRef = templatePoolDao.findByPoolTemplate(getDataStore().getId(), getId()); templatePoolRef.setDownloadPercent(100);