diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-12-14 09:05:48 +0100 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-12-14 09:05:48 +0100 |
commit | e752af8a5e6b462caed8faaeff0aafa30417c912 (patch) | |
tree | d618dab517b78b7206f1a0dc7fd52d5bed387831 /clustercontroller-apps/src | |
parent | f564cb4c8a05ddfffa6b0ef1c10ca03ff7594cdd (diff) |
Refactor code and document code to verify that ZooKeeper is working
Diffstat (limited to 'clustercontroller-apps/src')
-rw-r--r-- | clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java b/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java index b04f04abfb6..26ad2784b26 100644 --- a/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java +++ b/clustercontroller-apps/src/main/java/com/yahoo/vespa/clustercontroller/apps/clustercontroller/ClusterController.java @@ -33,6 +33,7 @@ public class ClusterController extends AbstractComponent * Dependency injection constructor for controller. {@link ZooKeeperProvider} argument given * to ensure that zookeeper has started before we start polling it. */ + @SuppressWarnings("unused") @Inject public ClusterController(ZooKeeperProvider zooKeeperProvider) { this(); @@ -45,17 +46,9 @@ public class ClusterController extends AbstractComponent public void setOptions(String clusterName, FleetControllerOptions options, Metric metricImpl) throws Exception { metricWrapper.updateMetricImplementation(metricImpl); - if (options.zooKeeperServerAddress != null && !"".equals(options.zooKeeperServerAddress)) { - // Wipe this path ... it's unclear why - String path = "/" + options.clusterName + options.fleetControllerIndex; - Curator curator = Curator.create(options.zooKeeperServerAddress); - if (curator.framework().checkExists().forPath(path) != null) - curator.framework().delete().deletingChildrenIfNeeded().forPath(path); - curator.framework().create().creatingParentsIfNeeded().forPath(path); - } + verifyThatZooKeeperWorks(options); synchronized (controllers) { FleetController controller = controllers.get(clusterName); - if (controller == null) { StatusHandler.ContainerStatusPageServer statusPageServer = new StatusHandler.ContainerStatusPageServer(); controller = FleetController.create(options, statusPageServer, metricWrapper); @@ -83,11 +76,9 @@ public class ClusterController extends AbstractComponent @Override public Map<String, RemoteClusterControllerTaskScheduler> getFleetControllers() { - Map<String, RemoteClusterControllerTaskScheduler> m = new LinkedHashMap<>(); synchronized (controllers) { - m.putAll(controllers); + return new LinkedHashMap<>(controllers); } - return m; } @Override @@ -104,4 +95,18 @@ public class ClusterController extends AbstractComponent controller.shutdown(); } + /** + * Creates a path in zookeeper for this fleetcontroller. Seems like this is meant as a check + * that zookeeper server is up and that we are able to do operations against it. + */ + private void verifyThatZooKeeperWorks(FleetControllerOptions options) throws Exception { + if (options.zooKeeperServerAddress != null && !"".equals(options.zooKeeperServerAddress)) { + String path = "/" + options.clusterName + options.fleetControllerIndex; + Curator curator = Curator.create(options.zooKeeperServerAddress); + if (curator.framework().checkExists().forPath(path) != null) + curator.framework().delete().deletingChildrenIfNeeded().forPath(path); + curator.framework().create().creatingParentsIfNeeded().forPath(path); + } + } + } |