TemplateDataStoreVO templateStoreRef = null; templateStoragePoolRef = _tmpltPoolDao.findByPoolTemplate(poolId, templateId); if (templateStoragePoolRef != null) { templateStoragePoolRef.setMarkedForGC(false); _tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef); return _tmpltPoolDao.findByPoolTemplate(poolId, templateId); } catch (Exception ex) { s_logger.debug("failed to copy template from image store:" + srcSecStore.getName() + " to primary storage");
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolVO.getId()); } else { if (_tmpltPoolDao.remove(templatePoolVO.getId())) { s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName()); if (_tmpltPoolDao.remove(templatePoolVO.getId())) { s_logger.debug("Successfully evicted template " + template.getName() + " from storage pool " + pool.getName()); s_logger.info("Storage is unavailable currently. Will retry evicte template " + template.getName() + " from storage pool " + pool.getName()); } finally { _tmpltPoolDao.releaseFromLockTable(templatePoolRef.getId());
List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = _tmpltPoolDao.listByPoolId(storagePoolId); _tmpltPoolDao.remove(templatePoolRef.getId());
@Override @DB public boolean resetTemplateDownloadStateOnPool(long templateStoragePoolRefId) { // have to use the same lock that prepareTemplateForCreate use to // maintain state consistency VMTemplateStoragePoolVO templateStoragePoolRef = _tmpltPoolDao.acquireInLockTable(templateStoragePoolRefId, 1200); if (templateStoragePoolRef == null) { s_logger.warn("resetTemplateDownloadStateOnPool failed - unable to lock TemplateStorgePoolRef " + templateStoragePoolRefId); return false; } try { templateStoragePoolRef.setTemplateSize(0); templateStoragePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED); _tmpltPoolDao.update(templateStoragePoolRefId, templateStoragePoolRef); } finally { _tmpltPoolDao.releaseFromLockTable(templateStoragePoolRefId); } return true; }
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(); templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200); try { if (templatePoolRef == null) { templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated); _tmpltPoolDao.update(templatePoolRefId, templatePoolRef); _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
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.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); 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( s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
@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); }
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()); } else { s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId()); if (templateStoragePoolRef == null) { templateStoragePoolRef = templatePoolDao.persist(templateStoragePoolRef); 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");
@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); }
long templatePoolRefId = templatePoolRef.getId(); templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
_vmTemplatePoolDao.update(templatePoolVO.getId(), templatePoolVO); s_logger.debug("Storage pool garbage collector has marked template with ID: " + templatePoolVO.getTemplateId() + " on pool " + templatePoolVO.getPoolId() + " for garbage collection.");
/** * This method is only relevant when storagePool is being used with a compute cluster that supports UUID resigning. */ @Override public long getBytesRequiredForTemplate(TemplateInfo templateInfo, StoragePool storagePool) { List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = tmpltPoolDao.listByPoolId(storagePool.getId()); if (lstTemplatePoolRefs != null) { for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) { if (templatePoolRef.getTemplateId() == templateInfo.getId()) { // This indicates that we already have this template stored on this primary storage, so // we do not require additional space. return 0; } } } // This indicates that we do not have a copy of this template on this primary storage, so // we need to take it into consideration from a space standpoint (ex. when a new VM is spun // up and wants to use this particular template for its root disk). return getDataObjectSizeIncludingHypervisorSnapshotReserve(templateInfo, storagePool); }
if (obj.getType() == DataObjectType.TEMPLATE) { VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId()); vo = templatePoolDao.persist(vo); } else if (obj.getType() == DataObjectType.SNAPSHOT) { SnapshotInfo snapshotInfo = (SnapshotInfo)obj;
TemplateInfo templateOnPrimary = (TemplateInfo)destPrimaryDataStore.create(srcTemplateInfo); VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(destPrimaryDataStore.getId(), templateOnPrimary.getId()); long templatePoolRefId = templatePoolRef.getId(); templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); _tmpltPoolDao.releaseFromLockTable(templatePoolRefId); _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
@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; }
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()); } else { s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
VMTemplateStoragePoolVO sPoolRef = vmTemplatePoolDao.findByPoolTemplate(poolId, templateId); if (sPoolRef == null) { if (s_logger.isDebugEnabled()) { sPoolRef.setLocalDownloadPath(ans.getInstallPath()); sPoolRef.setInstallPath(ans.getInstallPath()); vmTemplatePoolDao.persist(sPoolRef);
@Override public List<VMTemplateStoragePoolVO> getUnusedTemplatesInPool(StoragePoolVO pool) { List<VMTemplateStoragePoolVO> unusedTemplatesInPool = new ArrayList<VMTemplateStoragePoolVO>(); List<VMTemplateStoragePoolVO> allTemplatesInPool = _tmpltPoolDao.listByPoolId(pool.getId()); for (VMTemplateStoragePoolVO templatePoolVO : allTemplatesInPool) { VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templatePoolVO.getTemplateId()); // If this is a routing template, consider it in use if (template.getTemplateType() == TemplateType.SYSTEM) { continue; } // If the template is not yet downloaded to the pool, consider it in // use if (templatePoolVO.getDownloadState() != Status.DOWNLOADED) { continue; } if (template.getFormat() != ImageFormat.ISO && !_volumeDao.isAnyVolumeActivelyUsingTemplateOnPool(template.getId(), pool.getId())) { unusedTemplatesInPool.add(templatePoolVO); } } return unusedTemplatesInPool; }
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; }