RemoveControllers for server device driver
This method was not properly implemented but now
the driver can remove a list of designated controllers.
Refactoring was done according to received comments
Change-Id: I3f4c58d47da52305de491227ab44bd5add14041d
Signed-off-by: Georgios Katsikas <katsikas.gp@gmail.com>
diff --git a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java
index e26d4be..db62a6b 100644
--- a/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java
+++ b/drivers/server/src/main/java/org/onosproject/drivers/server/ServerControllerConfig.java
@@ -85,20 +85,14 @@
log.warn(
"I am not master for {}. " +
"Please use master {} to get controllers for this device",
- deviceId,
- mastershipService.getMasterFor(deviceId)
- );
+ deviceId, mastershipService.getMasterFor(deviceId));
return controllers;
}
// Hit the path that provides the server's controllers
InputStream response = null;
try {
- response = getController().get(
- deviceId,
- CONTROLLERS_CONF_URL,
- JSON
- );
+ response = getController().get(deviceId, CONTROLLERS_CONF_URL, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
@@ -134,6 +128,11 @@
int ctrlPort = ctrlObjNode.path(PARAM_CTRL_PORT).asInt();
String ctrlType = get(cn, PARAM_CTRL_TYPE);
+ // Implies no controller
+ if (ctrlIpStr.isEmpty()) {
+ continue;
+ }
+
// Check data format and range
IpAddress ctrlIp = null;
try {
@@ -167,9 +166,7 @@
log.warn(
"I am not master for {}. " +
"Please use master {} to set controllers for this device",
- deviceId,
- mastershipService.getMasterFor(deviceId)
- );
+ deviceId, mastershipService.getMasterFor(deviceId));
return;
}
@@ -192,11 +189,8 @@
// Post the controllers to the device
int response = getController().post(
- deviceId,
- CONTROLLERS_CONF_URL,
- new ByteArrayInputStream(sendObjNode.toString().getBytes()),
- JSON
- );
+ deviceId, CONTROLLERS_CONF_URL,
+ new ByteArrayInputStream(sendObjNode.toString().getBytes()), JSON);
if (!checkStatusCode(response)) {
log.error("Failed to set controllers on device {}", deviceId);
@@ -217,30 +211,23 @@
log.warn(
"I am not master for {}. " +
"Please use master {} to remove controllers from this device",
- deviceId,
- mastershipService.getMasterFor(deviceId)
- );
+ deviceId, mastershipService.getMasterFor(deviceId));
return;
}
- /**
- * TODO: Explicit removal of the requested controllers.
- */
+ for (ControllerInfo ctrl : controllers) {
+ log.info("Remove controller with {}:{}:{}",
+ ctrl.type(), ctrl.ip().toString(), ctrl.port());
- /**
- * List of controllers is ignored for now.
- * We just tell the server to remove its
- * current controller information.
- */
- int response = getController().delete(
- deviceId,
- CONTROLLERS_CONF_URL,
- null,
- JSON
- );
+ String remCtrlUrl = CONTROLLERS_CONF_URL + "/" + ctrl.ip().toString();
- if (!checkStatusCode(response)) {
- log.error("Failed to remove controllers from device {}", deviceId);
+ // Remove this controller
+ int response = getController().delete(deviceId, remCtrlUrl, null, JSON);
+
+ if (!checkStatusCode(response)) {
+ log.error("Failed to remove controller {}:{}:{} from device {}",
+ ctrl.type(), ctrl.ip().toString(), ctrl.port(), deviceId);
+ }
}
return;