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); } }
private boolean supportMounts(String path) { return mountInfoProvider .getNonDefaultMounts() .stream() .anyMatch(m -> m.isSupportFragmentUnder(path) || m.isUnder(path)); }
private boolean supportMounts(String path) { return mountInfoProvider .getNonDefaultMounts() .stream() .anyMatch(m -> m.isSupportFragmentUnder(path) || m.isUnder(path)); }
private boolean supportMounts(String path) { return mountInfoProvider .getNonDefaultMounts() .stream() .anyMatch(m -> m.isSupportFragmentUnder(path) || m.isUnder(path)); }
@Override protected PermissionStore getPermissionStore(Root root, String workspaceName, RestrictionProvider restrictionProvider) { List<PermissionStoreImpl> stores = newArrayList(); stores.add(new PermissionStoreImpl(root, workspaceName, restrictionProvider)); for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String psRoot = getPermissionRootName(m, workspaceName); PermissionStoreImpl ps = new PermissionStoreImpl(root, psRoot, restrictionProvider); stores.add(ps); } return new MountPermissionStore(stores); }
@Override protected PermissionStore getPermissionStore(Root root, String workspaceName, RestrictionProvider restrictionProvider) { List<PermissionStoreImpl> stores = newArrayList(); stores.add(new PermissionStoreImpl(root, workspaceName, restrictionProvider)); for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String psRoot = getPermissionRootName(m, workspaceName); PermissionStoreImpl ps = new PermissionStoreImpl(root, psRoot, restrictionProvider); stores.add(ps); } return new MountPermissionStore(stores); }
@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 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(); }
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(); }
@Override protected PermissionStore getPermissionStore(Root root, String workspaceName, RestrictionProvider restrictionProvider) { List<PermissionStoreImpl> stores = newArrayList(); stores.add(new PermissionStoreImpl(root, workspaceName, restrictionProvider)); for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String psRoot = getPermissionRootName(m, workspaceName); PermissionStoreImpl ps = new PermissionStoreImpl(root, psRoot, restrictionProvider); stores.add(ps); } return new MountPermissionStore(stores); }
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; }
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; }
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); // Although, it shouldn't matter much, but let's not add extra readers if they don't have any docs if (reader != null && reader.getReader() != null && reader.getReader().numDocs() > 0) { readers.add(reader); } } return readers.build(); }
for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String n = getNodeForMount(m, defaultName); names.remove(n);
@Override public void initialize(NodeBuilder builder, String workspaceName) { // property index for rep:principalName stored in ACEs NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder); if (!index.hasChildNode("acPrincipalName")) { NodeBuilder acPrincipalName = IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false, ImmutableList.<String>of(REP_PRINCIPAL_NAME), ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE, NT_REP_ACE)); acPrincipalName.setProperty("info", "Oak index used by authorization to quickly search a principal by name."); } // create the permission store and the root for this workspace. NodeBuilder permissionStore = builder.child(JCR_SYSTEM).child(REP_PERMISSION_STORE); if (!permissionStore.hasProperty(JCR_PRIMARYTYPE)) { permissionStore.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } if (!permissionStore.hasChildNode(workspaceName)) { permissionStore.child(workspaceName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String permissionRootName = MountPermissionProvider.getPermissionRootName(m, workspaceName); if (!permissionStore.hasChildNode(permissionRootName)) { permissionStore.child(permissionRootName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } } }
@Override public void initialize(NodeBuilder builder, String workspaceName) { // property index for rep:principalName stored in ACEs NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder); if (!index.hasChildNode("acPrincipalName")) { NodeBuilder acPrincipalName = IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false, ImmutableList.<String>of(REP_PRINCIPAL_NAME), ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE, NT_REP_ACE)); acPrincipalName.setProperty("info", "Oak index used by authorization to quickly search a principal by name."); } // create the permission store and the root for this workspace. NodeBuilder permissionStore = builder.child(JCR_SYSTEM).child(REP_PERMISSION_STORE); if (!permissionStore.hasProperty(JCR_PRIMARYTYPE)) { permissionStore.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } if (!permissionStore.hasChildNode(workspaceName)) { permissionStore.child(workspaceName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String permissionRootName = MountPermissionProvider.getPermissionRootName(m, workspaceName); if (!permissionStore.hasChildNode(permissionRootName)) { permissionStore.child(permissionRootName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } } }
@Override public void initialize(NodeBuilder builder, String workspaceName) { // property index for rep:principalName stored in ACEs NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder); if (!index.hasChildNode("acPrincipalName")) { NodeBuilder acPrincipalName = IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false, ImmutableList.<String>of(REP_PRINCIPAL_NAME), ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE, NT_REP_ACE)); acPrincipalName.setProperty("info", "Oak index used by authorization to quickly search a principal by name." ); } // create the permission store and the root for this workspace. NodeBuilder permissionStore = builder.child(JCR_SYSTEM).child(REP_PERMISSION_STORE); if (!permissionStore.hasProperty(JCR_PRIMARYTYPE)) { permissionStore.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } if (!permissionStore.hasChildNode(workspaceName)) { permissionStore.child(workspaceName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } for (Mount m : mountInfoProvider.getNonDefaultMounts()) { String permissionRootName = MountPermissionProvider.getPermissionRootName(m, workspaceName); if (!permissionStore.hasChildNode(permissionRootName)) { permissionStore.child(permissionRootName).setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME); } } }
@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")); }
@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")); }
@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()); }