Search in sources :

Example 1 with IdsQueryParameters

use of org.ovirt.engine.core.common.queries.IdsQueryParameters in project ovirt-engine by oVirt.

the class BackendVmsResource method mapCollection.

protected Vms mapCollection(List<org.ovirt.engine.core.common.businessentities.VM> entities) {
    Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
    boolean includeData = details.contains(DetailHelper.MAIN);
    boolean includeSize = details.contains("size");
    List<Guid> vmIds = entities.stream().map(VM::getId).collect(Collectors.toList());
    if (includeData) {
        // Fill VmInit for entities - the search query no join the VmInit to Vm
        IdsQueryParameters params = new IdsQueryParameters();
        params.setId(vmIds);
        QueryReturnValue queryReturnValue = runQuery(QueryType.GetVmsInit, params);
        if (queryReturnValue.getSucceeded() && queryReturnValue.getReturnValue() != null) {
            List<VmInit> vmInits = queryReturnValue.getReturnValue();
            Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
            for (org.ovirt.engine.core.common.businessentities.VM vm : entities) {
                vm.setVmInit(initMap.get(vm.getId()));
            }
        }
    }
    Vms collection = new Vms();
    if (includeData) {
        // optimization of DB access: retrieve GraphicsDevices for all VMs at once
        Map<Guid, List<GraphicsDevice>> vmsGraphicsDevices = DisplayHelper.getGraphicsDevicesForMultipleEntities(this, vmIds);
        for (org.ovirt.engine.core.common.businessentities.VM entity : entities) {
            Vm vm = map(entity);
            DisplayHelper.adjustDisplayData(this, vm, vmsGraphicsDevices, false);
            removeRestrictedInfo(vm);
            collection.getVms().add(addLinks(populate(vm, entity)));
        }
    }
    if (includeSize) {
        collection.setSize((long) entities.size());
    }
    return collection;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) Vm(org.ovirt.engine.api.model.Vm) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Vms(org.ovirt.engine.api.model.Vms)

Example 2 with IdsQueryParameters

use of org.ovirt.engine.core.common.queries.IdsQueryParameters in project ovirt-engine by oVirt.

the class BackendTemplatesResource method mapCollection.

protected Templates mapCollection(List<VmTemplate> entities) {
    Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
    boolean includeData = details.contains(DetailHelper.MAIN);
    boolean includeSize = details.contains("size");
    if (includeData) {
        // Fill VmInit for entities - the search query no join the VmInit to Templates
        IdsQueryParameters params = new IdsQueryParameters();
        List<Guid> ids = entities.stream().map(VmTemplate::getId).collect(Collectors.toList());
        params.setId(ids);
        QueryReturnValue queryReturnValue = runQuery(QueryType.GetVmsInit, params);
        if (queryReturnValue.getSucceeded() && queryReturnValue.getReturnValue() != null) {
            List<VmInit> vmInits = queryReturnValue.getReturnValue();
            Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
            for (VmTemplate template : entities) {
                template.setVmInit(initMap.get(template.getId()));
            }
        }
    }
    Templates collection = new Templates();
    if (includeData) {
        for (VmTemplate entity : entities) {
            Template template = map(entity);
            collection.getTemplates().add(addLinks(populate(template, entity)));
            DisplayHelper.adjustDisplayData(this, template);
        }
    }
    if (includeSize) {
        collection.setSize((long) entities.size());
    }
    return collection;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters) Templates(org.ovirt.engine.api.model.Templates) Guid(org.ovirt.engine.core.compat.Guid) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 3 with IdsQueryParameters

use of org.ovirt.engine.core.common.queries.IdsQueryParameters in project ovirt-engine by oVirt.

the class AsyncDataProvider method getAncestorImagesByImagesIds.

public void getAncestorImagesByImagesIds(AsyncQuery<Map<Guid, DiskImage>> aQuery, List<Guid> imagesIds) {
    aQuery.converterCallback = new CastingConverter<>();
    IdsQueryParameters params = new IdsQueryParameters(imagesIds);
    Frontend.getInstance().runQuery(QueryType.GetAncestorImagesByImagesIds, params, aQuery);
}
Also used : IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters)

Aggregations

IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)3 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Template (org.ovirt.engine.api.model.Template)1 Templates (org.ovirt.engine.api.model.Templates)1 Vm (org.ovirt.engine.api.model.Vm)1 Vms (org.ovirt.engine.api.model.Vms)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)1