Skip to content
Snippets Groups Projects
Commit 201dbb86 authored by Ryan Izard's avatar Ryan Izard
Browse files

Fix HA role REST API and add flag to allow us to toggle the controller's...

Fix HA role REST API and add flag to allow us to toggle the controller's behavior when a transition to STANDBY occurs. For now, since we don't have much logic in other modules to handle STANDBY roles, we'll shutdown, but in the future, we should give the ability to stay running and await the next transition to ACTIVE.
parent b2321b4b
No related branches found
No related tags found
No related merge requests found
...@@ -134,6 +134,7 @@ public class Controller implements IFloodlightProviderService, IStorageSourceLis ...@@ -134,6 +134,7 @@ public class Controller implements IFloodlightProviderService, IStorageSourceLis
* based on parameters that are only available in init() * based on parameters that are only available in init()
*/ */
private static RoleManager roleManager; private static RoleManager roleManager;
protected static boolean shutdownOnTransitionToStandby = false;
/* Storage table names */ /* Storage table names */
protected static final String CONTROLLER_TABLE_NAME = "controller_controller"; protected static final String CONTROLLER_TABLE_NAME = "controller_controller";
...@@ -620,10 +621,21 @@ public class Controller implements IFloodlightProviderService, IStorageSourceLis ...@@ -620,10 +621,21 @@ public class Controller implements IFloodlightProviderService, IStorageSourceLis
} }
log.info("ControllerId set to {}", this.controllerId); log.info("ControllerId set to {}", this.controllerId);
String shutdown = configParams.get("shutdownOnTransitionToStandby");
if (!Strings.isNullOrEmpty(shutdown)) {
try {
shutdownOnTransitionToStandby = Boolean.parseBoolean(shutdown.trim());
} catch (Exception e) {
log.error("Could not parse 'shutdownOnTransitionToStandby' of {}. Using default setting of {}",
shutdown, shutdownOnTransitionToStandby);
}
}
log.info("Shutdown when controller transitions to STANDBY HA role: {}", shutdownOnTransitionToStandby);
String decodeEth = configParams.get("deserializeEthPacketIns"); String decodeEth = configParams.get("deserializeEthPacketIns");
if (!Strings.isNullOrEmpty(decodeEth)) { if (!Strings.isNullOrEmpty(decodeEth)) {
try { try {
alwaysDecodeEth = Boolean.parseBoolean(decodeEth); alwaysDecodeEth = Boolean.parseBoolean(decodeEth.trim());
} catch (Exception e) { } catch (Exception e) {
log.error("Could not parse 'deserializeEthPacketIns' of {}. Using default setting of {}", decodeEth, alwaysDecodeEth); log.error("Could not parse 'deserializeEthPacketIns' of {}. Using default setting of {}", decodeEth, alwaysDecodeEth);
} }
......
...@@ -219,7 +219,7 @@ public class RoleManager { ...@@ -219,7 +219,7 @@ public class RoleManager {
controller.setNotifiedRole(newRole); controller.setNotifiedRole(newRole);
if(newRole == HARole.STANDBY) { if (newRole == HARole.STANDBY && Controller.shutdownOnTransitionToStandby) {
String reason = String.format("Received role request to " String reason = String.format("Received role request to "
+ "transition from ACTIVE to STANDBY (reason: %s)", + "transition from ACTIVE to STANDBY (reason: %s)",
getRoleInfo().getRoleChangeDescription()); getRoleInfo().getRoleChangeDescription());
......
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
package net.floodlightcontroller.core.web; package net.floodlightcontroller.core.web;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.restlet.resource.ServerResource; import org.restlet.resource.ServerResource;
import net.floodlightcontroller.core.HARole;
import net.floodlightcontroller.core.IFloodlightProviderService; import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.RoleInfo; import net.floodlightcontroller.core.RoleInfo;
...@@ -30,17 +32,16 @@ import org.slf4j.Logger; ...@@ -30,17 +32,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.MappingJsonFactory; import com.fasterxml.jackson.databind.MappingJsonFactory;
public class ControllerRoleResource extends ServerResource { public class ControllerRoleResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(ControllerRoleResource.class); protected static Logger log = LoggerFactory.getLogger(ControllerRoleResource.class);
private static final String STR_ACTIVE = "ACTIVE";
private static final String STR_STANDBY = "STANDBY";
private static final String STR_ROLE = "role"; private static final String STR_ROLE = "role";
private static final String STR_ROLE_CHANGE_DESC = "role-change-description"; private static final String STR_ROLE_CHANGE_DESC = "role_change_description";
private static final String STR_ROLE_CHANGE_DATE_TIME = "role-change-date-time"; private static final String STR_ROLE_CHANGE_DATE_TIME = "role_change_date_time";
@Get("json") @Get("json")
public Map<String, String> getRole() { public Map<String, String> getRole() {
...@@ -68,12 +69,9 @@ public class ControllerRoleResource extends ServerResource { ...@@ -68,12 +69,9 @@ public class ControllerRoleResource extends ServerResource {
String role = null; String role = null;
String roleChangeDesc = null; String roleChangeDesc = null;
retValue.put("TBD", "Not yet implemented");
return retValue;
/*
try { try {
try { try {
jp = f.createJsonParser(json); jp = f.createParser(json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -106,16 +104,14 @@ public class ControllerRoleResource extends ServerResource { ...@@ -106,16 +104,14 @@ public class ControllerRoleResource extends ServerResource {
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
retValue.put("ERROR", "Caught IOException while parsing JSON POST request in role request."); retValue.put("ERROR", "Caught exception while parsing controller role request. Supported roles: ACTIVE, STANDBY (or MASTER, SLAVE)");
} }
HARole harole = null; HARole harole = null;
try { try {
harole = HARole.valueOfBackwardsCompatible(role); harole = HARole.valueOfBackwardsCompatible(role.toUpperCase().trim());
} catch (IllegalArgumentException | NullPointerException e) { } catch (IllegalArgumentException | NullPointerException e) {
// The role value in the REST call didn't match a valid retValue.put("ERROR", "Caught exception while parsing controller role request. Supported roles: ACTIVE, STANDBY (or MASTER, SLAVE)");
// role name, so just leave the role as null and handle
// the error below.
} }
if (roleChangeDesc == null) { if (roleChangeDesc == null) {
...@@ -129,6 +125,6 @@ public class ControllerRoleResource extends ServerResource { ...@@ -129,6 +125,6 @@ public class ControllerRoleResource extends ServerResource {
retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription()); retValue.put(STR_ROLE_CHANGE_DESC, ri.getRoleChangeDescription());
retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString()); retValue.put(STR_ROLE_CHANGE_DATE_TIME, ri.getRoleChangeDateTime().toString());
return retValue;*/ return retValue;
} }
} }
...@@ -37,6 +37,7 @@ net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE ...@@ -37,6 +37,7 @@ net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE
net.floodlightcontroller.core.internal.FloodlightProvider.controllerId=1 net.floodlightcontroller.core.internal.FloodlightProvider.controllerId=1
net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-history-size=10 net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-history-size=10
net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.5 net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.5
net.floodlightcontroller.core.internal.FloodlightProvider.shutdownOnTransitionToStandby=true
net.floodlightcontroller.core.internal.OFSwitchManager.openFlowPort=6653 net.floodlightcontroller.core.internal.OFSwitchManager.openFlowPort=6653
net.floodlightcontroller.core.internal.OFSwitchManager.openFlowAddresses=0.0.0.0 net.floodlightcontroller.core.internal.OFSwitchManager.openFlowAddresses=0.0.0.0
net.floodlightcontroller.core.internal.OFSwitchManager.workerThreads=16 net.floodlightcontroller.core.internal.OFSwitchManager.workerThreads=16
......
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