blob: 3eeadbb57ab393874c3b293efbdcdaf77b4238dd [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;
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -07005import net.onrc.onos.core.topology.MutableTopology;
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
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070027 MutableTopology mutableTopology = topologyService.getTopology();
28 mutableTopology.acquireReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070029 try {
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070030 return eval(toRepresentation(mutableTopology.getSwitches(), null));
Ray Milkey269ffb92014-04-03 14:43:30 -070031 } finally {
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070032 mutableTopology.releaseReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070033 }
34 }
Jonathan Hart891d0502014-02-10 10:04:08 -080035}