Search in sources :

Example 16 with DiskProfile

use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.

the class CommonVmPoolCommand method autoSelectTargetDomainAndVolumeFormat.

private HashMap<Guid, DiskImage> autoSelectTargetDomainAndVolumeFormat() {
    HashMap<Guid, DiskImage> destinationMap = new HashMap<>();
    for (Disk disk : templateDisks) {
        DiskImage diskImage = (DiskImage) disk;
        ArrayList<Guid> storageIds = new ArrayList<>();
        Guid storageId = findAvailableStorageDomain(disk.getSize(), diskToStorageIds.get(disk.getId()));
        storageIds.add(storageId);
        List<Guid> profileIds = diskToProfileMap.get(disk.getId());
        for (Guid profileId : profileIds) {
            DiskProfile profile = diskProfileDao.get(profileId);
            if (profile.getStorageDomainId().equals(storageId)) {
                diskImage.setDiskProfileId(profile.getId());
                break;
            }
        }
        // Set target domain
        diskImage.setStorageIds(storageIds);
        // validation
        if (diskImage.getDiskStorageType() == DiskStorageType.CINDER) {
            diskImage.setVolumeFormat(VolumeFormat.RAW);
        } else {
            diskImage.setVolumeFormat(VolumeFormat.COW);
        }
        destinationMap.put(disk.getId(), diskImage);
    }
    return destinationMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile)

Example 17 with DiskProfile

use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.

the class DiskProfileHelper method setAndValidateDiskProfiles.

public ValidationResult setAndValidateDiskProfiles(Map<DiskImage, Guid> map, DbUser user) {
    if (map == null) {
        return ValidationResult.VALID;
    }
    Map<Guid, List<DiskProfile>> storageDiskProfilesMap = new HashMap<>();
    // caching disk profile ids that was already checked.
    Set<Guid> permittedDiskProfilesIds = new HashSet<>();
    for (Entry<DiskImage, Guid> entry : map.entrySet()) {
        DiskImage diskImage = entry.getKey();
        Guid storageDomainId = entry.getValue();
        if (diskImage.getDiskStorageType() != DiskStorageType.IMAGE) {
            log.info("Disk profiles is not supported for storage type '{}' (Disk '{}')", diskImage.getDiskStorageType(), diskImage.getDiskAlias());
            continue;
        }
        if (diskImage.getDiskProfileId() == null && storageDomainId != null) {
            List<DiskProfile> diskProfilesList = storageDiskProfilesMap.get(storageDomainId);
            if (diskProfilesList == null) {
                diskProfilesList = diskProfileDao.getAllForStorageDomain(storageDomainId);
                storageDiskProfilesMap.put(storageDomainId, diskProfilesList);
            }
            // Set Disk Profile according to permissions
            if (!updateDiskProfileForBackwardCompatibility(diskImage, diskProfilesList, permittedDiskProfilesIds, user)) {
                return new ValidationResult(EngineMessage.USER_NOT_AUTHORIZED_TO_ATTACH_DISK_PROFILE);
            }
        } else {
            DiskProfile diskProfile = updateDiskImageProfilesList(diskImage, storageDomainId);
            if (diskProfile == null) {
                return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_NOT_FOUND_FOR_STORAGE_DOMAIN, String.format("$storageDomainId %s", storageDomainId));
            }
            ValidationResult result = isDiskProfileParentEntityValid(diskProfile, storageDomainId);
            if (result != ValidationResult.VALID) {
                return result;
            }
            if (!isDiskProfilePermitted(diskProfile, permittedDiskProfilesIds, user)) {
                return new ValidationResult(EngineMessage.USER_NOT_AUTHORIZED_TO_ATTACH_DISK_PROFILE);
            }
        }
    }
    return ValidationResult.VALID;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile) HashSet(java.util.HashSet)

Example 18 with DiskProfile

use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.

the class DiskProfileValidator method isParentEntityValid.

public ValidationResult isParentEntityValid(Guid storageDomainId) {
    if (storageDomainId == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED);
    }
    Guid id = getProfile().getId();
    if (id == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_EMPTY);
    }
    DiskProfile fetchedDiskProfile = getProfileDao().get(id);
    if (fetchedDiskProfile == null) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND);
    }
    if (!storageDomainId.equals(fetchedDiskProfile.getStorageDomainId())) {
        String diskProfileName = fetchedDiskProfile.getName();
        StorageDomain targetStorageDomain = getStorageDomain(storageDomainId);
        String targetStorageDomainName = targetStorageDomain != null ? getStorageDomain(storageDomainId).getName() : "Unknown";
        return new ValidationResult(EngineMessage.ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN, String.format("$diskProfile %s", diskProfileName), String.format("$diskProfileId %s", fetchedDiskProfile.getId().toString()), String.format("$storageDomain %s", targetStorageDomainName));
    }
    return ValidationResult.VALID;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile)

Example 19 with DiskProfile

use of org.ovirt.engine.core.common.businessentities.profiles.DiskProfile in project ovirt-engine by oVirt.

the class DiskProfilesListModelTable method initTable.

@Override
public void initTable() {
    getTable().enableColumnResizing();
    AbstractTextColumn<DiskProfile> nameColumn = new AbstractTextColumn<DiskProfile>() {

        @Override
        public String getValue(DiskProfile object) {
            return object.getName();
        }
    };
    // $NON-NLS-1$
    getTable().addColumn(nameColumn, constants.profileNameLabel(), "200px");
    nameColumn.makeSortable();
    AbstractTextColumn<DiskProfile> descriptionColumn = new AbstractTextColumn<DiskProfile>() {

        @Override
        public String getValue(DiskProfile object) {
            return object.getDescription();
        }
    };
    // $NON-NLS-1$
    getTable().addColumn(descriptionColumn, constants.profileDescriptionLabel(), "200px");
    descriptionColumn.makeSortable();
    AbstractTextColumn<DiskProfile> qosColumn = new AbstractTextColumn<DiskProfile>() {

        @Override
        public String getValue(DiskProfile object) {
            String name = constants.unlimitedQos();
            if (object.getQosId() != null) {
                StorageQos storageQos = getModel().getQos(object.getQosId());
                if (storageQos != null) {
                    name = storageQos.getName();
                }
            }
            return name;
        }
    };
    // $NON-NLS-1$
    getTable().addColumn(qosColumn, constants.qosName(), "200px");
    qosColumn.makeSortable();
    // Add selection listener
    getModel().getSelectedItemChangedEvent().addListener((ev, sender, args) -> updatePermissionPanel());
    getModel().getItemsChangedEvent().addListener((ev, sender, args) -> updatePermissionPanel());
}
Also used : StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) AbstractTextColumn(org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn) DiskProfile(org.ovirt.engine.core.common.businessentities.profiles.DiskProfile)

Aggregations

DiskProfile (org.ovirt.engine.core.common.businessentities.profiles.DiskProfile)19 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)7 Guid (org.ovirt.engine.core.compat.Guid)7 ArrayList (java.util.ArrayList)5 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)5 HashMap (java.util.HashMap)3 List (java.util.List)3 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)3 DiskModel (org.ovirt.engine.ui.uicommonweb.models.vms.DiskModel)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)2 StorageQos (org.ovirt.engine.core.common.businessentities.qos.StorageQos)2 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1