blob: 4ca9927052fa83cb18548e46c631b1f4b675a706 [file] [log] [blame]
Jonathan Harte37e4e22014-05-13 19:12:02 -07001package net.onrc.onos.core.topology.web;
2
Jonathan Harte37e4e22014-05-13 19:12:02 -07003import net.onrc.onos.core.topology.ITopologyService;
4import net.onrc.onos.core.topology.Topology;
Jonathan Harte37e4e22014-05-13 19:12:02 -07005
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -07006import org.restlet.representation.Representation;
Jonathan Harte37e4e22014-05-13 19:12:02 -07007import org.restlet.resource.Get;
8import org.restlet.resource.ServerResource;
Jonathan Harte37e4e22014-05-13 19:12:02 -07009
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070010/**
11 * A class to access hosts information from the network topology.
12 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070013public class TopologyDevicesResource extends ServerResource {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070014 /**
15 * Gets the hosts information from the network topology.
16 *
17 * @return a Representation of a Collection of hosts from the network
18 * topology.
19 */
Jonathan Harte37e4e22014-05-13 19:12:02 -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());
Jonathan Harte37e4e22014-05-13 19:12:02 -070025
26 Topology topology = topologyService.getTopology();
Jonathan Harte37e4e22014-05-13 19:12:02 -070027 topology.acquireReadLock();
28 try {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070029 return toRepresentation(topology.getDevices(), null);
Jonathan Harte37e4e22014-05-13 19:12:02 -070030 } finally {
31 topology.releaseReadLock();
32 }
33 }
Jonathan Harte37e4e22014-05-13 19:12:02 -070034}