jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1464953 - in /jackrabbit/oak/trunk/oak-solr-embedded: ./ src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/ src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/
Date Fri, 05 Apr 2013 12:36:37 GMT
Author: tommaso
Date: Fri Apr  5 12:36:36 2013
New Revision: 1464953

URL: http://svn.apache.org/r1464953
Log:
OAK-735 - merged former way of initialing ESS with the DOSP, added SolrServerConfiguration
and factored out defaults, added a unified OSGi service SolrServerProvider for OakSolrConfigurationProvider

Added:
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrProviderService.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OsgiSolrServerConfigurationProvider.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfiguration.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationDefaults.java
  (with props)
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationProvider.java
  (with props)
Removed:
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrServerProvider.java
Modified:
    jackrabbit/oak/trunk/oak-solr-embedded/pom.xml
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProvider.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfigurationProvider.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
    jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java

Modified: jackrabbit/oak/trunk/oak-solr-embedded/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/pom.xml?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/pom.xml Fri Apr  5 12:36:36 2013
@@ -308,6 +308,16 @@
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>log4j-over-slf4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProvider.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProvider.java
Fri Apr  5 12:36:36 2013
@@ -23,55 +23,77 @@ import java.io.InputStream;
 import java.util.Arrays;
 
 import org.apache.jackrabbit.mk.util.IOUtils;
-import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
-import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfigurationProvider;
+import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrUtils;
 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.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;
 import org.apache.solr.core.CoreContainer;
 
 /**
- * Default implementation of {@link SolrServerProvider} and {@link OakSolrConfigurationProvider}
- * which hides an {@link EmbeddedSolrServer} configured as per passed {@link NodeState}
- * properties.
+ * Default implementation of {@link SolrServerProvider} which uses an
+ * {@link EmbeddedSolrServer} configured as per passed {@link SolrServerConfiguration}.
  */
