blob: d5fc52c20dbe89eb4407d95b6525ead0a1f3a9b8 [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;
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -07005import net.onrc.onos.core.topology.MutableTopology;
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
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070027 MutableTopology mutableTopology = topologyService.getTopology();
28 mutableTopology.acquireReadLock();
Jonathan Harte37e4e22014-05-13 19:12:02 -070029 try {
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070030 return eval(toRepresentation(mutableTopology.getLinks(), null));
Jonathan Harte37e4e22014-05-13 19:12:02 -070031 } finally {
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070032 mutableTopology.releaseReadLock();
Jonathan Harte37e4e22014-05-13 19:12:02 -070033 }
34 }
35}