blob: 7d287d378f13bdb7aecb748302f2af09957850df [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 links information from the network topology.
12 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070013public class TopologyLinksResource extends ServerResource {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070014 /**
15 * Gets the links information from the network topology.
16 *
17 * @return a Representation of a Collection of links 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();
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070027 topology.acquireReadLock();
Jonathan Harte37e4e22014-05-13 19:12:02 -070028 try {
Pavlin Radoslavovc097fdf2014-05-23 17:40:57 -070029 return toRepresentation(topology.getLinks(), null);
Jonathan Harte37e4e22014-05-13 19:12:02 -070030 } finally {
31 topology.releaseReadLock();
32 }
33 }
34}