Refresh data from Zookeeper before answering REST call
diff --git a/src/main/java/net/onrc/onos/registry/controller/ControllerRegistryResource.java b/src/main/java/net/onrc/onos/registry/controller/ControllerRegistryResource.java
index 51f1d32..5da2e7c 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ControllerRegistryResource.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ControllerRegistryResource.java
@@ -3,6 +3,10 @@
import java.util.ArrayList;
import java.util.Collection;
+import org.restlet.Response;
+import org.restlet.data.Status;
+import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.slf4j.Logger;
@@ -27,8 +31,13 @@
if (controllers == null){
controllers = new ArrayList<String>();
+ Response response = getResponse();
+ response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
+ Representation error = new StringRepresentation("Null data returned. Zookeeper connection may be down");
+ response.setEntity(error);
+ return null;
}
-
+
return controllers;
}
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 fe758cd..7d1420a 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -236,7 +236,16 @@
public Collection<String> getAllControllers() throws RegistryException {
log.debug("Getting all controllers");
+ //Rebuild the cache to make sure we have the latest data
+ //If we don't have ZK connection this will hang until we do. Undesirable.
+ try {
+ controllerCache.rebuild();
+ } catch (Exception e1) {
+ return null;
+ }
+
List<String> controllers = new ArrayList<String>();
+
for (ChildData data : controllerCache.getCurrentData()){
String d = null;
@@ -253,6 +262,7 @@
@Override
public void registerController(String id) throws RegistryException {
+ //TODO this isn't replaced if we lose Zookeeper connection
if (controllerId != null) {
throw new RegistryException(
"Controller already registered with id " + controllerId);