Temporarily disabled zookeeper connection on startup
diff --git a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java b/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
index fdcb5c0..bfb2e9a 100644
--- a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
+++ b/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
@@ -32,16 +32,16 @@
* @param controller A string identifying the controller and (possibly) how to talk to it.
* (We will have to develop a convention for this - most likely hostname:port)
*/
- public void registerController(String controllerId);
+ public void registerController(String controllerId) throws RegistryException;
/**
* Get all controllers in the cluster
* @return
*/
- public Collection<String> getAllControllers();
+ public Collection<String> getAllControllers() throws RegistryException;
- public String getControllerForSwitch(long dpid);
+ public String getControllerForSwitch(long dpid) throws RegistryException;
public Collection<Long> getSwitchesControlledByController(String controllerId);
}
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java b/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
index f4230ae..5f8a156 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
+++ b/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
@@ -153,11 +153,12 @@
try {
latch.close();
} catch (IOException e) {
-
+ //I think it's OK not to do anything here. Either the node got deleted correctly,
+ //or the connection went down and the node got deleted.
+ } finally {
+ switchLatches.remove(dpidStr);
+ switchCallbacks.remove(dpidStr);
}
-
- switchLatches.remove(dpidStr);
- switchCallbacks.remove(dpidStr);
}
@Override
@@ -188,9 +189,9 @@
}
@Override
- public Collection<String> getAllControllers() {
- // TODO Auto-generated method stub
+ public Collection<String> getAllControllers() throws RegistryException {
log.debug("Getting all controllers");
+
List<String> controllers = new ArrayList<String>();
for (ChildData data : controllerCache.getCurrentData()){
@@ -198,8 +199,7 @@
try {
d = new String(data.getData(), "UTF-8");
} catch (UnsupportedEncodingException e) {
- // TODO unlikely(throw exception)
- e.printStackTrace();
+ throw new RegistryException("Error encoding string", e);
}
controllers.add(d);
@@ -208,14 +208,12 @@
}
@Override
- public void registerController(String id) {
- // TODO Auto-generated method stub
+ public void registerController(String id) throws RegistryException {
byte bytes[] = null;
try {
bytes = id.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
- // TODO Throw some exception (very unlikely this will happen)
- e1.printStackTrace();
+ throw new RegistryException("Error encoding string", e1);
}
String path = controllerPath + "/" + id;
@@ -227,14 +225,12 @@
client.create().withProtection().withMode(CreateMode.EPHEMERAL)
.forPath(path, bytes);
} catch (Exception e) {
- // TODO Auto-generated catch block
- // TODO Make an exception that will be thrown here
- e.printStackTrace();
+ throw new RegistryException("Error contacting the Zookeeper service", e);
}
}
@Override
- public String getControllerForSwitch(long dpid) {
+ public String getControllerForSwitch(long dpid) throws RegistryException {
// TODO Work out how we should store this controller/switch data.
// The leader latch might be a index to the /controllers collections
// which holds more info on the controller (how to talk to it for example).
@@ -252,8 +248,7 @@
try {
leader = latch.getLeader();
} catch (Exception e) {
- // TODO Zookeeper issue, throw exception
- e.printStackTrace();
+ throw new RegistryException("Error contacting the Zookeeper service", e);
}
return leader.getId();
@@ -293,7 +288,7 @@
@Override
public void init (FloodlightModuleContext context) throws FloodlightModuleException {
-
+ /*
try {
String localHostname = java.net.InetAddress.getLocalHost().getHostName();
mastershipId = localHostname;
@@ -323,7 +318,7 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+ */
}
@Override
diff --git a/src/main/java/net/floodlightcontroller/mastership/RegistryException.java b/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
new file mode 100644
index 0000000..ebf564a
--- /dev/null
+++ b/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
@@ -0,0 +1,32 @@
+package net.floodlightcontroller.mastership;
+
+public class RegistryException extends Exception {
+
+ private static final long serialVersionUID = -8276300722010217913L;
+
+ public RegistryException() {
+ // 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, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ public RegistryException(String message, Throwable cause,
+ boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ // TODO Auto-generated constructor stub
+ }
+
+}