@Override public V3VMs adapt(Vms from) { V3VMs to = new V3VMs(); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); } if (from.isSetActive()) { to.setActive(from.getActive()); } if (from.isSetSize()) { to.setSize(from.getSize()); } if (from.isSetTotal()) { to.setTotal(from.getTotal()); } to.getVMs().addAll(adaptOut(from.getVms())); return to; } }
@Override public Vms adapt(V3VMs from) { Vms to = new Vms(); if (from.isSetActions()) { to.setActions(adaptIn(from.getActions())); } if (from.isSetActive()) { to.setActive(from.getActive()); } if (from.isSetSize()) { to.setSize(from.getSize()); } if (from.isSetTotal()) { to.setTotal(from.getTotal()); } to.getVms().addAll(adaptIn(from.getVMs())); return to; } }
@Override protected List<Vm> getCollection() { return collection.list().getVms(); }
/** * Create an instance of {@link Vms } * */ public Vms createVms() { return new Vms(); }
@Mapping(from = org.ovirt.engine.api.model.AffinityLabel.class, to = Label.class) public static Label map(org.ovirt.engine.api.model.AffinityLabel model, Label template) { LabelBuilder entity = template != null ? new LabelBuilder(template) : new LabelBuilder(); if (model.isSetId()) { entity.id(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.name(model.getName()); } if (model.isSetReadOnly()) { entity.readOnly(model.isReadOnly()); } if (model.isSetVms() && model.getVms().isSetVms()) { model.getVms().getVms().forEach(vm -> entity.vm(GuidUtils.asGuid(vm.getId()))); } if (model.isSetHosts() && model.getHosts().isSetHosts()) { model.getHosts().getHosts().forEach(host -> entity.host(GuidUtils.asGuid(host.getId()))); } return entity.build(); } }
@Override protected List<Vm> getCollection() { return collection.list().getVms(); }
@Test public void testGetCollectionGettter() { Method method = EntityHelper.getCollectionGetter(new Vms()); assertEquals("getVms", method.getName()); } }
@Override public Vms list() { Vms vms = new Vms(); boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED_CONSTRAINT_PARAMETER, true, false); if (unregistered) { List<org.ovirt.engine.core.common.businessentities.VM> unregisteredVms = getBackendCollection(QueryType.GetUnregisteredVms, new IdQueryParameters(storageDomainId)); List<Vm> collection = new ArrayList<>(); for (org.ovirt.engine.core.common.businessentities.VM entity : unregisteredVms) { Vm vm = map(entity); collection.add(addLinks(populate(vm, entity))); } vms.getVms().addAll(collection); } else { vms.getVms().addAll(getCollection()); } return vms; }
protected List<Vm> getCollection() { return collection.list().getVms(); }
@Test public void testIsCollection() { assertTrue(EntityHelper.isCollection(new Vms())); assertFalse(EntityHelper.isCollection(new Vm())); }
@Override public Vms list() { Vms vms = new Vms(); AffinityGroup affinityGroup = getEntity(); if (affinityGroup.getVmIds() != null) { for (int i = 0; i < affinityGroup.getVmIds().size(); i++) { Vm vm = new Vm(); vm.setId(affinityGroup.getVmIds().get(i).toString()); vm.setName(affinityGroup.getVmEntityNames().get(i)); vm = addLinks(populate(vm, null)); // remove vm actions, not relevant to this context vm.setActions(null); vms.getVms().add(vm); } } return vms; }
model.getVms().getVms().stream() .filter(Vm::isSetId) .map(Vm::getId)
@Override protected Disk doPopulate(Disk model, org.ovirt.engine.core.common.businessentities.storage.Disk entity) { // Populate the references to the VMs that are using this disk: List<org.ovirt.engine.core.common.businessentities.VM> vms = new ArrayList<>(1); QueryReturnValue result = runQuery(QueryType.GetVmsByDiskGuid, new IdQueryParameters(entity.getId())); if (result.getSucceeded()) { Map<Boolean, List<org.ovirt.engine.core.common.businessentities.VM>> map = result.getReturnValue(); if (MapUtils.isNotEmpty(map)) { for (List<org.ovirt.engine.core.common.businessentities.VM> list : map.values()) { vms.addAll(list); } } } if (CollectionUtils.isNotEmpty(vms)) { Vms modelVms = new Vms(); for (org.ovirt.engine.core.common.businessentities.VM vm : vms) { Vm modelVm = new Vm(); modelVm.setId(vm.getId().toString()); modelVms.getVms().add(modelVm); } model.setVms(modelVms); } return model; }
to.getVms().getVMs().addAll(adaptOut(from.getVms().getVms()));
@Test public void testVmIds() { AffinityGroup model = new AffinityGroup(); Vm vm = new Vm(); final Guid vmGuid = Guid.newGuid(); vm.setId(vmGuid.toString()); model.setVms(new Vms()); model.getVms().getVms().add(vm); org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup(); AffinityGroupMapper.map(model, entity); assertEquals(vmGuid, entity.getVmIds().get(0)); }
to.getVms().getVMs().addAll(adaptOut(from.getVms().getVms()));
@Test public void testVmIdsReplacement() { AffinityGroup model = new AffinityGroup(); Vm vm = new Vm(); final Guid vmGuid = Guid.newGuid(); vm.setId(vmGuid.toString()); model.setVms(new Vms()); model.getVms().getVms().add(vm); org.ovirt.engine.core.common.scheduling.AffinityGroup entity = new org.ovirt.engine.core.common.scheduling.AffinityGroup(); entity.getVdsIds().add(Guid.newGuid()); AffinityGroupMapper.map(model, entity); assertEquals(vmGuid, entity.getVmIds().get(0)); assertEquals(1, entity.getVmIds().size()); }
to.getVms().getVMs().addAll(adaptOut(from.getVms().getVms()));