Pavlin Radoslavov | cf2b553 | 2014-05-23 18:12:23 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology.web; |
| 2 | |
| 3 | import net.onrc.onos.core.topology.ITopologyService; |
| 4 | import net.onrc.onos.core.topology.Topology; |
| 5 | |
| 6 | import org.restlet.representation.Representation; |
| 7 | import org.restlet.resource.Get; |
| 8 | import org.restlet.resource.ServerResource; |
| 9 | |
| 10 | /** |
| 11 | * A class to access the network topology information. |
| 12 | */ |
| 13 | public class TopologyAllResource extends ServerResource { |
| 14 | /** |
| 15 | * Gets the network topology information. |
| 16 | * |
| 17 | * @return a Representation of the network topology. |
| 18 | */ |
| 19 | @Get("json") |
| 20 | public Representation retrieve() { |
| 21 | ITopologyService topologyService = |
| 22 | (ITopologyService) getContext().getAttributes() |
| 23 | .get(ITopologyService.class.getCanonicalName()); |
| 24 | |
| 25 | Topology topology = topologyService.getTopology(); |
| 26 | topology.acquireReadLock(); |
| 27 | try { |
| 28 | return toRepresentation(topology, null); |
| 29 | } finally { |
| 30 | topology.releaseReadLock(); |
| 31 | } |
| 32 | } |
| 33 | } |