blob: dfb381ed18f9ffd94ff66a5b698db732284c4bd8 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology.web;
Jonathan Hart891d0502014-02-10 10:04:08 -08002
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;
5import net.onrc.onos.core.topology.Topology;
Jonathan Hart891d0502014-02-10 10:04:08 -08006
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -07007import org.restlet.representation.Representation;
Jonathan Hart891d0502014-02-10 10:04:08 -08008import org.restlet.resource.Get;
9import org.restlet.resource.ServerResource;
Jonathan Hart891d0502014-02-10 10:04:08 -080010
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070011/**
12 * A class to access switches and ports information from the network topology.
13 */
Yuta HIGUCHI2ffc3b72014-06-09 15:38:28 -070014public class SwitchesResource extends ServerResource {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070015 /**
16 * Gets the switches and ports information from the network topology.
17 *
18 * @return a Representation of a Collection of switches from the network
19 * topology. Each switch contains the switch ports.
20 */
Ray Milkey269ffb92014-04-03 14:43:30 -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());
Ray Milkey269ffb92014-04-03 14:43:30 -070026
Jonathan Harte37e4e22014-05-13 19:12:02 -070027 Topology topology = topologyService.getTopology();
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070028 topology.acquireReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070029 try {
Yuta HIGUCHIa0dcd472014-07-06 21:06:29 -070030 return eval(toRepresentation(topology.getSwitches(), null));
Ray Milkey269ffb92014-04-03 14:43:30 -070031 } finally {
Jonathan Harte37e4e22014-05-13 19:12:02 -070032 topology.releaseReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070033 }
34 }
Jonathan Hart891d0502014-02-10 10:04:08 -080035}