blob: 0d41dddca60c9ed5bac865a235d5cd7ef79b24ee [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
Jonathan Harte37e4e22014-05-13 19:12:02 -07003import net.onrc.onos.core.topology.ITopologyService;
4import net.onrc.onos.core.topology.Topology;
Jonathan Hart891d0502014-02-10 10:04:08 -08005
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -07006import org.restlet.representation.Representation;
Jonathan Hart891d0502014-02-10 10:04:08 -08007import org.restlet.resource.Get;
8import org.restlet.resource.ServerResource;
Jonathan Hart891d0502014-02-10 10:04:08 -08009
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070010/**
11 * A class to access switches and ports information from the network topology.
12 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070013public class TopologySwitchesResource extends ServerResource {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070014 /**
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 Milkey269ffb92014-04-03 14:43:30 -070020 @Get("json")
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070021 public Representation retrieve() {
22 ITopologyService topologyService =
23 (ITopologyService) getContext().getAttributes()
24 .get(ITopologyService.class.getCanonicalName());
Ray Milkey269ffb92014-04-03 14:43:30 -070025
Jonathan Harte37e4e22014-05-13 19:12:02 -070026 Topology topology = topologyService.getTopology();
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070027 topology.acquireReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070028 try {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070029 return toRepresentation(topology.getSwitches(), null);
Ray Milkey269ffb92014-04-03 14:43:30 -070030 } finally {
Jonathan Harte37e4e22014-05-13 19:12:02 -070031 topology.releaseReadLock();
Ray Milkey269ffb92014-04-03 14:43:30 -070032 }
33 }
Jonathan Hart891d0502014-02-10 10:04:08 -080034}