@Test public void testGetImageDataStoresUnset() throws Exception { List<String> dsList1 = new ArrayList<>(); dsList1.add("ds1"); HostConfig host1 = getHostConfig("host1", dsList1, null); PathChildrenCacheEvent event1 = getMockedEvent("host1", host1, Type.CHILD_ADDED); List<ChildData> currEvents = getChildDataFromEvents(event1); when(mockCache.getCurrentData()).thenReturn(currEvents); ZookeeperHostMonitor hostMonitor = new ZookeeperHostMonitor(zkClient, pathCache, executer); Set<Datastore> datastores = hostMonitor.getImageDatastores(); assertThat(datastores.size(), is(0)); }
public synchronized Set<Datastore> getImageDatastores() { Set<Datastore> imageDatastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (String imageDs : config.getImage_datastore_ids()) { Datastore tmpDs = null; for (Datastore ds : config.getDatastores()) { if (ds.getId().equals(imageDs)) { tmpDs = ds; break; } } if (tmpDs == null) { logger.warn("Image datastore id {} is specified, but doesn't exist in datastores", imageDs); } else { imageDatastores.add(tmpDs); } } } return imageDatastores; }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getImageDatastores() { Set<Datastore> imageDatastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (String imageDs : config.getImage_datastore_ids()) { Datastore tmpDs = null; for (Datastore ds : config.getDatastores()) { if (ds.getId().equals(imageDs)) { tmpDs = ds; break; } } if (tmpDs == null) { logger.warn("Image datastore id {} is specified, but doesn't exist in datastores", imageDs); } else { imageDatastores.add(tmpDs); } } } return imageDatastores; } }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getImageDatastores() { Set<Datastore> imageDatastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (String imageDs : config.getImage_datastore_ids()) { Datastore tmpDs = null; for (Datastore ds : config.getDatastores()) { if (ds.getId().equals(imageDs)) { tmpDs = ds; break; } } if (tmpDs == null) { logger.warn("Image datastore id {} is specified, but doesn't exist in datastores", imageDs); } else { imageDatastores.add(tmpDs); } } } return imageDatastores; } @Inject  ZookeeperHostMonitor(CuratorFramework zkClient,
                              @ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                              ExecutorService executor); }
ZookeeperHostMonitor extends ZookeeperMonitor implements HostMonitor { public synchronized Set<Datastore> getImageDatastores() { Set<Datastore> imageDatastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (String imageDs : config.getImage_datastore_ids()) { Datastore tmpDs = null; for (Datastore ds : config.getDatastores()) { if (ds.getId().equals(imageDs)) { tmpDs = ds; break; } } if (tmpDs == null) { logger.warn("Image datastore id {} is specified, but doesn't exist in datastores", imageDs); } else { imageDatastores.add(tmpDs); } } } return imageDatastores; } @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> getImageDatastores() { Set<Datastore> imageDatastores = new HashSet<>(); for (ChildData child : childrenCache.getCurrentData()) { String hostId = ZKPaths.getNodeFromPath(child.getPath()); HostConfig config = deserialize(hostId, child.getData()); for (String imageDs : config.getImage_datastore_ids()) { Datastore tmpDs = null; for (Datastore ds : config.getDatastores()) { if (ds.getId().equals(imageDs)) { tmpDs = ds; break; } } if (tmpDs == null) { logger.warn("Image datastore id {} is specified, but doesn't exist in datastores", imageDs); } else { imageDatastores.add(tmpDs); } } } return imageDatastores; } @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();  }