@Test public void testGetAllDatastores() throws Exception { List<String> dsList1 = new ArrayList<>(); List<String> dsList2 = new ArrayList<>(); List<String> dsList3 = new ArrayList<>(); dsList1.add("ds1"); dsList2.add("ds1"); dsList2.add("ds2"); dsList3.add("ds3"); HostConfig host1 = getHostConfig("host1", dsList1, ""); HostConfig host2 = getHostConfig("host2", dsList2, ""); HostConfig host3 = getHostConfig("host3", dsList3, ""); PathChildrenCacheEvent event1 = getMockedEvent("host1", host1, Type.CHILD_ADDED); PathChildrenCacheEvent event2 = getMockedEvent("host2", host2, Type.CHILD_ADDED); PathChildrenCacheEvent event3 = getMockedEvent("host3", host3, Type.CHILD_ADDED); List<ChildData> currEvents = getChildDataFromEvents(event1, event2, event3); when(mockCache.getCurrentData()).thenReturn(currEvents); ZookeeperHostMonitor hostMonitor = new ZookeeperHostMonitor(zkClient, pathCache, executer); Set<Datastore> datastores = hostMonitor.getAllDatastores(); assertThat(datastores.size(), is(3)); assertThat(datastores.contains(new Datastore("ds1")), is(true)); assertThat(datastores.contains(new Datastore("ds2")), is(true)); assertThat(datastores.contains(new Datastore("ds3")), is(true)); }
public synchronized Set<Datastore> getAllDatastores() { Set<Datastore> datastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (Datastore ds : config.getDatastores()) { datastores.add(ds); } } return datastores; }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getAllDatastores() { Set<Datastore> datastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (Datastore ds : config.getDatastores()) { datastores.add(ds); } } return datastores; } }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getAllDatastores() { Set<Datastore> datastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (Datastore ds : config.getDatastores()) { datastores.add(ds); } } return datastores; } @Inject  ZookeeperHostMonitor(CuratorFramework zkClient,
                              @ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                              ExecutorService executor); }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getAllDatastores() { Set<Datastore> datastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (Datastore ds : config.getDatastores()) { datastores.add(ds); } } return datastores; } @Inject  ZookeeperHostMonitor(CuratorFramework zkClient,
                              @ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                              ExecutorService executor); synchronized ServerSet createStaticServerSet(String hostId); @Override synchronized void addChangeListener(HostChangeListener listener); @Override synchronized void removeChangeListener(HostChangeListener listener); synchronized Set<Datastore> getImageDatastores(); synchronized Set<HostConfig> getHostsForDatastore(String datastoreId); synchronized Set<Datastore> getDatastoresForHost(String hostId); synchronized Set<Datastore> getAllDatastores(); }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getAllDatastores() { Set<Datastore> datastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (Datastore ds : config.getDatastores()) { datastores.add(ds); } } return datastores; } @Inject  ZookeeperHostMonitor(CuratorFramework zkClient,
                              @ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                              ExecutorService executor); synchronized ServerSet createStaticServerSet(String hostId); @Override synchronized void addChangeListener(HostChangeListener listener); @Override synchronized void removeChangeListener(HostChangeListener listener); synchronized Set<Datastore> getImageDatastores(); synchronized Set<HostConfig> getHostsForDatastore(String datastoreId); synchronized Set<Datastore> getDatastoresForHost(String hostId); synchronized Set<Datastore> getAllDatastores();  }