Skip to content

Commit

Permalink
OAK-6773: Convert oak-store-composite to OSGi R7 annotations (#1423)
Browse files Browse the repository at this point in the history
* OAK-6773: Convert oak-store-composite to OSGi R7 annotations

done
  • Loading branch information
mbaedke committed Apr 29, 2024
1 parent dcae752 commit 3efe9f7
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 110 deletions.
9 changes: 7 additions & 2 deletions oak-store-composite/pom.xml
Expand Up @@ -93,8 +93,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<scope>provided</scope>
</dependency>

Expand Down
Expand Up @@ -17,14 +17,15 @@
package org.apache.jackrabbit.oak.composite;

import org.apache.jackrabbit.guava.common.io.Closer;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ComponentPropertyType;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
Expand Down Expand Up @@ -57,7 +58,7 @@
import static org.apache.jackrabbit.guava.common.collect.Sets.newIdentityHashSet;
import static java.util.stream.Collectors.toSet;

@Component(policy = ConfigurationPolicy.REQUIRE)
@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
public class CompositeNodeStoreService {

private static final Logger LOG = LoggerFactory.getLogger(CompositeNodeStoreService.class);
Expand All @@ -66,10 +67,9 @@ public class CompositeNodeStoreService {

private static final String MOUNT_ROLE_PREFIX = "composite-mount-";

@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, policy = ReferencePolicy.STATIC)
@Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.STATIC)
private MountInfoProvider mountInfoProvider;

@Reference(cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, policy = ReferencePolicy.DYNAMIC, bind = "bindNodeStore", unbind = "unbindNodeStore", referenceInterface = NodeStoreProvider.class, target="(!(service.pid=org.apache.jackrabbit.oak.composite.CompositeNodeStore))")
private List<NodeStoreWithProps> nodeStores = new ArrayList<>();

@Reference
Expand All @@ -78,22 +78,26 @@ public class CompositeNodeStoreService {
@Reference
private StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;

@Property(label = "Enable node store checks",
description = "Whether the composite node store constraints should be checked before start",
boolValue = true
)
private static final String ENABLE_CHECKS = "enableChecks";

@Property(label = "Pre-populate seed mount",
description = "Setting this parameter to a mount name will enable pre-populating the empty default store"
)
private static final String PROP_SEED_MOUNT = "seedMount";

@Property(label = "Gather path statistics",
description = "Whether the CompositeNodeStoreStatsMBean should gather information about the most popular paths (may be expensive)",
boolValue = false
)
private static final String PATH_STATS = "pathStats";
@ComponentPropertyType
@interface Config {
@AttributeDefinition(
name = "Enable node store checks",
description = "Whether the composite node store constraints should be checked before start"
)
boolean enableChecks() default true;

@AttributeDefinition(
name = "Pre-populate seed mount",
description = "Setting this parameter to a mount name will enable pre-populating the empty default store"
)
String seedMount();

@AttributeDefinition(
name = "Gather path statistics",
description = "Whether the CompositeNodeStoreStatsMBean should gather information about the most popular paths (may be expensive)"
)
boolean pathStats() default false;
}

private ComponentContext context;

Expand All @@ -112,11 +116,11 @@ public class CompositeNodeStoreService {
private boolean enableChecks;

@Activate
protected void activate(ComponentContext context, Map<String, ?> config) throws IOException, CommitFailedException {
protected void activate(ComponentContext context, Config config) throws IOException, CommitFailedException {
this.context = context;
seedMount = PropertiesUtil.toString(config.get(PROP_SEED_MOUNT), null);
pathStats = PropertiesUtil.toBoolean(config.get(PATH_STATS), false);
enableChecks = PropertiesUtil.toBoolean(config.get(ENABLE_CHECKS), true);
seedMount = config.seedMount();
pathStats = config.pathStats();
enableChecks = config.enableChecks();
registerCompositeNodeStore();
}

Expand Down Expand Up @@ -260,6 +264,7 @@ private void unregisterCompositeNodeStore() throws IOException {
}

@SuppressWarnings("unused")
@Reference(name = "nodeStores", cardinality = ReferenceCardinality.AT_LEAST_ONE, policy = ReferencePolicy.DYNAMIC, service = NodeStoreProvider.class, target="(!(service.pid=org.apache.jackrabbit.oak.composite.CompositeNodeStore))")
protected void bindNodeStore(NodeStoreProvider ns, Map<String, ?> config) throws IOException, CommitFailedException {
NodeStoreWithProps newNs = new NodeStoreWithProps(ns, config);
nodeStores.add(newNs);
Expand Down
Expand Up @@ -16,38 +16,38 @@
*/
package org.apache.jackrabbit.oak.composite;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ComponentPropertyType;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
import org.apache.jackrabbit.oak.spi.commit.Validator;
import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
import org.apache.jackrabbit.oak.spi.mount.Mounts;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.osgi.framework.BundleContext;

import java.util.Map;

/**
* {@link Validator} which detects references crossing the mount boundaries
*/
@Component(label = "Apache Jackrabbit Oak CrossMountReferenceValidatorProvider", policy = ConfigurationPolicy.REQUIRE)
@Property(name = "type", value = "crossMountRefValidator", propertyPrivate = true)
@Service({ValidatorProvider.class, EditorProvider.class})
@Component(configurationPolicy = ConfigurationPolicy.REQUIRE, service = {ValidatorProvider.class, EditorProvider.class})
public class CrossMountReferenceValidatorProvider extends ValidatorProvider {

@Property(
boolValue = true,
label = "Fail when detecting commits cross-mount references",
description = "Commits will fail if set to true when detecting cross-mount references. If set to false the commit information is only logged."
)
private static final String PROP_FAIL_ON_DETECTION = "failOnDetection";
@ComponentPropertyType
@interface Config {
@AttributeDefinition
String type() default "crossMountRefValidator";

@AttributeDefinition(
name = "Fail when detecting commits cross-mount references",
description = "Commits will fail if set to true when detecting cross-mount references. If set to false the commit information is only logged."
)
boolean failOnDetection() default true;
}

private boolean failOnDetection;

@Reference
Expand All @@ -62,8 +62,8 @@ public CrossMountReferenceValidatorProvider(MountInfoProvider mountInfoProvider,
}

@Activate
private void activate(BundleContext bundleContext, Map<String, ?> config) {
failOnDetection = PropertiesUtil.toBoolean(config.get(PROP_FAIL_ON_DETECTION), false);
private void activate(Config config) {
failOnDetection = config.failOnDetection();
}

@Override
Expand Down
Expand Up @@ -17,10 +17,14 @@

package org.apache.jackrabbit.oak.composite;

import org.apache.felix.scr.annotations.*;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ComponentPropertyType;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.spi.commit.*;
import org.apache.jackrabbit.oak.spi.mount.Mount;
import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
Expand All @@ -36,17 +40,20 @@
/**
* {@link Validator} which detects change commits to the read only mounts.
*/
@Component(label = "Apache Jackrabbit Oak PrivateStoreValidatorProvider")
@Component
public class PrivateStoreValidatorProvider extends ValidatorProvider {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final String ROOT_PATH = "/";

@Property(
boolValue = true,
label = "Fail when detecting commits to the read-only stores",
description = "Commits will fail if set to true when detecting changes to any read-only store. If set to false the commit information is only logged."
)
private static final String PROP_FAIL_ON_DETECTION = "failOnDetection";
@ComponentPropertyType
@interface Config {
@AttributeDefinition(
name = "Fail when detecting commits to the read-only stores",
description = "Commits will fail if set to true when detecting changes to any read-only store. If set to false the commit information is only logged."
)
boolean failOnDetection() default true;
}

private boolean failOnDetection;

@Reference
Expand All @@ -60,8 +67,8 @@ public Validator getRootValidator(NodeState before, NodeState after, CommitInfo
}

@Activate
private void activate(BundleContext bundleContext, Map<String, ?> config) {
failOnDetection = PropertiesUtil.toBoolean(config.get(PROP_FAIL_ON_DETECTION), true);
private void activate(BundleContext bundleContext, Config config) {
failOnDetection = config.failOnDetection();

if (mountInfoProvider.hasNonDefaultMounts()) {
serviceRegistration = bundleContext.registerService(EditorProvider.class.getName(), this, null);
Expand Down
Expand Up @@ -18,8 +18,7 @@

import java.util.Set;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Component;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
Expand All @@ -32,8 +31,7 @@

import org.apache.jackrabbit.guava.common.collect.Sets;

@Component
@Service(MountedNodeStoreChecker.class)
@Component(service={MountedNodeStoreChecker.class})
public class NamespacePrefixNodestoreChecker implements MountedNodeStoreChecker<NamespacePrefixNodestoreChecker.Context> {

@Override
Expand Down
Expand Up @@ -19,10 +19,9 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.composite.MountedNodeStore;
import org.apache.jackrabbit.oak.plugins.tree.factories.TreeFactory;
Expand All @@ -32,16 +31,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service(NodeStoreChecks.class)
@Component(service = {NodeStoreChecks.class})
public class NodeStoreChecksService implements NodeStoreChecks {

private final Logger log = LoggerFactory.getLogger(getClass());

@Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
@Reference(cardinality = ReferenceCardinality.MULTIPLE,
bind = "bindChecker",
unbind = "unbindChecker",
referenceInterface = MountedNodeStoreChecker.class)
service = MountedNodeStoreChecker.class)
private List<MountedNodeStoreChecker<?>> checkers = new CopyOnWriteArrayList<>();

@Reference
Expand Down
Expand Up @@ -26,8 +26,7 @@
import java.util.List;
import java.util.Set;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Component;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.Tree;
Expand All @@ -48,8 +47,7 @@
/**
* Checks that nodes present in a mount are consistent with the global node type definitions
*/
@Component
@Service(MountedNodeStoreChecker.class)
@Component(service = {MountedNodeStoreChecker.class})
public class NodeTypeDefinitionNodeStoreChecker implements MountedNodeStoreChecker<NodeTypeDefinitionNodeStoreChecker.Context> {

@Override
Expand Down

0 comments on commit 3efe9f7

Please sign in to comment.