private static Set<IndexStoreStrategy> getStrategies(boolean unique, MountInfoProvider mountInfoProvider, Iterable<String> children, String defaultName) { if (mountInfoProvider.hasNonDefaultMounts()) { Set<String> names = new HashSet<String>(); for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String n = getNodeForMount(m, defaultName); names.remove(n); Mount defMount = mountInfoProvider.getDefaultMount();
MountedNodeStore getOwningStore(String path) { Mount mount = mip.getMountByPath(path); if (nodeStoresByMount.containsKey(mount)) { return nodeStoresByMount.get(mount); } else { throw new IllegalArgumentException("Unable to find an owning store for path " + path); } }
private void initializeMounts() { fooMount = mip.getMountByName("foo"); roMount = mip.getMountByName("ro"); defaultMount = mip.getDefaultMount(); }
boolean shouldBeComposite(final String path) { boolean supportMounts = false; if (mip.getNonDefaultMounts().stream().anyMatch(m -> m.isSupportFragmentUnder(path))) { supportMounts = true; } else if (!mip.getMountsPlacedUnder(path).isEmpty()) { supportMounts = true; } return supportMounts && mip.getMountByPath(path).isDefault(); }
private List<LuceneIndexReader> createMountedReaders(LuceneIndexDefinition definition, NodeState defnState, String indexPath) throws IOException { ImmutableList.Builder<LuceneIndexReader> readers = ImmutableList.builder(); LuceneIndexReader reader = createReader(mountInfoProvider.getDefaultMount(), definition, defnState, indexPath); //Default mount is the first entry. This ensures that suggester, spellcheck can work on that untill they //support multiple readers if (reader != null) { readers.add(reader); } for (Mount m : mountInfoProvider.getNonDefaultMounts()) { reader = createReader(m, definition, defnState, indexPath); if (reader != null) { readers.add(reader); } } return readers.build(); }
@Test public void mountWithConfig_Paths() throws Exception{ MockOsgi.activate(service, context.bundleContext(), ImmutableMap.<String, Object>of("mountedPaths", new String[] {"/a", "/b"})); MountInfoProvider provider = context.getService(MountInfoProvider.class); assertEquals(1, provider.getNonDefaultMounts().size()); Mount m = provider.getMountByName(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT); assertNotNull(m); Mount defMount = provider.getDefaultMount(); assertNotNull(defMount); assertFalse(m.isReadOnly()); assertEquals(m, provider.getMountByPath("/a")); assertEquals(defMount, provider.getMountByPath("/x")); }
private void checkMountsAreConsistentWithMounts() { int buildMountCount = nonDefaultStores.size(); int mipMountCount = mip.getNonDefaultMounts().size(); checkArgument(buildMountCount == mipMountCount, "Inconsistent mount configuration. Builder received %s mounts, but MountInfoProvider knows about %s.", buildMountCount, mipMountCount); } }
public Builder addMount(String mountName, NodeStore store) { checkNotNull(store, "store"); checkNotNull(mountName, "mountName"); Mount mount = checkNotNull(mip.getMountByName(mountName), "No mount with name %s found in %s", mountName, mip); nonDefaultStores.add(new MountedNodeStore(mount, store)); return this; }
@Test public void nonDefaultMounts() throws Exception{ MountInfoProvider mip = Mounts.newBuilder() .mount("foo", "/a", "/b") .mount("bar", "/x", "/y") .build(); Collection<Mount> mounts = mip.getNonDefaultMounts(); assertEquals(2, mounts.size()); assertFalse(mounts.contains(mip.getDefaultMount())); assertNotNull(mip.getMountByName("foo")); assertNotNull(mip.getMountByName("bar")); assertNull(mip.getMountByName("boom")); }
NodeCounterEditor(NodeCounterRoot root, MountInfoProvider mountInfoProvider) { this.root = root; this.name = "/"; this.parent = null; this.mountInfoProvider = mountInfoProvider; this.currentMount = mountInfoProvider.getDefaultMount(); this.mountCanChange = true; this.countOffsets = new HashMap<>(); }
@Test public void defaultMount() throws Exception { MountInfoProvider mip = new SimpleMountInfoProvider(Collections.<Mount>emptyList()); assertNotNull(mip.getMountByPath("/a")); assertTrue(mip.getMountByPath("/a").isDefault()); assertFalse(mip.hasNonDefaultMounts()); }
static Set<String> getSupportedPaths(@NotNull ConfigurationParameters params, @NotNull MountInfoProvider mountInfoProvider) { Set<String> supportedPaths = params.getConfigValue(CugConstants.PARAM_CUG_SUPPORTED_PATHS, ImmutableSet.of()); if (!supportedPaths.isEmpty() && mountInfoProvider.hasNonDefaultMounts()) { for (Mount mount : mountInfoProvider.getNonDefaultMounts()) { for (String path : supportedPaths) { if (mount.isUnder(path)) { log.error("Configured supported CUG path '{}' includes node store mount '{}'.", path, mount.getName()); throw new IllegalStateException(); } else if (mount.isMounted(path)) { log.error("Configured supported CUG path '{}' is part of node store mount '{}'.", path, mount.getName()); throw new IllegalStateException(); } } } } return supportedPaths; }
@Activate private void activate(BundleContext bundleContext, Map<String, ?> config) { failOnDetection = PropertiesUtil.toBoolean(config.get(PROP_FAIL_ON_DETECTION), true); if (mountInfoProvider.hasNonDefaultMounts()) { serviceRegistration = bundleContext.registerService(EditorProvider.class.getName(), this, null); logger.info("Enabling PrivateStoreValidatorProvider with failOnDetection {}", failOnDetection); } }
@Override public void deleteDocuments(String path) throws IOException { Mount mount = mountInfoProvider.getMountByPath(path); getWriter(mount).deleteDocuments(path); //In case of default mount look for other mounts with roots under this path //Note that one mount cannot be part of another mount if (mount.isDefault()) { //If any mount falls under given path then delete all documents in that for (Mount m : mountInfoProvider.getMountsPlacedUnder(path)) { getWriter(m).deleteAll(); } } }
for (Mount m : mountInfoProvider.getNonDefaultMounts()) { if (!availableMounts.contains(m.getName())) { LOG.info("Composite node store registration is deferred until there's mount {} registered in OSGi", m.getName()); new InitialContentMigrator(globalNs.nodeStore.getNodeStore(), ns.getNodeStoreProvider().getNodeStore(), mountInfoProvider.getMountByName(seedMount)).migrate();
private List<MountedNodeStore> getContributingStores(String path, Function<MountedNodeStore, Iterable<String>> childrenProvider) { Mount owningMount = mip.getMountByPath(path); if (!owningMount.isDefault() && nodeStoresByMount.containsKey(owningMount)) { MountedNodeStore nodeStore = nodeStoresByMount.get(owningMount); if (nodeStore != globalStore) { return singletonList(nodeStore); } } // scenario 2 - multiple mounts participate List<MountedNodeStore> mountedStores = newArrayList(); mountedStores.add(globalStore); // we need mounts placed exactly one level beneath this path Collection<Mount> mounts = mip.getMountsPlacedDirectlyUnder(path); // query the mounts next for (MountedNodeStore mountedNodeStore : nonDefaultStores) { final Mount mount = mountedNodeStore.getMount(); if (mounts.contains(mount)) { mountedStores.add(mountedNodeStore); } else if (hasChildrenContainingPathFragmentName(mountedNodeStore, path, childrenProvider)) { mountedStores.add(mountedNodeStore); } } return mountedStores; }
@Test public void mountsPlacedUnder() { MountInfoProvider mip = Mounts.newBuilder() .mount("first", "/b") .mount("second", "/d", "/b/a") .mount("third", "/h", "/b/c") .build(); Collection<Mount> mountsContainedBetweenPaths = mip.getMountsPlacedUnder("/b"); assertEquals(2, mountsContainedBetweenPaths.size()); } }
@Test public void mountWithConfig_Name() throws Exception{ MockOsgi.activate(service, context.bundleContext(), ImmutableMap.<String, Object>of( "mountedPaths", new String[] {"/a", "/b"}, "mountName", "foo", "readOnlyMount", true )); MountInfoProvider provider = context.getService(MountInfoProvider.class); assertEquals(1, provider.getNonDefaultMounts().size()); Mount m = provider.getMountByName(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT); assertNull(m); Mount defMount = provider.getDefaultMount(); assertNotNull(defMount); m = provider.getMountByName("foo"); assertEquals(m, provider.getMountByPath("/a")); assertEquals(defMount, provider.getMountByPath("/x")); assertTrue(m.isReadOnly()); }
@Override public boolean close(long timestamp) throws IOException { // explicitly get writers for mounts which haven't got writers even at close. // This essentially ensures we respect DefaultIndexWriters#close's intent to // create empty index even if nothing has been written during re-index. stream(concat(singleton(mountInfoProvider.getDefaultMount()), mountInfoProvider.getNonDefaultMounts()) .spliterator(), false) .filter(m -> reindex && !m.isReadOnly()) // only needed when re-indexing for read-write mounts. // reindex for ro-mount doesn't make sense in this case anyway. .forEach(m -> getWriter(m)); // open default writers for mounts that passed all our tests boolean indexUpdated = false; for (LuceneIndexWriter w : writers.values()) { indexUpdated |= w.close(timestamp); } return indexUpdated; }
private boolean supportMounts(String path) { return mountInfoProvider .getNonDefaultMounts() .stream() .anyMatch(m -> m.isSupportFragmentUnder(path) || m.isUnder(path)); }