-public class DefaultOakSolrProvider implements SolrServerProvider, OakSolrConfigurationProvider
{
+public class DefaultOakSolrProvider implements SolrServerProvider {
 
-    private final OakSolrNodeStateConfiguration oakSolrConfiguration;
+    private final SolrServerConfiguration solrServerConfiguration;
 
-    public DefaultOakSolrProvider(NodeState configurationNodeState) {
-        this.oakSolrConfiguration = new FixedNodeStateConfiguration(configurationNodeState);
-    }
-
-    public DefaultOakSolrProvider(NodeStore store, String path) {
-        this.oakSolrConfiguration = new UpToDateNodeStateConfiguration(store, path);
+    public DefaultOakSolrProvider(SolrServerConfiguration solrServerConfiguration) {
+        this.solrServerConfiguration = solrServerConfiguration;
     }
 
     private SolrServer solrServer;
 
     private SolrServer createSolrServer() throws Exception {
 
-        String solrHomePath = oakSolrConfiguration.getSolrHomePath();
-        String coreName = oakSolrConfiguration.getCoreName();
-        String solrConfigPath = oakSolrConfiguration.getSolrConfigPath();
+        String solrHomePath = solrServerConfiguration.getSolrHomePath();
+        String coreName = solrServerConfiguration.getCoreName();
+        String solrConfigPath = solrServerConfiguration.getSolrConfigPath();
+        SolrServerConfiguration.HttpConfiguration httpConfiguration = solrServerConfiguration.getHttpConfiguration();
 
-        if (solrConfigPath != null && solrHomePath != null && coreName !=
null) {
 
+        if (solrConfigPath != null && solrHomePath != null && coreName !=
null) {
             checkSolrConfiguration(solrHomePath, solrConfigPath, coreName);
+            if (httpConfiguration != null) {
+                ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(JettySolrRunner.class.getClassLoader());
+
+                Integer httpPort = httpConfiguration.getHttpPort();
+                String context = httpConfiguration.getContext();
+                try {
+                    JettySolrRunner jettySolrRunner = new JettySolrRunner(solrHomePath, context,
httpPort, "solrconfig.xml", "schema.xml", true);
+                    jettySolrRunner.start(true);
+                } finally {
+                    Thread.currentThread().setContextClassLoader(classLoader);
+                }
+                HttpSolrServer httpSolrServer = new HttpSolrServer(new StringBuilder(SolrServerConfigurationDefaults.LOCAL_BASE_URL)
+                        .append(':').append(httpPort).append(coreName).toString());
+                if (OakSolrUtils.checkServerAlive(httpSolrServer)) {
+                    return httpSolrServer;
+                } else {
+                    throw new IOException("the spawn HTTP Solr server is not alive");
+                }
 
-            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-            Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
 
-            CoreContainer coreContainer = new CoreContainer(solrHomePath);
-            try {
-                coreContainer.load(solrHomePath, new File(solrConfigPath));
-            } finally {
-                Thread.currentThread().setContextClassLoader(classLoader);
-            }
+            } else {
+                ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader());
+
+                CoreContainer coreContainer = new CoreContainer(solrHomePath);
+                try {
+                    coreContainer.load(solrHomePath, new File(solrConfigPath));
+                } finally {
+                    Thread.currentThread().setContextClassLoader(classLoader);
+                }
 
-            return new EmbeddedSolrServer(coreContainer, coreName);
+                EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName);
+                if (OakSolrUtils.checkServerAlive(server)) {
+                    return server;
+                } else {
+                    throw new IOException("the embedded Solr server is not alive");
+                }
+            }
         } else {
             throw new Exception("SolrServer configuration proprties not set");
         }
@@ -157,8 +179,4 @@ public class DefaultOakSolrProvider impl
         return solrServer;
     }
 
-    @Override
-    public OakSolrConfiguration getConfiguration() {
-        return oakSolrConfiguration;
-    }
 }

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfiguration.java
Fri Apr  5 12:36:36 2013
@@ -28,11 +28,6 @@ import org.apache.jackrabbit.oak.spi.que
  */
 public class EmbeddedSolrConfiguration implements OakSolrConfiguration {
 
-    private static final String PATH_FIELD_NAME = "path";
-    private static final String CHILD_FIELD_NAME = "path_child";
-    private static final String DESC_FIELD_NAME = "path_desc";
-    private static final String ANC_FIELD_NAME = "path_anc";
-
     @Override
     public String getFieldNameFor(Type<?> propertyType) {
         if (Type.BINARIES.equals(propertyType) || Type.BINARY.equals(propertyType)) {
@@ -44,7 +39,7 @@ public class EmbeddedSolrConfiguration i
 
     @Override
     public String getPathField() {
-        return PATH_FIELD_NAME;
+        return SolrServerConfigurationDefaults.PATH_FIELD_NAME;
     }
 
     @Override
@@ -52,19 +47,19 @@ public class EmbeddedSolrConfiguration i
         String fieldName = null;
         switch (pathRestriction) {
             case ALL_CHILDREN: {
-                fieldName = DESC_FIELD_NAME;
+                fieldName = SolrServerConfigurationDefaults.DESC_FIELD_NAME;
                 break;
             }
             case DIRECT_CHILDREN: {
-                fieldName = CHILD_FIELD_NAME;
+                fieldName = SolrServerConfigurationDefaults.CHILD_FIELD_NAME;
                 break;
             }
             case EXACT: {
-                fieldName = PATH_FIELD_NAME;
+                fieldName = SolrServerConfigurationDefaults.PATH_FIELD_NAME;
                 break;
             }
             case PARENT: {
-                fieldName = ANC_FIELD_NAME;
+                fieldName = SolrServerConfigurationDefaults.ANC_FIELD_NAME;
                 break;
             }
 
@@ -84,6 +79,6 @@ public class EmbeddedSolrConfiguration i
 
     @Override
     public String getCoreName() {
-        return "oak";
+        return SolrServerConfigurationDefaults.CORE_NAME;
     }
 }

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfigurationProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfigurationProvider.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfigurationProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrConfigurationProvider.java
Fri Apr  5 12:36:36 2013
@@ -16,19 +16,23 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.embedded;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfigurationProvider;
 
 /**
  * An {@link OakSolrConfigurationProvider} for the embedded Solr server
  */
-@Component(immediate = true)
-@Service(OakSolrConfigurationProvider.class)
 public class EmbeddedSolrConfigurationProvider implements OakSolrConfigurationProvider {
 
-    private final OakSolrConfiguration embeddedConfiguration = new EmbeddedSolrConfiguration();
+    private final OakSolrConfiguration embeddedConfiguration;
+
+    public EmbeddedSolrConfigurationProvider() {
+        embeddedConfiguration = new EmbeddedSolrConfiguration();
+    }
+
+    public EmbeddedSolrConfigurationProvider(OakSolrConfiguration embeddedConfiguration)
{
+        this.embeddedConfiguration = embeddedConfiguration;
+    }
 
     @Override
     public OakSolrConfiguration getConfiguration() {

Added: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrProviderService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrProviderService.java?rev=1464953&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrProviderService.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/EmbeddedSolrProviderService.java
Fri Apr  5 12:36:36 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.embedded;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Services;
+import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
+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.NodeStore;
+import org.apache.solr.client.solrj.SolrServer;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * OSGi service for the embedded Solr server module.
+ */
+@Component
+@Services({
+        @Service(value = SolrServerProvider.class),
+        @Service(value = OakSolrConfigurationProvider.class)
+})
+public class EmbeddedSolrProviderService implements SolrServerProvider, OakSolrConfigurationProvider
{
+
+
+    @Property(value = "/oak:index/solrIdx", name = "configuration path",
+            description = "path to node holding Solr configuration")
+    private static final String CONFIGURATION_PATH = "solr.configuration.node.path";
+
+    @Reference
+    private NodeStore nodeStore;
+
+    @Reference
+    private SolrServerConfigurationProvider solrServerConfigurationProvider;
+
+    private OakSolrConfigurationProvider oakSolrConfigurationProvider;
+
+    private SolrServerProvider solrServerProvider;
+
+    @Activate
+    public void activate(ComponentContext context) throws Exception {
+        try {
+            // try reading configuration from the configured repository path
+            UpToDateNodeStateConfiguration nodeStateConfiguration = new UpToDateNodeStateConfiguration(nodeStore,
String.valueOf(
+                    context.getProperties().get(CONFIGURATION_PATH)));
+            solrServerProvider = new DefaultOakSolrProvider(nodeStateConfiguration.getSolrServerConfiguration());
+            oakSolrConfigurationProvider = new EmbeddedSolrConfigurationProvider(nodeStateConfiguration);
+        } catch (Exception e) {
+            // use the default config and the OSGi based server configuration
+            solrServerProvider = new DefaultOakSolrProvider(solrServerConfigurationProvider.getSolrServerConfiguration());
+            oakSolrConfigurationProvider = new EmbeddedSolrConfigurationProvider();
+        }
+    }
+
+    @Override
+    public OakSolrConfiguration getConfiguration() {
+        return oakSolrConfigurationProvider.getConfiguration();
+    }
+
+    @Override
+    public SolrServer getSolrServer() throws Exception {
+        return solrServerProvider.getSolrServer();
+    }
+}

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

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OakSolrNodeStateConfiguration.java
Fri Apr  5 12:36:36 2013
@@ -32,7 +32,7 @@ import org.apache.jackrabbit.oak.spi.sta
  * Subclasses of this should at least provide the {@link org.apache.jackrabbit.oak.spi.state.NodeState}
which holds
  * the configuration.
  */
-public abstract class OakSolrNodeStateConfiguration implements OakSolrConfiguration {
+public abstract class OakSolrNodeStateConfiguration extends EmbeddedSolrConfiguration implements
OakSolrConfiguration, SolrServerConfigurationProvider {
 
     /**
      * get the {@link org.apache.jackrabbit.oak.spi.state.NodeState} which contains the properties
for the Oak -
@@ -43,17 +43,8 @@ public abstract class OakSolrNodeStateCo
     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;
-    }
-
-    @Override
     public String getPathField() {
-        return getStringValueFor(Properties.PATH_FIELD, "path_exact");
+        return getStringValueFor(Properties.PATH_FIELD, SolrServerConfigurationDefaults.PATH_FIELD_NAME);
     }
 
     @Override
@@ -61,19 +52,19 @@ public abstract class OakSolrNodeStateCo
         String fieldName = null;
         switch (pathRestriction) {
             case ALL_CHILDREN: {
-                fieldName = getStringValueFor(Properties.DESCENDANTS_FIELD, "path_des");
+                fieldName = getStringValueFor(Properties.DESCENDANTS_FIELD, SolrServerConfigurationDefaults.DESC_FIELD_NAME);
                 break;
             }
             case DIRECT_CHILDREN: {
-                fieldName = getStringValueFor(Properties.CHILDREN_FIELD, "path_child");
+                fieldName = getStringValueFor(Properties.CHILDREN_FIELD, SolrServerConfigurationDefaults.CHILD_FIELD_NAME);
                 break;
             }
             case EXACT: {
-                fieldName = getStringValueFor(Properties.PATH_FIELD, "path_exact");
+                fieldName = getStringValueFor(Properties.PATH_FIELD, SolrServerConfigurationDefaults.PATH_FIELD_NAME);
                 break;
             }
             case PARENT: {
-                fieldName = getStringValueFor(Properties.PARENT_FIELD, "path_anc");
+                fieldName = getStringValueFor(Properties.PARENT_FIELD, SolrServerConfigurationDefaults.ANC_FIELD_NAME);
                 break;
             }
 
@@ -82,26 +73,13 @@ public abstract class OakSolrNodeStateCo
     }
 
     @Override
-    public String getFieldForPropertyRestriction(Filter.PropertyRestriction propertyRestriction)
{
-        return null;
-    }
-
-    @Override
     public CommitPolicy getCommitPolicy() {
-        return CommitPolicy.valueOf(getStringValueFor(Properties.COMMIT_POLICY, CommitPolicy.HARD.toString()));
-    }
-
-    public String getSolrHomePath() {
-        return getStringValueFor(Properties.SOLRHOME_PATH, "./");
-    }
-
-    public String getSolrConfigPath() {
-        return getStringValueFor(Properties.SOLRCONFIG_PATH, "./solr.xml");
+        return CommitPolicy.valueOf(getStringValueFor(Properties.COMMIT_POLICY, CommitPolicy.SOFT.toString()));
     }
 
     @Override
     public String getCoreName() {
-        return getStringValueFor(Properties.CORE_NAME, "oak");
+        return getStringValueFor(Properties.CORE_NAME, SolrServerConfigurationDefaults.CORE_NAME);
     }
 
     protected String getStringValueFor(String propertyName, String defaultValue) {
@@ -119,6 +97,12 @@ public abstract class OakSolrNodeStateCo
         return value;
     }
 
+    @Override
+    public SolrServerConfiguration getSolrServerConfiguration() {
+        return new SolrServerConfiguration(getStringValueFor(Properties.SOLRHOME_PATH, SolrServerConfigurationDefaults.SOLR_HOME_PATH),
+                getStringValueFor(Properties.SOLRCONFIG_PATH, SolrServerConfigurationDefaults.SOLR_CONFIG_PATH),
getCoreName());
+    }
+
     /**
      * Properties that may be retrieved from the configuration {@link org.apache.jackrabbit.oak.spi.state.NodeState}.
      */

Added: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OsgiSolrServerConfigurationProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OsgiSolrServerConfigurationProvider.java?rev=1464953&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OsgiSolrServerConfigurationProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/OsgiSolrServerConfigurationProvider.java
Fri Apr  5 12:36:36 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.embedded;
+
+import java.io.File;
+
+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.Service;
+import org.apache.jackrabbit.oak.plugins.index.solr.embedded.SolrServerConfiguration;
+import org.apache.jackrabbit.oak.plugins.index.solr.embedded.SolrServerConfigurationDefaults;
+import org.apache.jackrabbit.oak.plugins.index.solr.embedded.SolrServerConfigurationProvider;
+import org.apache.solr.client.solrj.SolrServer;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * An OSGi service {@link SolrServerConfigurationProvider}
+ */
+@Component
+@Service(value = SolrServerConfigurationProvider.class)
+public class OsgiSolrServerConfigurationProvider implements SolrServerConfigurationProvider
{
+
+    @Property(value = SolrServerConfigurationDefaults.SOLR_HOME_PATH)
+    private static final String SOLR_HOME_PATH = "solr.home.path";
+
+    @Property(value = SolrServerConfigurationDefaults.CORE_NAME)
+    private static final String SOLR_CORE_NAME = "solr.core.name";
+
+    @Property(value = SolrServerConfigurationDefaults.SOLR_CONFIG_PATH)
+    private static final String SOLR_CONFIG_FILE = "solr.config.path";
+
+    @Property(value = SolrServerConfigurationDefaults.HTTP_PORT)
+    private static final String SOLR_HTTP_PORT = "solr.http.port";
+
+    private static SolrServer solrServer;
+
+    private String solrHome;
+    private String solrConfigFile;
+    private String solrCoreName;
+
+    private Integer solrHttpPort;
+
+    private SolrServerConfiguration solrServerConfiguration;
+
+
+    @Activate
+    protected void activate(ComponentContext componentContext) throws Exception {
+        solrHome = String.valueOf(componentContext.getProperties().get(SOLR_HOME_PATH));
+        File file = new File(solrHome);
+        if (!file.exists()) {
+            assert file.createNewFile();
+        }
+        solrConfigFile = String.valueOf(componentContext.getProperties().get(SOLR_CONFIG_FILE));
+        solrCoreName= String.valueOf(componentContext.getProperties().get(SOLR_CORE_NAME));
+
+        solrHttpPort = Integer.valueOf(String.valueOf(componentContext.getProperties().get(SOLR_HTTP_PORT)));
+        // TODO : add the possibility to inject solrconfig and schema files
+
+        solrServerConfiguration = new SolrServerConfiguration(solrHome, solrConfigFile, solrCoreName);
+    }
+
+    @Deactivate
+    protected void deactivate() throws Exception {
+        solrHome = null;
+        solrHttpPort = null;
+        solrConfigFile = null;
+        solrCoreName = null;
+        if (solrServer != null) {
+            solrServer.shutdown();
+            solrServer = null;
+        }
+    }
+
+    @Override
+    public SolrServerConfiguration getSolrServerConfiguration() {
+        return solrServerConfiguration;
+    }
+}

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

Added: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfiguration.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfiguration.java?rev=1464953&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfiguration.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfiguration.java
Fri Apr  5 12:36:36 2013
@@ -0,0 +1,95 @@
+/*
+ * 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.embedded;
+
+/**
+ * Configuration parameters for starting a {@link org.apache.solr.client.solrj.SolrServer}
+ */
+public class SolrServerConfiguration {
+
+    private final String solrHomePath;
+    private final String solrConfigPath;
+    private final String coreName;
+    private HttpConfiguration httpConfiguration;
+
+    public SolrServerConfiguration(String solrHomePath, String solrConfigPath, String coreName)
{
+        this.solrHomePath = solrHomePath;
+        this.solrConfigPath = solrConfigPath;
+        this.coreName = coreName;
+    }
+
+    public SolrServerConfiguration withHttpConfiguration(String context, Integer httpPort)
{
+        this.httpConfiguration = new HttpConfiguration(context, httpPort);
+        return this;
+    }
+
+    /**
+     * get the Solr home path where all the configuration files are stored
+     *
+     * @return a <code>String</code> representing a path to the Solr home.
+     */
+    public String getSolrHomePath() {
+        return solrHomePath;
+    }
+
+    /**
+     * get the name of the main Solr configuration file (solr.xml for multicore
+     * deployments or solrconfig.xml for single core deployments).
+     *
+     * @return a <code>String</code> representing a path to the main Solr config
file.
+     */
+    public String getSolrConfigPath() {
+        return solrConfigPath;
+    }
+
+    /**
+     * get the default core name to use for the Solr server
+     *
+     * @return a <code>String</code> representing the core name
+     */
+    public String getCoreName() {
+        return coreName;
+    }
+
+    /**
+     * get the {@link HttpConfiguration} holding parameters for enabling Solr
+     * server with HTTP bindings
+     *
+     * @return a {@link HttpConfiguration} or <code>null</code> if not set
+     */
+    public HttpConfiguration getHttpConfiguration() {
+        return httpConfiguration;
+    }
+
+    class HttpConfiguration {
+        private String context;
+        private Integer httpPort;
+
+        HttpConfiguration(String context, Integer httpPort) {
+            this.context = context;
+            this.httpPort = httpPort;
+        }
+
+        public String getContext() {
+            return context;
+        }
+
+        public Integer getHttpPort() {
+            return httpPort;
+        }
+    }
+}

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

Added: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationDefaults.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationDefaults.java?rev=1464953&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationDefaults.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationDefaults.java
Fri Apr  5 12:36:36 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.embedded;
+
+/**
+ * Defaults for embedded Solr server configurations.
+ */
+public class SolrServerConfigurationDefaults {
+
+    public static final String SOLR_HOME_PATH = "./";
+    public static final String SOLR_CONFIG_PATH = "./solr.xml";
+    public static final String CORE_NAME = "oak";
+
+    public static final String HTTP_PORT = "8983";
+    public static final String LOCAL_BASE_URL = "http://127.0.0.1";
+    public static final String CONTEXT = "/solr";
+
+    public static final String PATH_FIELD_NAME = "path_exact";
+    public static final String CHILD_FIELD_NAME = "path_child";
+    public static final String DESC_FIELD_NAME = "path_desc";
+    public static final String ANC_FIELD_NAME = "path_anc";
+
+}

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

Added: jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationProvider.java?rev=1464953&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/SolrServerConfigurationProvider.java
Fri Apr  5 12:36:36 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.embedded;
+
+/**
+ * {@link org.apache.solr.client.solrj.SolrServer} configuration provider.
+ */
+public interface SolrServerConfigurationProvider {
+
+    /**
+     * Provide a {@lin SolrServerConfiguration} to be used to initialize a specific
+     * {@link org.apache.solr.client.solrj.SolrServer} implementation.
+     *
+     * @return the {@link SolrServerConfiguration} holding the configuration parameters
+     */
+    public SolrServerConfiguration getSolrServerConfiguration();
+}

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

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/DefaultOakSolrProviderTest.java
Fri Apr  5 12:36:36 2013
@@ -16,14 +16,10 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.embedded;
 
-import org.apache.jackrabbit.oak.spi.query.PropertyValues;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.solr.client.solrj.SolrServer;
 import org.junit.Test;
 
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * Testcase for {@link DefaultOakSolrProvider}
@@ -31,16 +27,10 @@ import static org.mockito.Mockito.when;
 public class DefaultOakSolrProviderTest {
 
     @Test
-    public void testSolrServerInitializationWithoutConfigurationFiles() throws Exception
{
-        NodeState nodeState = mock(NodeState.class);
-        when(nodeState.exists()).thenReturn(true);
-        when(nodeState.getProperty(OakSolrNodeStateConfiguration.Properties.CORE_NAME)).
-                thenReturn(PropertyValues.create(PropertyValues.newString("oak")));
-        when(nodeState.getProperty(OakSolrNodeStateConfiguration.Properties.SOLRHOME_PATH)).
-                thenReturn(PropertyValues.create(PropertyValues.newString("target/solr")));
-        when(nodeState.getProperty(OakSolrNodeStateConfiguration.Properties.SOLRCONFIG_PATH)).
-                thenReturn(PropertyValues.create(PropertyValues.newString("target/solr/solr.xml")));
-        DefaultOakSolrProvider defaultOakSolrProvider = new DefaultOakSolrProvider(nodeState);
+    public void testSolrServerInitialization() throws Exception {
+        SolrServerConfiguration solrServerConfiguration = new SolrServerConfiguration("target/solr",
+                "target/solr/solr.xml", "oak");
+        DefaultOakSolrProvider defaultOakSolrProvider = new DefaultOakSolrProvider(solrServerConfiguration);
         SolrServer solrServer = defaultOakSolrProvider.getSolrServer();
         assertNotNull(solrServer);
     }

Modified: jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java?rev=1464953&r1=1464952&r2=1464953&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-embedded/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/embedded/UpToDateNodeStateConfigurationTest.java
Fri Apr  5 12:36:36 2013
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNull;
 
 /**
- * Testcase for {@link org.apache.jackrabbit.oak.plugins.index.solr.server.UpToDateNodeStateConfiguration}
+ * Testcase for {@link UpToDateNodeStateConfiguration}
  */
 public class UpToDateNodeStateConfigurationTest {
 
@@ -40,7 +40,7 @@ public class UpToDateNodeStateConfigurat
     public void testNonExistingPath() throws Exception {
         String path = "some/path/to/oak:index/solrIdx";
         UpToDateNodeStateConfiguration upToDateNodeStateConfiguration = new UpToDateNodeStateConfiguration(store,
path);
-        assertNull(upToDateNodeStateConfiguration.getSolrConfigPath());
+        assertNull(upToDateNodeStateConfiguration.getCoreName());
     }
 
     @Test



Mime
View raw message