Search in sources :

Example 1 with CompositeEditorProvider

use of org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider in project jackrabbit-oak by apache.

the class CrossMountReferenceValidatorTest method initializeHook.

@Before
public void initializeHook() {
    MountInfoProvider mip = Mounts.newBuilder().mount("foo", "/a").build();
    hook = new EditorHook(new CompositeEditorProvider(new IndexUpdateProvider(new CompositeIndexEditorProvider(new PropertyIndexEditorProvider().with(mip), new ReferenceEditorProvider().with(mip))), new CrossMountReferenceValidatorProvider().with(mip).withFailOnDetection(true)));
}
Also used : ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) Before(org.junit.Before)

Example 2 with CompositeEditorProvider

use of org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider in project jackrabbit-oak by apache.

the class InitialContent method initialize.

@Override
public void initialize(@Nonnull NodeBuilder builder) {
    builder.setProperty(JCR_PRIMARYTYPE, NT_REP_ROOT, Type.NAME);
    if (!builder.hasChildNode(JCR_SYSTEM)) {
        NodeBuilder system = builder.child(JCR_SYSTEM);
        system.setProperty(JCR_PRIMARYTYPE, NT_REP_SYSTEM, Type.NAME);
        system.child(JCR_VERSIONSTORAGE).setProperty(JCR_PRIMARYTYPE, REP_VERSIONSTORAGE, Type.NAME);
        system.child(JCR_NODE_TYPES).setProperty(JCR_PRIMARYTYPE, NT_REP_NODE_TYPES, Type.NAME);
        system.child(VersionConstants.JCR_ACTIVITIES).setProperty(JCR_PRIMARYTYPE, VersionConstants.REP_ACTIVITIES, Type.NAME);
        Namespaces.setupNamespaces(system);
    }
    NodeBuilder versionStorage = builder.child(JCR_SYSTEM).child(JCR_VERSIONSTORAGE);
    if (prePopulateVS && !isInitialized(versionStorage)) {
        createIntermediateNodes(versionStorage);
    }
    if (!builder.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
        NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
        NodeBuilder uuid = IndexUtils.createIndexDefinition(index, "uuid", true, true, ImmutableList.<String>of(JCR_UUID), null);
        uuid.setProperty("info", "Oak index for UUID lookup (direct lookup of nodes with the mixin 'mix:referenceable').");
        NodeBuilder nodetype = IndexUtils.createIndexDefinition(index, "nodetype", true, false, ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES), null);
        nodetype.setProperty("info", "Oak index for queries with node type, and possibly path restrictions, " + "for example \"/jcr:root/content//element(*, mix:language)\".");
        IndexUtils.createReferenceIndex(index);
        index.child("counter").setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME).setProperty(TYPE_PROPERTY_NAME, NodeCounterEditorProvider.TYPE).setProperty(IndexConstants.ASYNC_PROPERTY_NAME, IndexConstants.ASYNC_PROPERTY_NAME).setProperty("info", "Oak index that allows to estimate " + "how many nodes are stored below a given path, " + "to decide whether traversing or using an index is faster.");
    }
    // squeeze node state before it is passed to store (OAK-2411)
    NodeState base = squeeze(builder.getNodeState());
    NodeStore store = new MemoryNodeStore(base);
    registerBuiltIn(RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null));
    NodeState target = store.getRoot();
    target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 3 with CompositeEditorProvider

use of org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider in project jackrabbit-oak by apache.

the class TestUtil method registerNodeType.

public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn) {
    // Taken from org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent
    NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
    NodeStore store = new MemoryNodeStore(base);
    Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null);
    NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types");
    NodeState target = store.getRoot();
    target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) ModifiedNodeState(org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Root(org.apache.jackrabbit.oak.api.Root) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook)

Example 4 with CompositeEditorProvider

use of org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider in project jackrabbit-oak by apache.

the class LuceneIndexAggregation2Test method createRepository.

