Minor Registry changes and Controller now registers itself on startup using the registry
diff --git a/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
index e924f6a..0971f40 100644
--- a/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
+++ b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
@@ -29,8 +29,9 @@
public String getMastershipId ();
/**
- * Register a controller to the ONOS cluster
+ * Register a controller to the ONOS cluster.
* @param controller A string identifying the controller
+ * @throws errors connecting to registry service, controllerId already registered
*/
public void registerController(String controllerId) throws RegistryException;
diff --git a/src/main/java/net/onrc/onos/registry/controller/RegistryException.java b/src/main/java/net/onrc/onos/registry/controller/RegistryException.java
index 3b237c2..fbc68a44 100644
--- a/src/main/java/net/onrc/onos/registry/controller/RegistryException.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryException.java
@@ -9,18 +9,16 @@
// TODO Auto-generated constructor stub
}
-
- public RegistryException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
public RegistryException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
*/
+ public RegistryException(String message) {
+ super(message);
+ }
+
public RegistryException(String message, Throwable cause) {
super(message, cause);
}
diff --git a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
index e3181fe..8a468bc 100644
--- a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
@@ -32,7 +32,8 @@
public void requestControl(long dpid, ControlChangeCallback cb)
throws RegistryException {
if (controllerId == null) {
- throw new RuntimeException("Must register a controller before calling requestControl");
+ throw new RuntimeException(
+ "Must register a controller before calling requestControl");
}
switchCallbacks.put(HexString.toHexString(dpid), cb);
@@ -75,6 +76,10 @@
@Override
public void registerController(String controllerId)
throws RegistryException {
+ if (this.controllerId != null) {
+ throw new RegistryException(
+ "Controller already registered with id " + this.controllerId);
+ }
this.controllerId = controllerId;
}
diff --git a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
index 58b8bc7..1695451 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Charsets;
import com.netflix.curator.RetryPolicy;
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
@@ -286,15 +287,20 @@
@Override
public void registerController(String id) throws RegistryException {
//if (!zookeeperEnabled) return;
+ if (controllerId != null) {
+ throw new RegistryException(
+ "Controller already registered with id " + controllerId);
+ }
controllerId = id;
- byte bytes[] = null;
+ byte bytes[] = id.getBytes(Charsets.UTF_8);
+ /*byte bytes[] = null;
try {
bytes = id.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new RegistryException("Error encoding string", e1);
- }
+ }*/
String path = controllerPath + "/" + id;
@@ -364,12 +370,13 @@
}
*/
- String controllerId = null;
+ /*String controllerId = null;
try {
controllerId = new String(d.getData(), "UTF-8");
} catch (UnsupportedEncodingException e) {
log.warn("Encoding exception: {}", e.getMessage());
- }
+ }*/
+ String controllerId = new String(d.getData(), Charsets.UTF_8);
String[] splitted = d.getPath().split("-");
int sequenceNumber = Integer.parseInt(splitted[splitted.length - 1]);