Skip to content
Snippets Groups Projects
Commit 149db29c authored by Rob Vaterlaus's avatar Rob Vaterlaus
Browse files

REST API support for getting per-switch HA role info

parent 40e39e32
No related branches found
No related tags found
No related merge requests found
......@@ -11,33 +11,10 @@ import org.restlet.resource.Post;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RoleResource extends ServerResource {
public class ControllerRoleResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(RoleResource.class);
protected static Logger log = LoggerFactory.getLogger(ControllerRoleResource.class);
public static class RoleInfo {
protected String role;
public RoleInfo() {
}
public RoleInfo(String role) {
setRole(role);
}
public RoleInfo(Role role) {
this.role = (role != null) ? role.name() : "DISABLED";
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
@Get("json")
public RoleInfo getRole() {
IFloodlightProviderService floodlightProvider =
......
......@@ -39,6 +39,7 @@ public class CoreWebRoutable implements RestletRoutable {
Router router = new Router(context);
router.attach("/module/all/json", ModuleLoaderResource.class);
router.attach("/module/loaded/json", LoadedModuleLoaderResource.class);
router.attach("/switch/{switchId}/role/json", SwitchRoleResource.class);
router.attach("/switch/all/{statType}/json", AllSwitchStatisticsResource.class);
router.attach("/switch/{switchId}/{statType}/json", SwitchStatisticsResource.class);
router.attach("/controller/switches/json", ControllerSwitchesResource.class);
......@@ -56,7 +57,7 @@ public class CoreWebRoutable implements RestletRoutable {
EventHistoryTopologyClusterResource.class);
router.attach("/storage/tables/json", StorageSourceTablesResource.class);
router.attach("/controller/summary/json", ControllerSummaryResource.class);
router.attach("/role/json", RoleResource.class);
router.attach("/role/json", ControllerRoleResource.class);
router.attach("/health/json", HealthCheckResource.class);
return router;
}
......
package net.floodlightcontroller.core.web;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
public class RoleInfo {
protected String role;
public RoleInfo() {
}
public RoleInfo(String role) {
setRole(role);
}
public RoleInfo(Role role) {
this.role = (role != null) ? role.name() : "DISABLED";
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
\ No newline at end of file
package net.floodlightcontroller.core.web;
import java.util.HashMap;
import org.openflow.util.HexString;
import org.restlet.resource.ServerResource;
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IOFSwitch;
import org.restlet.resource.Get;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SwitchRoleResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(SwitchRoleResource.class);
@Get("json")
public Object getRole() {
IFloodlightProviderService floodlightProvider =
(IFloodlightProviderService)getContext().getAttributes().
get(IFloodlightProviderService.class.getCanonicalName());
String switchId = (String) getRequestAttributes().get("switchId");
RoleInfo roleInfo;
if (switchId.equalsIgnoreCase("all")) {
HashMap<String,RoleInfo> model = new HashMap<String,RoleInfo>();
for (IOFSwitch sw: floodlightProvider.getSwitches().values()) {
switchId = sw.getStringId();
roleInfo = new RoleInfo(sw.getRole());
model.put(switchId, roleInfo);
}
return model;
}
Long dpid = HexString.toLong(switchId);
IOFSwitch sw = floodlightProvider.getSwitches().get(dpid);
if (sw == null)
return null;
roleInfo = new RoleInfo(sw.getRole());
return roleInfo;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment