Search in sources :

Example 21 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project sling by apache.

the class RepositoryTestHelper method createOakRepository.

public static Repository createOakRepository(NodeStore nodeStore) {
    DefaultWhiteboard whiteboard = new DefaultWhiteboard();
    final Oak oak = new Oak(nodeStore).with(new InitialContent()).with(JcrConflictHandler.createJcrConflictHandler()).with(new EditorHook(new VersionEditorProvider())).with(new OpenSecurityProvider()).with(new NamespaceEditorProvider()).with(new TypeEditorProvider()).with(new ConflictValidatorProvider()).with(//getDefaultWorkspace())
    "default").with(whiteboard);
    //        if (commitRateLimiter != null) {
    //            oak.with(commitRateLimiter);
    //        }
    final ContentRepository contentRepository = oak.createContentRepository();
    return new RepositoryImpl(contentRepository, whiteboard, new OpenSecurityProvider(), 1000, null);
}
Also used : InitialContent(org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent) NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) RepositoryImpl(org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl) Oak(org.apache.jackrabbit.oak.Oak) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) VersionEditorProvider(org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)

Example 22 with EditorHook

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

the class AsyncIndexUpdate method mergeWithConcurrencyCheck.

private static void mergeWithConcurrencyCheck(final NodeStore store, List<ValidatorProvider> validatorProviders, NodeBuilder builder, final String checkpoint, final Long lease, final String name) throws CommitFailedException {
    CommitHook concurrentUpdateCheck = new CommitHook() {

        @Override
        @Nonnull
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            // check for concurrent updates by this async task
            NodeState async = before.getChildNode(ASYNC);
            if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) {
                return after;
            } else {
                throw newConcurrentUpdateException();
            }
        }
    };
    List<EditorProvider> editorProviders = Lists.newArrayList();
    editorProviders.add(new ConflictValidatorProvider());
    editorProviders.addAll(validatorProviders);
    CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(editorProviders)), concurrentUpdateCheck);
    try {
        store.merge(builder, hooks, createCommitInfo());
    } catch (CommitFailedException ex) {
        // OAK-2961
        if (ex.isOfType(CommitFailedException.STATE) && ex.getCode() == 1) {
            throw newConcurrentUpdateException();
        } else {
            throw ex;
        }
    }
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) AnnotatingConflictHandler(org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 23 with EditorHook

use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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 24 with EditorHook

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

the class Oak method withEditorHook.

/**
 * Turns all currently tracked editors to an editor commit hook and
 * associates that hook with the repository to be created. This way
 * a sequence of {@code with()} calls that alternates between editors
 * and other commit hooks will have all the editors in the correct
 * order while still being able to leverage the performance gains of
 * multiple editors iterating over the changes simultaneously.
 */
private void withEditorHook() {
    if (!editorProviders.isEmpty()) {
        commitHooks.add(new EditorHook(CompositeEditorProvider.compose(editorProviders)));
        editorProviders = newArrayList();
    }
}
Also used : EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook)

Example 25 with EditorHook

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

the class MutableRoot method getCommitHook.

/**
 * Combine the globally defined commit hook(s) and the hooks and validators defined by the
 * various security related configurations.
 *
 * @return A commit hook combining repository global commit hook(s) with the pluggable hooks
 *         defined with the security modules and the padded {@code hooks}.
 */
private CommitHook getCommitHook() {
    List<CommitHook> hooks = newArrayList();
    hooks.add(ResetCommitAttributeHook.INSTANCE);
    hooks.add(hook);
    List<CommitHook> postValidationHooks = new ArrayList<CommitHook>();
    List<ValidatorProvider> validators = new ArrayList<>();
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        for (CommitHook ch : sc.getCommitHooks(workspaceName)) {
            if (ch instanceof PostValidationHook) {
                postValidationHooks.add(ch);
            } else if (ch != EmptyHook.INSTANCE) {
                hooks.add(ch);
            }
        }
        validators.addAll(sc.getValidators(workspaceName, subject.getPrincipals(), moveTracker));
    }
    if (!validators.isEmpty()) {
        hooks.add(new EditorHook(CompositeEditorProvider.compose(validators)));
    }
    hooks.addAll(postValidationHooks);
    return CompositeHook.compose(hooks);
}
Also used : CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PostValidationHook(org.apache.jackrabbit.oak.spi.commit.PostValidationHook) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider)

Aggregations

EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)69 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)46 Test (org.junit.Test)44 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)43 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)24 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)11 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)11 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)11 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)11 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)8 AnnotatingConflictHandler (org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler)7 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)7 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)7 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)7 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)6 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)6 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)6 Before (org.junit.Before)6