Search in sources :

Example 1 with RepositoryInitializer

use of org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer in project jackrabbit-oak by apache.

the class Jcr method setUpOak.

private void setUpOak() {
    // whiteboard
    if (whiteboard != null) {
        oak.with(whiteboard);
    }
    // repository initializers
    for (RepositoryInitializer repositoryInitializer : repositoryInitializers) {
        oak.with(repositoryInitializer);
    }
    // query index providers
    for (QueryIndexProvider queryIndexProvider : queryIndexProviders) {
        oak.with(queryIndexProvider);
    }
    // commit hooks
    for (CommitHook commitHook : commitHooks) {
        oak.with(commitHook);
    }
    // conflict handlers
    oak.with(conflictHandler);
    // index editor providers
    for (IndexEditorProvider indexEditorProvider : indexEditorProviders) {
        oak.with(indexEditorProvider);
    }
    // editors
    for (Editor editor : editors) {
        oak.with(editor);
    }
    // editor providers
    for (EditorProvider editorProvider : editorProviders) {
        oak.with(editorProvider);
    }
    // securityProvider
    oak.with(securityProvider);
    // executors
    if (scheduledExecutor != null) {
        oak.with(scheduledExecutor);
    }
    if (executor != null) {
        oak.with(executor);
    }
    // observers
    for (Observer observer : observers) {
        oak.with(observer);
    }
    // commit rate limiter
    if (commitRateLimiter != null) {
        oak.with(commitRateLimiter);
    }
    // query engine settings
    if (queryEngineSettings != null) {
        oak.with(queryEngineSettings);
    }
    // default workspace name
    if (defaultWorkspaceName != null) {
        oak.with(defaultWorkspaceName);
    }
    if (clusterable != null) {
        oak.with(clusterable);
    }
}
Also used : CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) BackgroundObserver(org.apache.jackrabbit.oak.spi.commit.BackgroundObserver) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) OrderedPropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) OrderedPropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) NodeCounterEditorProvider(org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider) NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)

Example 2 with RepositoryInitializer

use of org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer in project jackrabbit-oak by apache.

the class RepeatedRepositoryUpgradeTest method doUpgradeRepository.

protected void doUpgradeRepository(File source, NodeStore target, boolean skipInit) throws RepositoryException, IOException {
    final RepositoryConfig config = RepositoryConfig.create(source);
    final RepositoryContext context = RepositoryContext.create(config);
    try {
        final RepositoryUpgrade repositoryUpgrade = new RepositoryUpgrade(context, target);
        repositoryUpgrade.setSkipInitialization(skipInit);
        repositoryUpgrade.copy(new RepositoryInitializer() {

            @Override
            public void initialize(@Nonnull NodeBuilder builder) {
                builder.child("foo").child("bar");
            }
        });
    } finally {
        context.getRepository().shutdown();
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) RepositoryContext(org.apache.jackrabbit.core.RepositoryContext) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 3 with RepositoryInitializer

use of org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer 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();
        SecurityProviderImpl security = new SecurityProviderImpl(mapSecurityConfig(config.getSecurityConfig()));
        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.wrap(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);
        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.upgrade.nodestate.report.ReportingNodeState) 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.upgrade.nodestate.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) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) 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) 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) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer)

Example 4 with RepositoryInitializer

use of org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer in project jackrabbit-oak by apache.

the class PropertyIndexQueryTest method testInvalidNamespace.

@Ignore("OAK-1517")
@Test
public void testInvalidNamespace() throws Exception {
    new Oak().with(new InitialContent()).with(new OpenSecurityProvider()).with(new PropertyIndexEditorProvider()).with(new RepositoryInitializer() {

        @Override
        public void initialize(@Nonnull NodeBuilder builder) {
            createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("illegal:namespaceProperty"), null);
        }
    }).createContentRepository();
    fail("creating an index definition with an illegal namespace should fail.");
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Nonnull(javax.annotation.Nonnull) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 5 with RepositoryInitializer

use of org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer in project jackrabbit-oak by apache.

the class RepositoryManager method registerRepository.

private ServiceRegistration registerRepository(BundleContext bundleContext) {
    Oak oak = new Oak(store).with(new InitialContent()).with(new VersionHook()).with(JcrConflictHandler.createJcrConflictHandler()).with(whiteboard).with(securityProvider).with(editorProvider).with(indexEditorProvider).with(indexProvider).withFailOnMissingIndexProvider().withAsyncIndexing();
    for (RepositoryInitializer initializer : initializers.getServices()) {
        oak.with(initializer);
    }
    if (commitRateLimiter != null) {
        oak.with(commitRateLimiter);
    }
    repository = new OsgiRepository(oak.createContentRepository(), whiteboard, securityProvider, observationQueueLength, commitRateLimiter, fastQueryResultSize);
    return bundleContext.registerService(Repository.class.getName(), repository, new Properties());
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Repository(javax.jcr.Repository) Oak(org.apache.jackrabbit.oak.Oak) VersionHook(org.apache.jackrabbit.oak.plugins.version.VersionHook) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) Properties(java.util.Properties)

Aggregations

RepositoryInitializer (org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer)5 InitialContent (org.apache.jackrabbit.oak.InitialContent)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 RepositoryConfig (org.apache.jackrabbit.core.config.RepositoryConfig)2 Oak (org.apache.jackrabbit.oak.Oak)2 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)2 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)2 ReferenceEditorProvider (org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider)2 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)2 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)2 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 Nonnull (javax.annotation.Nonnull)1 NamespaceException (javax.jcr.NamespaceException)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 RepositoryContext (org.apache.jackrabbit.core.RepositoryContext)1