Author: chetanm
Date: Mon Jul 4 15:26:10 2016
New Revision: 1751312
URL: http://svn.apache.org/viewvc?rev=1751312&view=rev
Log:
OAK-3404 - [multiplex] Path to logical store mapping
Enable OSGi integration. By default the DEFAULT MountInfoProvider would be
registered with OSGi. If some mount info is configured then that
SimpleMountInfoProvider instance would be registered
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfo.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfo.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfo.java?rev=1751312&r1=1751311&r2=1751312&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfo.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfo.java
Mon Jul 4 15:26:10 2016
@@ -19,6 +19,8 @@
package org.apache.jackrabbit.oak.plugins.multiplex;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.List;
import com.google.common.collect.ImmutableList;
@@ -52,4 +54,15 @@ final class MountInfo {
}
return false;
}
+
+ @Override
+ public String toString() {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ pw.print(mount);
+ for (String path : includedPaths) {
+ pw.printf("\t%s%n", path);
+ }
+ return sw.toString();
+ }
}
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java?rev=1751312&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java
Mon Jul 4 15:26:10 2016
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.multiplex;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
+import org.apache.jackrabbit.oak.commons.PropertiesUtil;
+import org.apache.jackrabbit.oak.spi.mount.Mount;
+import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(metatype = true, label = "Apache Jackrabbit Oak MountInfoProvider")
+public class MountInfoProviderService {
+
+ @Property(label = "Mounted paths",
+ unbounded = PropertyUnbounded.ARRAY,
+ description = "Paths which are part of private mount"
+ )
+ private static final String PROP_MOUNT_PATHS = "mountedPaths";
+
+ static final String PROP_MOUNT_NAME_DEFAULT = "private";
+
+ @Property(label = "Mount name",
+ description = "Name of the mount",
+ value = PROP_MOUNT_NAME_DEFAULT
+ )
+ private static final String PROP_MOUNT_NAME = "mountName";
+
+ private static final boolean PROP_MOUNT_READONLY_DEFAULT = false;
+
+ @Property(label = "Readonly",
+ description = "If enabled then mount would be considered as
readonly",
+ boolValue = PROP_MOUNT_READONLY_DEFAULT
+ )
+ private static final String PROP_MOUNT_READONLY = "readOnlyMount";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ServiceRegistration reg;
+
+ @Activate
+ private void activate(BundleContext bundleContext, Map<String, ?> config) {
+ String[] paths =
PropertiesUtil.toStringArray(config.get(PROP_MOUNT_PATHS));
+ String mountName =
PropertiesUtil.toString(config.get(PROP_MOUNT_NAME), PROP_MOUNT_NAME_DEFAULT);
+ boolean readOnly =
PropertiesUtil.toBoolean(config.get(PROP_MOUNT_READONLY),
PROP_MOUNT_READONLY_DEFAULT);
+
+ MountInfoProvider mip = MountInfoProvider.DEFAULT;
+ if (paths != null){
+ Mount mount = new Mount(mountName.trim(), readOnly);
+ List<String> trimmedPaths = new ArrayList<String>(paths.length);
+ for (String path : paths){
+ trimmedPaths.add(path.trim());
+ }
+ MountInfo mi = new MountInfo(mount, trimmedPaths);
+ mip = new SimpleMountInfoProvider(Collections.singletonList(mi));
+ log.info("Enabling mount for {}", mi);
+ } else {
+ log.info("No mount config provided. Mounting would be disabled");
+ }
+
+ reg = bundleContext.registerService(MountInfoProvider.class.getName(),
mip, null);
+ }
+
+ @Deactivate
+ private void deactivate() {
+ if (reg != null) {
+ reg.unregister();
+ reg = null;
+ }
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java?rev=1751312&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java
Mon Jul 4 15:26:10 2016
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.multiplex;
+
+import java.util.Collections;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.jackrabbit.oak.spi.mount.Mount;
+import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class MountInfoProviderServiceTest {
+ @Rule
+ public final OsgiContext context = new OsgiContext();
+
+ private MountInfoProviderService service = new MountInfoProviderService();
+
+ @Test
+ public void defaultSetup() throws Exception{
+ MockOsgi.activate(service, context.bundleContext(),
Collections.<String, Object>emptyMap());
+
+ MountInfoProvider provider =
context.getService(MountInfoProvider.class);
+ assertNotNull(provider);
+ assertEquals(MountInfoProvider.DEFAULT, provider);
+
+ MockOsgi.deactivate(service);
+ assertNull(context.getService(MountInfoProvider.class));
+ }
+
+ @Test
+ public void mountWithConfig_Paths() throws Exception{
+ MockOsgi.activate(service, context.bundleContext(),
+ ImmutableMap.<String, Object>of("mountedPaths", new String[]
{"/a", "/b"}));
+
+ MountInfoProvider provider =
context.getService(MountInfoProvider.class);
+ assertEquals(1, provider.getNonDefaultMounts().size());
+
+ Mount m =
provider.getMount(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT);
+ assertNotNull(m);
+ assertFalse(m.isReadOnly());
+ assertEquals(m, provider.getMountInfo("/a"));
+ assertEquals(Mount.DEFAULT, provider.getMountInfo("/x"));
+ }
+
+ @Test
+ public void mountWithConfig_Name() throws Exception{
+ MockOsgi.activate(service, context.bundleContext(),
+ ImmutableMap.<String, Object>of(
+ "mountedPaths", new String[] {"/a", "/b"},
+ "mountName", "foo",
+ "readOnlyMount", true
+ ));
+
+ MountInfoProvider provider =
context.getService(MountInfoProvider.class);
+ assertEquals(1, provider.getNonDefaultMounts().size());
+
+ Mount m =
provider.getMount(MountInfoProviderService.PROP_MOUNT_NAME_DEFAULT);
+ assertNull(m);
+
+ m = provider.getMount("foo");
+ assertEquals(m, provider.getMountInfo("/a"));
+ assertEquals(Mount.DEFAULT, provider.getMountInfo("/x"));
+ assertTrue(m.isReadOnly());
+ }
+
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/multiplex/MountInfoProviderServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native