blob: 6d910a8850d1e34090a2d798c419990240251b0a [file] [log] [blame]
Jonathan Harte37e4e22014-05-13 19:12:02 -07001package net.onrc.onos.core.topology.web;
2
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -07003import static net.onrc.onos.core.topology.web.TopologyResource.eval;
Jonathan Harte37e4e22014-05-13 19:12:02 -07004import net.onrc.onos.core.topology.ITopologyService;
5import net.onrc.onos.core.topology.Topology;
Jonathan Harte37e4e22014-05-13 19:12:02 -07006
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -07007import org.restlet.representation.Representation;
Jonathan Harte37e4e22014-05-13 19:12:02 -07008import org.restlet.resource.Get;
9import org.restlet.resource.ServerResource;
Jonathan Harte37e4e22014-05-13 19:12:02 -070010
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070011/**
12 * A class to access links information from the network topology.
13 */
Yuta HIGUCHI2ffc3b72014-06-09 15:38:28 -070014public class LinksResource extends ServerResource {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070015 /**
16 * Gets the links information from the network topology.
17 *
18 * @return a Representation of a Collection of links from the network
19 * topology.
20 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070021 @Get("json")
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070022 public Representation retrieve() {
23 ITopologyService topologyService =
24 (ITopologyService) getContext().getAttributes()
25 .get(ITopologyService.class.getCanonicalName());
Jonathan Harte37e4e22014-05-13 19:12:02 -070026
27 Topology topology = topologyService.getTopology();
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070028 topology.acquireReadLock();
Jonathan Harte37e4e22014-05-13 19:12:02 -070029 try {
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -070030 return eval(toRepresentation(topology.getLinks(), null));
Jonathan Harte37e4e22014-05-13 19:12:02 -070031 } finally {
32 topology.releaseReadLock();
33 }
34 }
35}