Search in sources :

Example 1 with GetImagesListVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters in project ovirt-engine by oVirt.

the class DiskImagesValidator method diskImagesOnStorage.

/**
 * checks that the given disks do not exist on the target storage domains
 * @param imageToDestinationDomainMap map containing the destination domain for each of the disks
 * @param storagePoolId the storage pool ID to check whether the disks are residing on
 * @return validation result indicating whether the disks don't exist on the target storage domains
 */
public ValidationResult diskImagesOnStorage(Map<Guid, Guid> imageToDestinationDomainMap, Guid storagePoolId) {
    Map<Guid, List<Guid>> domainImages = new HashMap<>();
    for (DiskImage diskImage : diskImages) {
        Guid targetStorageDomainId = imageToDestinationDomainMap.get(diskImage.getId());
        List<Guid> imagesOnStorageDomain = domainImages.get(targetStorageDomainId);
        if (imagesOnStorageDomain == null) {
            VDSReturnValue returnValue = Backend.getInstance().getResourceManager().runVdsCommand(VDSCommandType.GetImagesList, new GetImagesListVDSCommandParameters(targetStorageDomainId, storagePoolId));
            if (returnValue.getSucceeded()) {
                imagesOnStorageDomain = (List<Guid>) returnValue.getReturnValue();
                domainImages.put(targetStorageDomainId, imagesOnStorageDomain);
            } else {
                return new ValidationResult(EngineMessage.ERROR_GET_IMAGE_LIST, String.format("$sdName %1$s", getStorageDomainStaticDao().get(targetStorageDomainId).getName()));
            }
        }
        if (imagesOnStorageDomain.contains(diskImage.getId())) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_ALREADY_CONTAINS_DISK);
        }
    }
    return ValidationResult.VALID;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) 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) GetImagesListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 2 with GetImagesListVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters in project ovirt-engine by oVirt.

the class GetUnregisteredDisksQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    StorageDomain storageDomain = storageDomainDao.get(getStorageDomainId());
    if (storageDomain == null) {
        getQueryReturnValue().setExceptionString(EngineMessage.STORAGE_DOMAIN_DOES_NOT_EXIST.toString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    if (storageDomain.getStorageType().isCinderDomain()) {
        QueryReturnValue returnValue = runInternalQuery(QueryType.GetUnregisteredCinderDisksByStorageDomainId, new IdQueryParameters(getStorageDomainId()));
        setReturnValue(returnValue.getReturnValue());
        return;
    }
    // first, run getImagesList query into vdsm to get all of the images on the storage domain - then store in
    // imagesList
    VDSReturnValue imagesListResult = runVdsCommand(VDSCommandType.GetImagesList, new GetImagesListVDSCommandParameters(getStorageDomainId(), getStoragePoolId()));
    @SuppressWarnings("unchecked") List<Guid> imagesList = (List<Guid>) imagesListResult.getReturnValue();
    // fromDao is a list of all disk images on the domain from the Dao
    List<DiskImage> fromDao = diskImageDao.getAllSnapshotsForStorageDomain(getStorageDomainId());
    // if the ID in imagesList is recognized by oVirt, remove from list
    for (DiskImage image : fromDao) {
        imagesList.remove(image.getId());
    }
    List<Disk> unregisteredDisks = new ArrayList<>();
    for (Guid unregisteredDiskId : imagesList) {
        GetUnregisteredDiskQueryParameters unregQueryParams = new GetUnregisteredDiskQueryParameters(unregisteredDiskId, getStorageDomainId(), getStoragePoolId());
        QueryReturnValue unregQueryReturn = runInternalQuery(QueryType.GetUnregisteredDisk, unregQueryParams);
        if (unregQueryReturn.getSucceeded()) {
            unregisteredDisks.add(unregQueryReturn.getReturnValue());
        } else {
            log.debug("Could not get populated disk: {}", unregQueryReturn.getExceptionString());
        }
    }
    getQueryReturnValue().setReturnValue(unregisteredDisks);
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) List(java.util.List) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) GetImagesListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 GetImagesListVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 Guid (org.ovirt.engine.core.compat.Guid)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 GetUnregisteredDiskQueryParameters (org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1