jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1461196 - in /jackrabbit/oak/trunk/oak-solr-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/ test/java/org/apache/jackrabbit/oak/plugins/index/solr/ test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/
Date Tue, 26 Mar 2013 16:00:32 GMT
Author: tommaso
Date: Tue Mar 26 16:00:32 2013
New Revision: 1461196

URL: http://svn.apache.org/r1461196
Log:
OAK-720 - made OakNodeStateConfiguration abstract and created Fixed and UpToDate extensions

Added:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java?rev=1461196&r1=1461195&r2=1461196&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/DefaultOakSolrProvider.java
Tue Mar 26 16:00:32 2013
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfigurationProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.SolrServerProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
 import org.apache.solr.core.CoreContainer;
@@ -41,7 +42,11 @@ public class DefaultOakSolrProvider impl
     private final OakSolrNodeStateConfiguration oakSolrConfiguration;
 
     public DefaultOakSolrProvider(NodeState configurationNodeState) {
-        this.oakSolrConfiguration = new OakSolrNodeStateConfiguration(configurationNodeState);
+        this.oakSolrConfiguration = new FixedNodeStateConfiguration(configurationNodeState);
+    }
+
+    public DefaultOakSolrProvider(NodeStore store, String path) {
+        this.oakSolrConfiguration = new UpToDateNodeStateConfiguration(store, path);
     }
 
     private SolrServer solrServer;
@@ -64,7 +69,7 @@ public class DefaultOakSolrProvider impl
         // check if solrHomePath exists
         File solrHomePathFile = new File(solrHomePath);
         if (!solrHomePathFile.exists()) {
-            if (!solrHomePathFile.mkdir()) {
+            if (!solrHomePathFile.mkdirs()) {
                 throw new IOException("could not create solrHomePath directory");
             } else {
                 // copy all the needed files to the just created directory
@@ -115,14 +120,14 @@ public class DefaultOakSolrProvider impl
                 if (inputStream != null) {
                     try {
                         inputStream.close();
-                    } catch (Exception e){
+                    } catch (Exception e) {
                         // do nothing
                     }
                 }
                 if (outputStream != null) {
                     try {
                         outputStream.close();
-                    } catch (Exception e){
+                    } catch (Exception e) {
                         // do nothing
                     }
                 }

Added: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java?rev=1461196&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java
Tue Mar 26 16:00:32 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.index.solr.server;
+
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * A {@link OakSolrNodeStateConfiguration} whose {@link NodeState} is given once
+ * and never updated so that the configuration is fixed.
+ */
+public class FixedNodeStateConfiguration extends OakSolrNodeStateConfiguration {
+
+    private final NodeState configurationNodeState;
+
+    public FixedNodeStateConfiguration(NodeState configurationNodeState) {
+        this.configurationNodeState = configurationNodeState;
+    }
+
+    @Override
+    protected NodeState getConfigurationNodeState() {
+        return configurationNodeState;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/FixedNodeStateConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java?rev=1461196&r1=1461195&r2=1461196&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/OakSolrNodeStateConfiguration.java
Tue Mar 26 16:00:32 2013
@@ -28,17 +28,26 @@ import org.apache.jackrabbit.oak.spi.sta
  * For each of the supported properties a default is provided if either the
  * property doesn't exist in the node or if the value is <code>null</code> or
  * empty <code>String</code>.
+ * <p/>
+ * Subclasses of this should at least provide the {@link NodeState} which holds
+ * the configuration.
  */
-public class OakSolrNodeStateConfiguration implements OakSolrConfiguration {
+public abstract class OakSolrNodeStateConfiguration implements OakSolrConfiguration {
 
-    private NodeState solrConfigurationNodeState;
-
-    public OakSolrNodeStateConfiguration(NodeState solrConfigurationNodeState) {
-        this.solrConfigurationNodeState = solrConfigurationNodeState;
-    }
+    /**
+     * get the {@link NodeState} which contains the properties for the Oak -
+     * Solr configuration.
+     *
+     * @return a {@link NodeState} for the Solr configuration.
+     */
+    protected abstract NodeState getConfigurationNodeState();
 
     @Override
     public String getFieldNameFor(Type<?> propertyType) {
+        if (Type.BINARIES.equals(propertyType) || Type.BINARY.equals(propertyType)) {
+            // TODO : use Tika / SolrCell here
+            return propertyType.toString() + "_bin";
+        }
         return null;
     }
 
@@ -95,9 +104,9 @@ public class OakSolrNodeStateConfigurati
         return getStringValueFor(Properties.CORE_NAME, "oak");
     }
 
-    private String getStringValueFor(String propertyName, String defaultValue) {
+    protected String getStringValueFor(String propertyName, String defaultValue) {
         String value = null;
-        PropertyState property = solrConfigurationNodeState.getProperty(propertyName);
+        PropertyState property = getConfigurationNodeState().getProperty(propertyName);
         if (property != null) {
             value = property.getValue(Type.STRING);
         }

Added: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java?rev=1461196&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java
Tue Mar 26 16:00:32 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.index.solr.server;
+
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+/**
+ * A {@link OakSolrNodeStateConfiguration} whose {@link NodeState} is retrieved
+ * via the {@link NodeStore} and a given <code>String</code> path.
+ */
+public class UpToDateNodeStateConfiguration extends OakSolrNodeStateConfiguration {
+
+    private final NodeStore store;
+    private final String path;
+
+    public UpToDateNodeStateConfiguration(NodeStore store, String path) {
+        this.store = store;
+        this.path = path;
+    }
+
+    @Override
+    protected NodeState getConfigurationNodeState() {
+        NodeState currentState = store.getRoot();
+        for (String child : path.split("/")) {
+            currentState = currentState.getChildNode(child);
+        }
+        return currentState;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java?rev=1461196&r1=1461195&r2=1461196&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
Tue Mar 26 16:00:32 2013
@@ -26,7 +26,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexDiff;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
-import org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrNodeStateConfiguration;
+import org.apache.jackrabbit.oak.plugins.index.solr.server.FixedNodeStateConfiguration;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -93,6 +93,6 @@ public class TestUtils {
 
 
     public static OakSolrConfiguration getTestConfiguration(NodeState nodeState) {
-        return new OakSolrNodeStateConfiguration(nodeState);
+        return new FixedNodeStateConfiguration(nodeState);
     }
 }

Added: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java?rev=1461196&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
Tue Mar 26 16:00:32 2013
@@ -0,0 +1,35 @@
+
+package org.apache.jackrabbit.oak.plugins.index.solr.server;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testcase for {@link UpToDateNodeStateConfiguration}
+ */
+public class UpToDateNodeStateConfigurationTest {
+
+    private NodeStore store;
+
+    @Before
+    public void setUp() throws Exception {
+        MicroKernel microKernel = new MicroKernelImpl();
+        String jsop = "^\"a\":1 ^\"b\":2 ^\"c\":3 +\"x\":{} +\"y\":{} +\"z\":{} " +
+                "+\"oak:index\":{\"solrIdx\":{\"coreName\":\"cn\", \"solrHome\":\"sh\", \"solrConfig\":\"sc\"}}
";
+        microKernel.commit("/", jsop, microKernel.getHeadRevision(), "test data");
+        store = new KernelNodeStore(microKernel);
+    }
+
+    @Test
+    public void testPath() throws Exception {
+        String path = "oak:index/solrIdx";
+        UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store,
path);
+        assertEquals("cn", upToDateNodeStateConfiguration.getCoreName());
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/server/UpToDateNodeStateConfigurationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message