Search in sources :

Example 56 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class S3DataStoreStatsTest method initNodeStore.

private static NodeStore initNodeStore(final Optional<Blob> blobProp1, final Optional<Blob> blobProp2, final Optional<String> stringProp, final Optional<Integer> intProp, final Optional<List<Blob>> blobPropList) throws CommitFailedException {
    final NodeStore nodeStore = new MemoryNodeStore();
    NodeBuilder rootBuilder = nodeStore.getRoot().builder();
    NodeBuilder builder = initNodeBuilder(rootBuilder);
    if (blobProp1.isPresent()) {
        builder.setProperty("blobProp1", blobProp1.get());
    }
    if (blobProp2.isPresent()) {
        builder.setProperty("blobProp2", blobProp2.get());
    }
    if (stringProp.isPresent()) {
        builder.setProperty("stringProp", stringProp.get());
    }
    if (intProp.isPresent()) {
        builder.setProperty("intProp", intProp.get());
    }
    if (blobPropList.isPresent()) {
        builder.setProperty(MultiBinaryPropertyState.binaryPropertyFromBlob("blobPropList", blobPropList.get()));
    }
    nodeStore.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    return nodeStore;
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 57 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class UserInitializer method initialize.

//-----------------------------------------------< WorkspaceInitializer >---
@Override
public void initialize(NodeBuilder builder, String workspaceName) {
    // squeeze node state before it is passed to store (OAK-2411)
    NodeState base = squeeze(builder.getNodeState());
    MemoryNodeStore store = new MemoryNodeStore(base);
    Root root = RootFactory.createSystemRoot(store, EmptyHook.INSTANCE, workspaceName, securityProvider, null, new CompositeQueryIndexProvider(new PropertyIndexProvider(), new NodeTypeIndexProvider()));
    UserConfiguration userConfiguration = securityProvider.getConfiguration(UserConfiguration.class);
    UserManager userManager = userConfiguration.getUserManager(root, NamePathMapper.DEFAULT);
    String errorMsg = "Failed to initialize user content.";
    try {
        Tree rootTree = root.getTree(PathUtils.ROOT_PATH);
        checkState(rootTree.exists());
        Tree index = TreeUtil.getOrAddChild(rootTree, IndexConstants.INDEX_DEFINITIONS_NAME, JcrConstants.NT_UNSTRUCTURED);
        if (!index.hasChild("authorizableId")) {
            Tree authorizableId = IndexUtils.createIndexDefinition(index, "authorizableId", true, new String[] { REP_AUTHORIZABLE_ID }, new String[] { NT_REP_AUTHORIZABLE });
            authorizableId.setProperty("info", "Oak index used by the user management " + "to enforce uniqueness of rep:authorizableId property values.");
        }
        if (!index.hasChild("principalName")) {
            Tree principalName = IndexUtils.createIndexDefinition(index, "principalName", true, new String[] { REP_PRINCIPAL_NAME }, new String[] { NT_REP_AUTHORIZABLE });
            principalName.setProperty("info", "Oak index used by the user management " + "to enforce uniqueness of rep:principalName property values, " + "and to quickly search a principal by name if it was constructed manually.");
        }
        if (!index.hasChild("repMembers")) {
            Tree members = IndexUtils.createIndexDefinition(index, "repMembers", false, new String[] { REP_MEMBERS }, new String[] { NT_REP_MEMBER_REFERENCES });
            members.setProperty("info", "Oak index used by the user management to lookup group membership.");
        }
        ConfigurationParameters params = userConfiguration.getParameters();
        String adminId = params.getConfigValue(PARAM_ADMIN_ID, DEFAULT_ADMIN_ID);
        if (userManager.getAuthorizable(adminId) == null) {
            boolean omitPw = params.getConfigValue(PARAM_OMIT_ADMIN_PW, false);
            userManager.createUser(adminId, (omitPw) ? null : adminId);
        }
        String anonymousId = Strings.emptyToNull(params.getConfigValue(PARAM_ANONYMOUS_ID, DEFAULT_ANONYMOUS_ID, String.class));
        if (anonymousId != null && userManager.getAuthorizable(anonymousId) == null) {
            userManager.createUser(anonymousId, null);
        }
        if (root.hasPendingChanges()) {
            root.commit();
        }
    } catch (RepositoryException | CommitFailedException e) {
        log.error(errorMsg, e);
        throw new RuntimeException(e);
    }
    NodeState target = store.getRoot();
    target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Also used : ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeTypeIndexProvider(org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider) Root(org.apache.jackrabbit.oak.api.Root) CompositeQueryIndexProvider(org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider) RepositoryException(javax.jcr.RepositoryException) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)

Example 58 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class ExternalIdentityRepositoryInitializer method initialize.

@Override
public void initialize(@Nonnull NodeBuilder builder) {
    NodeState base = builder.getNodeState();
    NodeStore store = new MemoryNodeStore(base);
    String errorMsg = "Failed to initialize external identity content.";
    try {
        Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null, null);
        // create index definition for "rep:externalId" and "rep:externalPrincipalNames"
        Tree rootTree = root.getTree(PathUtils.ROOT_PATH);
        checkState(rootTree.exists());
        Tree index = TreeUtil.getOrAddChild(rootTree, IndexConstants.INDEX_DEFINITIONS_NAME, JcrConstants.NT_UNSTRUCTURED);
        if (enforceUniqueIds && !index.hasChild("externalId")) {
            Tree definition = IndexUtils.createIndexDefinition(index, "externalId", true, new String[] { ExternalIdentityConstants.REP_EXTERNAL_ID });
            definition.setProperty("info", "Oak index assuring uniqueness of rep:externalId properties.");
        }
        if (!index.hasChild("externalPrincipalNames")) {
            Tree definition = IndexUtils.createIndexDefinition(index, "externalPrincipalNames", false, new String[] { ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES });
            definition.setProperty("info", "Oak index used by the principal management provided by the external authentication module.");
        }
        if (root.hasPendingChanges()) {
            root.commit();
        }
    } catch (RepositoryException e) {
        log.error(errorMsg, e);
        throw new RuntimeException(e);
    } catch (CommitFailedException e) {
        log.error(errorMsg, e);
        throw new RuntimeException(e);
    }
    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) Root(org.apache.jackrabbit.oak.api.Root) RepositoryException(javax.jcr.RepositoryException) 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) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 59 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class CompositeStoreFixture method getNodeStore.

