use of org.ovirt.engine.api.restapi.resource.utils.LinksTreeNode in project ovirt-engine by oVirt.
the class BaseBackendResource method follow.
/**
* Follows links in the entity according to value of "follow" URL query parameter.
* A valid value of'follow' is a comma separated list of strings, which represent
* internal links to be followed. Links may have several 'levels' denoted by periods.
* e.g: GET ...api/vms?follow="nics,disk_attachments.template,disk_attachments.disks"
*/
public final void follow(ActionableResource entity) {
String followValue = ParametersHelper.getParameter(getHttpHeaders(), getUriInfo(), FOLLOW);
if (followValue != null && !followValue.equals("")) {
ParametersHelper.removeParameter(FOLLOW);
ParametersHelper.removeParameter(MAX);
LinksTreeNode linksTree = linkFollower.createLinksTree(entity.getClass(), followValue);
follow(entity, linksTree);
linkFollower.followLinks(entity, linksTree);
}
}
use of org.ovirt.engine.api.restapi.resource.utils.LinksTreeNode in project ovirt-engine by oVirt.
the class LinkFollowerTest method testFollowLinks.
@Test
public void testFollowLinks() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
LinksTreeNode linksTree = linkFollower.createLinksTree(Vm.class, "nics,disk_attachments.disk");
Vm vm = createVm();
linkFollower.followLinks(vm, linksTree);
assertNotNull(vm.getNics());
assertNotNull(vm.getNics().getNics());
assertFalse(vm.getNics().getNics().isEmpty());
assertEquals(2, vm.getNics().getNics().size());
assertNotNull(vm.getDiskAttachments());
assertNotNull(vm.getDiskAttachments().getDiskAttachments());
assertFalse(vm.getDiskAttachments().getDiskAttachments().isEmpty());
assertEquals(3, vm.getDiskAttachments().getDiskAttachments().size());
assertNotNull(vm.getDiskAttachments().getDiskAttachments().get(0).getDisk());
assertNotNull(vm.getDiskAttachments().getDiskAttachments().get(1).getDisk());
assertNotNull(vm.getDiskAttachments().getDiskAttachments().get(2).getDisk());
}
use of org.ovirt.engine.api.restapi.resource.utils.LinksTreeNode in project ovirt-engine by oVirt.
the class LinkFollowerTest method testCreateLinksTree.
@Test
public void testCreateLinksTree() {
LinksTreeNode linksTree = linkFollower.createLinksTree(Vm.class, "disk_attachments.disk,disk_attachments.template,tags,nics.network_labels");
assertNotNull(linksTree);
assertEquals("vm", linksTree.getElement());
assertTrue(linksTree.isRoot());
assertFalse(linksTree.isFollowed());
assertEquals(3, linksTree.getChildren().size());
// disk_attachments
LinksTreeNode child1 = linksTree.getChild("disk_attachments").get();
assertNotNull(child1);
assertFalse(child1.isRoot());
assertFalse(child1.isFollowed());
assertEquals("disk_attachments", child1.getElement());
assertEquals(child1.getChildren().size(), 2);
assertNotNull(child1.getChild("disk").get());
assertNotNull(child1.getChild("template").get());
// nics
LinksTreeNode child2 = linksTree.getChild("nics").get();
assertNotNull(child2);
assertFalse(child2.isRoot());
assertFalse(child2.isFollowed());
assertEquals("nics", child2.getElement());
assertEquals(child2.getChildren().size(), 1);
assertNotNull(child2.getChild("network_labels").get());
// tags
assertNotNull(linksTree.getChild("tags").get());
}
Aggregations