Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.registry.web; |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.registry.IControllerRegistryService; |
| 7 | import net.onrc.onos.core.registry.RegistryException; |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 8 | |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 9 | import org.restlet.resource.Get; |
| 10 | import org.restlet.resource.ServerResource; |
| 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | |
| 14 | public class ControllerRegistryResource extends ServerResource { |
| 15 | |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 16 | protected final static Logger log = LoggerFactory.getLogger(ControllerRegistryResource.class); |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 17 | |
| 18 | @Get("json") |
| 19 | public Collection<String> getControllers() { |
| 20 | IControllerRegistryService registry = |
| 21 | (IControllerRegistryService) getContext().getAttributes(). |
| 22 | get(IControllerRegistryService.class.getCanonicalName()); |
| 23 | |
| 24 | Collection<String> controllers = null; |
| 25 | try { |
| 26 | controllers = registry.getAllControllers(); |
| 27 | } catch (RegistryException e) { |
| 28 | log.warn("Error retrieving controller list: {}", e.getMessage()); |
| 29 | } |
| 30 | |
| 31 | if (controllers == null){ |
| 32 | controllers = new ArrayList<String>(); |
| 33 | } |
| 34 | |
| 35 | return controllers; |
| 36 | } |
| 37 | |
| 38 | } |