private NodeStore getNodeStore() throws IOException, InvalidFileStoreVersionException {
    if (inMemory) {
        return new MemoryNodeStore();
    }
    FileStoreBuilder fsBuilder = fileStoreBuilder(new File(base, unique)).withMaxFileSize(maxFileSizeMB).withSegmentCacheSize(cacheSizeMB).withMemoryMapping(memoryMapping);
    fileStore = fsBuilder.build();
    return SegmentNodeStoreBuilders.builder(fileStore).build();
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) File(java.io.File)

Example 60 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class OakFixture method getMemory.

public static OakFixture getMemory(String name, final long cacheSize) {
    return new OakFixture(name) {

        @Override
        public Oak getOak(int clusterId) throws Exception {
            Oak oak;
            oak = newOak(new MemoryNodeStore());
            return oak;
        }

        @Override
        public Oak[] setUpCluster(int n, StatisticsProvider statsProvider) throws Exception {
            Oak[] cluster = new Oak[n];
            for (int i = 0; i < cluster.length; i++) {
                Oak oak;
                oak = newOak(new MemoryNodeStore());
                cluster[i] = oak;
            }
            return cluster;
        }

        @Override
        public void tearDownCluster() {
        // nothing to do
        }
    };
}
Also used : MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Oak(org.apache.jackrabbit.oak.Oak) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider)

Aggregations

MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)92 Test (org.junit.Test)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)58 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)37 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)35 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)33 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)13 Oak (org.apache.jackrabbit.oak.Oak)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)7 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 InitialContent (org.apache.jackrabbit.oak.InitialContent)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Validator (org.apache.jackrabbit.oak.spi.commit.Validator)6 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)6 Semaphore (java.util.concurrent.Semaphore)5