@Override
protected ContentRepository createRepository() {
    LuceneIndexProvider provider = new LuceneIndexProvider();
    return new Oak().with(new InitialContent() {

        @Override
        public void initialize(@Nonnull NodeBuilder builder) {
            super.initialize(builder);
            // registering additional node types for wider testing
            InputStream stream = null;
            try {
                stream = LuceneIndexAggregation2Test.class.getResourceAsStream("test_nodetypes.cnd");
                NodeState base = builder.getNodeState();
                NodeStore store = new MemoryNodeStore(base);
                Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null);
                NodeTypeRegistry.register(root, stream, "testing node types");
                NodeState target = store.getRoot();
                target.compareAgainstBaseState(base, new ApplyDiff(builder));
            } catch (Exception e) {
                LOG.error("Error while registering required node types. Failing here", e);
                fail("Error while registering required node types");
            } finally {
                printNodeTypes(builder);
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                        LOG.debug("Ignoring exception on stream closing.", e);
                    }
                }
            }
        }
    }).with(new OpenSecurityProvider()).with(((QueryIndexProvider) provider.with(getNodeAggregator()))).with((Observer) provider).with(new LuceneIndexEditorProvider()).createContentRepository();
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) InputStream(java.io.InputStream) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) IOException(java.io.IOException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IOException(java.io.IOException) InitialContent(org.apache.jackrabbit.oak.InitialContent) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Oak(org.apache.jackrabbit.oak.Oak)

Example 5 with CompositeEditorProvider

use of org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider in project jackrabbit-oak by apache.

the class RepositoryUpgrade method copy.

/**
 * Copies the full content from the source to the target repository.
 * <p>
 * The source repository <strong>must not be modified</strong> while
 * the copy operation is running to avoid an inconsistent copy.
 * <p>
 * Note that both the source and the target repository must be closed
 * during the copy operation as this method requires exclusive access
 * to the repositories.
 *
 * @param initializer optional extra repository initializer to use
 * @throws RepositoryException if the copy operation fails
 */
public void copy(RepositoryInitializer initializer) throws RepositoryException {
    if (checkLongNames) {
        assertNoLongNames();
    }
    RepositoryConfig config = source.getRepositoryConfig();
    logger.info("Copying repository content from {} to Oak", config.getHomeDir());
    try {
        NodeBuilder targetBuilder = target.getRoot().builder();
        if (VersionHistoryUtil.getVersionStorage(targetBuilder).exists() && !versionCopyConfiguration.skipOrphanedVersionsCopy()) {
            logger.warn("The version storage on destination already exists. Orphaned version histories will be skipped.");
            versionCopyConfiguration.setCopyOrphanedVersions(null);
        }
        final Root upgradeRoot = new UpgradeRoot(targetBuilder);
        String workspaceName = source.getRepositoryConfig().getDefaultWorkspaceName();
        SecurityProvider security = SecurityProviderBuilder.newBuilder().with(mapSecurityConfig(config.getSecurityConfig())).build();
        if (skipInitialization) {
            logger.info("Skipping the repository initialization");
        } else {
            // init target repository first
            logger.info("Initializing initial repository content from {}", config.getHomeDir());
            new InitialContent().initialize(targetBuilder);
            if (initializer != null) {
                initializer.initialize(targetBuilder);
            }
            logger.debug("InitialContent completed from {}", config.getHomeDir());
            for (SecurityConfiguration sc : security.getConfigurations()) {
                RepositoryInitializer ri = sc.getRepositoryInitializer();
                ri.initialize(targetBuilder);
                logger.debug("Repository initializer '" + ri.getClass().getName() + "' completed", config.getHomeDir());
            }
            for (SecurityConfiguration sc : security.getConfigurations()) {
                WorkspaceInitializer wi = sc.getWorkspaceInitializer();
                wi.initialize(targetBuilder, workspaceName);
                logger.debug("Workspace initializer '" + wi.getClass().getName() + "' completed", config.getHomeDir());
            }
        }
        HashBiMap<String, String> uriToPrefix = HashBiMap.create();
        logger.info("Copying registered namespaces");
        copyNamespaces(targetBuilder, uriToPrefix);
        logger.debug("Namespace registration completed.");
        if (skipInitialization) {
            logger.info("Skipping registering node types and privileges");
        } else {
            logger.info("Copying registered node types");
            NodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {

                @Override
                protected Tree getTypes() {
                    return upgradeRoot.getTree(NODE_TYPES_PATH);
                }

                @Nonnull
                @Override
                protected Root getWriteRoot() {
                    return upgradeRoot;
                }
            };
            copyNodeTypes(ntMgr, new ValueFactoryImpl(upgradeRoot, NamePathMapper.DEFAULT));
            logger.debug("Node type registration completed.");
            // migrate privileges
            logger.info("Copying registered privileges");
            PrivilegeConfiguration privilegeConfiguration = security.getConfiguration(PrivilegeConfiguration.class);
            copyCustomPrivileges(privilegeConfiguration.getPrivilegeManager(upgradeRoot, NamePathMapper.DEFAULT));
            logger.debug("Privilege registration completed.");
            // Triggers compilation of type information, which we need for
            // the type predicates used by the bulk  copy operations below.
            new TypeEditorProvider(false).getRootEditor(targetBuilder.getBaseState(), targetBuilder.getNodeState(), targetBuilder, null);
        }
        final NodeState reportingSourceRoot = ReportingNodeState.wrap(JackrabbitNodeState.createRootNodeState(source, workspaceName, targetBuilder.getNodeState(), uriToPrefix, copyBinariesByReference, skipOnError), new LoggingReporter(logger, "Migrating", LOG_NODE_COPY, -1));
        final NodeState sourceRoot;
        if (filterLongNames) {
            sourceRoot = NameFilteringNodeState.wrapRoot(reportingSourceRoot);
        } else {
            sourceRoot = reportingSourceRoot;
        }
        final Stopwatch watch = Stopwatch.createStarted();
        logger.info("Copying workspace content");
        copyWorkspace(sourceRoot, targetBuilder, workspaceName);
        // on TarMK this does call triggers the actual copy
        targetBuilder.getNodeState();
        logger.info("Upgrading workspace content completed in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) {
            logger.info("Copying version storage");
            watch.reset().start();
            copyVersionStorage(targetBuilder, getVersionStorage(sourceRoot), getVersionStorage(targetBuilder), versionCopyConfiguration);
            // on TarMK this does call triggers the actual copy
            targetBuilder.getNodeState();
            logger.info("Version storage copied in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        } else {
            logger.info("Skipping the version storage as the copyOrphanedVersions is set to false");
        }
        watch.reset().start();
        logger.info("Applying default commit hooks");
        // TODO: default hooks?
        List<CommitHook> hooks = newArrayList();
        UserConfiguration userConf = security.getConfiguration(UserConfiguration.class);
        String groupsPath = userConf.getParameters().getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH);
        String usersPath = userConf.getParameters().getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
        // hooks specific to the upgrade, need to run first
        hooks.add(new EditorHook(new CompositeEditorProvider(new RestrictionEditorProvider(), new GroupEditorProvider(groupsPath), // copy referenced version histories
        new VersionableEditor.Provider(sourceRoot, workspaceName, versionCopyConfiguration), new SameNameSiblingsEditor.Provider(), AuthorizableFolderEditor.provider(groupsPath, usersPath))));
        // this editor works on the VersionableEditor output, so it can't be
        // a part of the same EditorHook
        hooks.add(new EditorHook(new VersionablePropertiesEditor.Provider()));
        // security-related hooks
        for (SecurityConfiguration sc : security.getConfigurations()) {
            hooks.addAll(sc.getCommitHooks(workspaceName));
        }
        if (customCommitHooks != null) {
            hooks.addAll(customCommitHooks);
        }
        // type validation, reference and indexing hooks
        hooks.add(new EditorHook(new CompositeEditorProvider(createTypeEditorProvider(), createIndexEditorProvider())));
        target.merge(targetBuilder, new LoggingCompositeHook(hooks, source, overrideEarlyShutdown()), CommitInfo.EMPTY);
        logger.info("Processing commit hooks completed in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        removeVersions();
        logger.debug("Repository upgrade completed.");
    } catch (Exception e) {
        throw new RepositoryException("Failed to copy content", e);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) NameFilteringNodeState(org.apache.jackrabbit.oak.upgrade.nodestate.NameFilteringNodeState) ReportingNodeState(org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState) FilteringNodeState(org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) Stopwatch(com.google.common.base.Stopwatch) LoggingReporter(org.apache.jackrabbit.oak.plugins.migration.report.LoggingReporter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) VersionableEditor(org.apache.jackrabbit.oak.upgrade.version.VersionableEditor) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) RestrictionEditorProvider(org.apache.jackrabbit.oak.upgrade.security.RestrictionEditorProvider) Root(org.apache.jackrabbit.oak.api.Root) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) RepositoryException(javax.jcr.RepositoryException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) RestrictionEditorProvider(org.apache.jackrabbit.oak.upgrade.security.RestrictionEditorProvider) GroupEditorProvider(org.apache.jackrabbit.oak.upgrade.security.GroupEditorProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) InitialContent(org.apache.jackrabbit.oak.InitialContent) WorkspaceInitializer(org.apache.jackrabbit.oak.spi.lifecycle.WorkspaceInitializer) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) GroupEditorProvider(org.apache.jackrabbit.oak.upgrade.security.GroupEditorProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer)

Aggregations

CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)6 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 Root (org.apache.jackrabbit.oak.api.Root)4 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)4 NamespaceEditorProvider (org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider)4 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)4 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)4 IOException (java.io.IOException)3 InitialContent (org.apache.jackrabbit.oak.InitialContent)3 InputStream (java.io.InputStream)2 Nonnull (javax.annotation.Nonnull)2 Oak (org.apache.jackrabbit.oak.Oak)2 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)2 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)2 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)2 FilteringNodeState (org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState)2 ReportingNodeState (org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState)2