Search in sources :

Example 26 with RepoImage

use of org.ovirt.engine.core.common.businessentities.storage.RepoImage in project ovirt-engine by oVirt.

the class IsoDomainListSynchronizer method refreshIsoDomain.

/**
 * The procedure Try to refresh the repository files of the storage domain id, By iterate over the storage pools of
 * this domain, and try to choose a valid storage pool, to fetch the repository files from the VDSM, and refresh the
 * cached table. <BR/>
 * If succeeded, will return True. Otherwise return false with updated list of problematic repository files with the
 * storage pool, storage domain, and file type, that could not complete the cache update transaction.
 *
 * @param storageDomainId
 *            - The Repository domain Id, we want to refresh.
 * @param problematicRepoFileList
 *            - List of business entities, each one indicating the problematic entity.
 * @param imageType
 *            - The imageType we want to fetch the files from the cache.
 * @return Boolean value indicating if the refresh succeeded or not.
 */
private boolean refreshIsoDomain(Guid storageDomainId, List<RepoImage> problematicRepoFileList, ImageFileType imageType) {
    List<StoragePoolIsoMap> isoMapList = fetchAllStoragePoolsForIsoDomain(storageDomainId, imageType);
    for (StoragePoolIsoMap storagePoolIsoMap : isoMapList) {
        Guid storagePoolId = storagePoolIsoMap.getStoragePoolId();
        StorageDomainStatus status = storagePoolIsoMap.getStatus();
        if (StorageDomainStatus.Active != status) {
            handleInactiveStorageDomain(storageDomainId, imageType, status);
        } else {
            // Try to refresh the domain of the storage pool id because its status is active.
            boolean refreshOk = refreshIsoDomainFileForStoragePool(storageDomainId, storagePoolId, imageType);
            if (!refreshOk) {
                log.debug("Failed refreshing Storage domain id '{}', for '{}' file type in storage pool id '{}'.", storageDomainId, imageType, storagePoolId);
                // Add the repository file to the list of problematic Iso domains.
                RepoImage repoImage = createMockRepositoryFileMetaData(storageDomainId, imageType, storagePoolId);
                problematicRepoFileList.add(repoImage);
                return false;
            }
        }
    }
    return true;
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) Guid(org.ovirt.engine.core.compat.Guid) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus)

Example 27 with RepoImage

use of org.ovirt.engine.core.common.businessentities.storage.RepoImage in project ovirt-engine by oVirt.

the class IsoDomainListSynchronizer method createMockRepositoryFileMetaData.

// set a mock repository file meta data with storage domain id and storage pool id.
private static RepoImage createMockRepositoryFileMetaData(Guid storageDomainId, ImageFileType imageType, Guid storagePoolId) {
    RepoImage repoImage = new RepoImage();
    repoImage.setStoragePoolId(storagePoolId);
    repoImage.setRepoDomainId(storageDomainId);
    repoImage.setFileType(imageType);
    return repoImage;
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage)

Example 28 with RepoImage

use of org.ovirt.engine.core.common.businessentities.storage.RepoImage 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)

Example 29 with RepoImage

use of org.ovirt.engine.core.common.businessentities.storage.RepoImage in project ovirt-engine by oVirt.

the class BackendFilesResourceTest method setUpFiles.

private List<RepoImage> setUpFiles() {
    List<RepoImage> isos = new ArrayList<>();
    for (int i = 0; i < NAMES.length; i++) {
        RepoImage file = new RepoImage();
        file.setRepoImageId(NAMES[i]);
        isos.add(file);
    }
    return isos;
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) ArrayList(java.util.ArrayList)

Example 30 with RepoImage

use of org.ovirt.engine.core.common.businessentities.storage.RepoImage in project ovirt-engine by oVirt.

the class ImportRepoImageModel method executeCommand.

@Override
public void executeCommand(UICommand command) {
    if (!validate()) {
        return;
    }
    super.executeCommand(command);
    startProgress();
    ArrayList<ActionParametersBase> actionParameters = new ArrayList<>();
    final StringBuilder imageNames = new StringBuilder();
    for (EntityModel entity : getEntities()) {
        RepoImage repoImage = (RepoImage) entity.getEntity();
        // $NON-NLS-1$
        imageNames.append("\n -");
        imageNames.append(repoImage.getRepoImageName());
        ImportRepoImageParameters importParameters = new ImportRepoImageParameters();
        // source
        importParameters.setSourceRepoImageId(repoImage.getRepoImageId());
        importParameters.setSourceStorageDomainId(sourceStorageDomain.getId());
        // destination
        importParameters.setDiskAlias(((RepoImageModel) entity).getDiskImageAlias());
        importParameters.setStoragePoolId(getDataCenter().getSelectedItem().getId());
        importParameters.setStorageDomainId(getStorageDomain().getSelectedItem().getId());
        importParameters.setClusterId(getStorageDomain().getSelectedItem().getId());
        Quota selectedQuota = getQuota().getSelectedItem();
        if (selectedQuota != null) {
            importParameters.setQuotaId(selectedQuota.getId());
        }
        Boolean importAsTemplate = getImportAsTemplate().getEntity();
        importParameters.setImportAsTemplate(importAsTemplate);
        if (importAsTemplate) {
            importParameters.setClusterId(getCluster().getSelectedItem().getId());
            String templateName = getTemplateName().getEntity();
            if (StringHelper.isNotNullOrEmpty(templateName)) {
                importParameters.setTemplateName(templateName);
            }
        }
        actionParameters.add(importParameters);
    }
    Frontend.getInstance().runMultipleAction(ActionType.ImportRepoImage, actionParameters, result -> {
        ImportExportRepoImageBaseModel model = (ImportExportRepoImageBaseModel) result.getState();
        model.stopProgress();
        model.cancel();
        ConfirmationModel confirmModel = new ConfirmationModel();
        storageIsoListModel.setConfirmWindow(confirmModel);
        confirmModel.setTitle(ConstantsManager.getInstance().getConstants().importImagesTitle());
        confirmModel.setHelpTag(HelpTag.import_images);
        // $NON-NLS-1$
        confirmModel.setHashName("import_images");
        confirmModel.setMessage(ConstantsManager.getInstance().getMessages().importProcessHasBegunForImages(imageNames.toString()));
        confirmModel.getCommands().add(// $NON-NLS-1$
        new UICommand("CancelConfirm", storageIsoListModel).setTitle(ConstantsManager.getInstance().getConstants().close()).setIsDefault(true).setIsCancel(true));
    }, this);
}
Also used : ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ImportRepoImageParameters(org.ovirt.engine.core.common.action.ImportRepoImageParameters) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Quota(org.ovirt.engine.core.common.businessentities.Quota) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Aggregations

RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)41 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)5 Guid (org.ovirt.engine.core.compat.Guid)5 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)4 InstanceType (org.ovirt.engine.core.common.businessentities.InstanceType)3 Quota (org.ovirt.engine.core.common.businessentities.Quota)3 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 NullSafeRenderer (org.ovirt.engine.ui.common.widget.renderer.NullSafeRenderer)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)2 ListModelTypeAheadChangeableListBoxEditor (org.ovirt.engine.ui.common.widget.editor.ListModelTypeAheadChangeableListBoxEditor)2 VncKeyMapRenderer (org.ovirt.engine.ui.common.widget.editor.VncKeyMapRenderer)2 EntityModelCheckBoxEditor (org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor)2