Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datagrid.web; |
Jonathan Hart | 10a7e2b | 2014-02-21 18:30:08 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.Collection; |
| 4 | |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 6 | import net.onrc.onos.core.datagrid.IEventChannel; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.topology.TopologyEvent; |
| 8 | import net.onrc.onos.core.topology.TopologyManager; |
Jonathan Hart | 10a7e2b | 2014-02-21 18:30:08 -0800 | [diff] [blame] | 9 | |
| 10 | import org.restlet.resource.Get; |
| 11 | import org.restlet.resource.ServerResource; |
| 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
| 15 | public class GetNGEventsResource extends ServerResource { |
| 16 | |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 17 | public static final Logger log = LoggerFactory.getLogger(GetNGEventsResource.class); |
| 18 | |
| 19 | @Get("json") |
| 20 | public String retrieve() { |
| 21 | IDatagridService datagridService = |
| 22 | (IDatagridService) getContext().getAttributes(). |
| 23 | get(IDatagridService.class.getCanonicalName()); |
| 24 | |
| 25 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 26 | log.debug("Get topology events"); |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 27 | |
| 28 | IEventChannel<byte[], TopologyEvent> channel = datagridService.createChannel(TopologyManager.EVENT_CHANNEL_NAME, |
| 29 | byte[].class, TopologyEvent.class); |
| 30 | |
| 31 | Collection<TopologyEvent> entries = channel.getAllEntries(); |
| 32 | |
Pavlin Radoslavov | 424150c | 2014-04-09 12:12:36 -0700 | [diff] [blame] | 33 | StringBuilder result = new StringBuilder(); |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 34 | for (TopologyEvent event : entries) { |
Pavlin Radoslavov | 424150c | 2014-04-09 12:12:36 -0700 | [diff] [blame] | 35 | result.append(event.toString() + "\n"); |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Pavlin Radoslavov | 424150c | 2014-04-09 12:12:36 -0700 | [diff] [blame] | 38 | return result.toString(); |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 39 | } |
Jonathan Hart | 10a7e2b | 2014-02-21 18:30:08 -0800 | [diff] [blame] | 40 | } |