blob: 94e7e6213d7a3d77a7a6308173af27a324a1cf80 [file] [log] [blame]
Jonathan Hartdeda0ba2014-04-03 11:14:12 -07001package net.onrc.onos.core.registry.web;
Jonathan Hart3d7730a2013-02-22 11:51:17 -08002
3import java.util.ArrayList;
4import java.util.Collection;
5
Jonathan Hartdeda0ba2014-04-03 11:14:12 -07006import net.onrc.onos.core.registry.IControllerRegistryService;
7import net.onrc.onos.core.registry.RegistryException;
Naoki Shiotab32edf52013-12-12 14:09:36 -08008
Jonathan Hart3d7730a2013-02-22 11:51:17 -08009import org.restlet.resource.Get;
10import org.restlet.resource.ServerResource;
11import org.slf4j.Logger;
12import org.slf4j.LoggerFactory;
13
14public class ControllerRegistryResource extends ServerResource {
15
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070016 protected final static Logger log = LoggerFactory.getLogger(ControllerRegistryResource.class);
Jonathan Hart3d7730a2013-02-22 11:51:17 -080017
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}