blob: 90d919872ad084078f3a5eb52527bcaa57af2add [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.core.web;
2
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08003import net.floodlightcontroller.util.EventHistory;
Jonathan Hart23701d12014-04-03 10:45:48 -07004import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService;
5import net.onrc.onos.core.linkdiscovery.internal.EventHistoryTopologyLink;
6import net.onrc.onos.core.linkdiscovery.internal.LinkDiscoveryManager;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08007
8import org.restlet.resource.Get;
9import org.restlet.resource.ServerResource;
10import org.slf4j.Logger;
11import org.slf4j.LoggerFactory;
12
13/**
14 * @author subrata
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080015 */
16public class EventHistoryTopologyLinkResource extends ServerResource {
17 // TODO - Move this to the DeviceManager Rest API
Ray Milkey269ffb92014-04-03 14:43:30 -070018 protected final static Logger log =
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019 LoggerFactory.getLogger(EventHistoryTopologyLinkResource.class);
20
21 @Get("json")
22 public EventHistory<EventHistoryTopologyLink> handleEvHistReq() {
23
24 // Get the event history count. Last <count> events would be returned
Ray Milkey269ffb92014-04-03 14:43:30 -070025 String evHistCount = (String) getRequestAttributes().get("count");
26 int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080027 try {
28 count = Integer.parseInt(evHistCount);
Ray Milkey269ffb92014-04-03 14:43:30 -070029 } catch (NumberFormatException nFE) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 // Invalid input for event count - use default value
31 }
32
33 LinkDiscoveryManager linkDiscoveryManager =
Ray Milkey269ffb92014-04-03 14:43:30 -070034 (LinkDiscoveryManager) getContext().getAttributes().
35 get(ILinkDiscoveryService.class.getCanonicalName());
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036 if (linkDiscoveryManager != null) {
37 return new EventHistory<EventHistoryTopologyLink>(
38 linkDiscoveryManager.evHistTopologyLink, count);
39 }
Ray Milkey269ffb92014-04-03 14:43:30 -070040
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080041 return null;
42 }
43}