Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web; |
| 2 | |
Yuta HIGUCHI | a0dcd47 | 2014-07-06 21:06:29 -0700 | [diff] [blame] | 3 | import static net.onrc.onos.core.topology.web.TopologyResource.eval; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.topology.ITopologyService; |
| 5 | import net.onrc.onos.core.topology.Topology; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 6 | |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 7 | import org.restlet.representation.Representation; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 8 | import org.restlet.resource.Get; |
| 9 | import org.restlet.resource.ServerResource; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 10 | |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 11 | /** |
| 12 | * A class to access links information from the network topology. |
| 13 | */ |
Yuta HIGUCHI | 2ffc3b7 | 2014-06-09 15:38:28 -0700 | [diff] [blame] | 14 | public class LinksResource extends ServerResource { |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 15 | /** |
| 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 Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 21 | @Get("json") |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 22 | public Representation retrieve() { |
| 23 | ITopologyService topologyService = |
| 24 | (ITopologyService) getContext().getAttributes() |
| 25 | .get(ITopologyService.class.getCanonicalName()); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 26 | |
| 27 | Topology topology = topologyService.getTopology(); |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 28 | topology.acquireReadLock(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 29 | try { |
Yuta HIGUCHI | a0dcd47 | 2014-07-06 21:06:29 -0700 | [diff] [blame] | 30 | return eval(toRepresentation(topology.getLinks(), null)); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 31 | } finally { |
| 32 | topology.releaseReadLock(); |
| 33 | } |
| 34 | } |
| 35 | } |