Search in sources :

Example 1 with TransactionMethod

use of org.ovirt.engine.core.utils.transaction.TransactionMethod in project ovirt-engine by oVirt.

the class IsoDomainListSynchronizer method refreshIsoFileListMetaData.

private boolean refreshIsoFileListMetaData(final Guid repoStorageDomainId, final Map<String, Map<String, Object>> fileStats, final ImageFileType imageType) {
    Lock syncObject = getSyncObject(repoStorageDomainId, imageType);
    try {
        syncObject.lock();
        return (Boolean) TransactionSupport.executeInScope(TransactionScopeOption.RequiresNew, new TransactionMethod<Object>() {

            @Override
            public Object runInTransaction() {
                long currentTime = System.currentTimeMillis();
                repoFileMetaDataDao.removeRepoDomainFileList(repoStorageDomainId, imageType);
                for (Map.Entry<String, Map<String, Object>> entry : fileStats.entrySet()) {
                    repoFileMetaDataDao.addRepoFileMap(newRepoImage(currentTime, entry));
                }
                return true;
            }

            public RepoImage newRepoImage(long currentTime, Map.Entry<String, Map<String, Object>> entry) {
                RepoImage repo_md = new RepoImage();
                repo_md.setLastRefreshed(currentTime);
                repo_md.setSize(retrieveIsoFileSize(entry));
                repo_md.setRepoDomainId(repoStorageDomainId);
                repo_md.setDateCreated(null);
                repo_md.setRepoImageId(entry.getKey());
                repo_md.setRepoImageName(null);
                repo_md.setFileType(imageType);
                return repo_md;
            }
        });
    } catch (Exception e) {
        log.warn("Updating repository content to DB failed for repoStorageDomainId={}, imageType={}: {}", repoStorageDomainId, imageType, e.getMessage());
        log.debug("Exception", e);
        return false;
    } finally {
        syncObject.unlock();
    }
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) TransactionMethod(org.ovirt.engine.core.utils.transaction.TransactionMethod) EngineException(org.ovirt.engine.core.common.errors.EngineException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)1 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 TransactionMethod (org.ovirt.engine.core.utils.transaction.TransactionMethod)1