blob: e1fbb1bb61df822e9c0fab254807788f8d381fc3 [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.EventHistoryTopologySwitch;
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;
10
11/**
12 * @author subrata
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080013 */
14public class EventHistoryTopologySwitchResource extends ServerResource {
15
16 @Get("json")
17 public EventHistory<EventHistoryTopologySwitch> handleEvHistReq() {
18
19 // Get the event history count. Last <count> events would be returned
Ray Milkey269ffb92014-04-03 14:43:30 -070020 String evHistCount = (String) getRequestAttributes().get("count");
21 int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022 try {
23 count = Integer.parseInt(evHistCount);
Ray Milkey269ffb92014-04-03 14:43:30 -070024 } catch (NumberFormatException nFE) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080025 // Invalid input for event count - use default value
26 }
27
28 LinkDiscoveryManager topoManager =
Ray Milkey269ffb92014-04-03 14:43:30 -070029 (LinkDiscoveryManager) getContext().getAttributes().
30 get(ILinkDiscoveryService.class.getCanonicalName());
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031
32 return new EventHistory<EventHistoryTopologySwitch>(
Ray Milkey269ffb92014-04-03 14:43:30 -070033 topoManager.evHistTopologySwitch, count);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 }
35}