Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.topology.ITopologyService; |
| 4 | import net.onrc.onos.core.topology.Topology; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 5 | |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 6 | import org.restlet.representation.Representation; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 7 | import org.restlet.resource.Get; |
| 8 | import org.restlet.resource.ServerResource; |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 9 | |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 10 | /** |
| 11 | * A class to access switches and ports information from the network topology. |
| 12 | */ |
Yuta HIGUCHI | 2ffc3b7 | 2014-06-09 15:38:28 -0700 | [diff] [blame^] | 13 | public class SwitchesResource extends ServerResource { |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 14 | /** |
| 15 | * Gets the switches and ports information from the network topology. |
| 16 | * |
| 17 | * @return a Representation of a Collection of switches from the network |
| 18 | * topology. Each switch contains the switch ports. |
| 19 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | @Get("json") |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 21 | public Representation retrieve() { |
| 22 | ITopologyService topologyService = |
| 23 | (ITopologyService) getContext().getAttributes() |
| 24 | .get(ITopologyService.class.getCanonicalName()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 26 | Topology topology = topologyService.getTopology(); |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 27 | topology.acquireReadLock(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | try { |
Pavlin Radoslavov | c097fdf | 2014-05-23 17:40:57 -0700 | [diff] [blame] | 29 | return toRepresentation(topology.getSwitches(), null); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | } finally { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 31 | topology.releaseReadLock(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 32 | } |
| 33 | } |
Jonathan Hart | 891d050 | 2014-02-10 10:04:08 -0800 | [diff] [blame] | 34 | } |