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; |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame^] | 5 | import net.onrc.onos.core.topology.MutableTopology; |
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 | |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame^] | 27 | MutableTopology mutableTopology = topologyService.getTopology(); |
| 28 | mutableTopology.acquireReadLock(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 29 | try { |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame^] | 30 | return eval(toRepresentation(mutableTopology.getLinks(), null)); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 31 | } finally { |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame^] | 32 | mutableTopology.releaseReadLock(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | } |