Author: ivol37 at gmail.com
Date: Tue Jan 25 10:53:10 2011
New Revision: 705

Log:


Added:
   sandbox/ivol/amdatu-searchandindex/solr/org.amdatu.searchandindex.solr.cfg
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrCoreProvider.java
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDaemonServiceImpl.java
      - copied, changed from r704, 
/sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrServiceImpl.java
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrRestServiceImpl.java
   sandbox/ivol/amdatu-searchandindex/solr/src/main/resources/conf/
Removed:
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrServiceImpl.java
Modified:
   sandbox/ivol/amdatu-searchandindex/solr/pom.xml
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrService.java
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDispatchFilter.java
   
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/osgi/Activator.java
   sandbox/ivol/amdatu-searchandindex/solr/src/main/resources/solr.xml

Added: 
sandbox/ivol/amdatu-searchandindex/solr/org.amdatu.searchandindex.solr.cfg
==============================================================================
--- (empty file)
+++ sandbox/ivol/amdatu-searchandindex/solr/org.amdatu.searchandindex.solr.cfg  
Tue Jan 25 10:53:10 2011
@@ -0,0 +1,2 @@
+# Solr work directory
+workdir=solr
\ No newline at end of file

Modified: sandbox/ivol/amdatu-searchandindex/solr/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-searchandindex/solr/pom.xml     (original)
+++ sandbox/ivol/amdatu-searchandindex/solr/pom.xml     Tue Jan 25 10:53:10 2011
@@ -81,6 +81,13 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.web.rest</groupId>
+      <artifactId>jaxrs</artifactId>
+      <version>${platform.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -113,6 +120,27 @@
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <tasks>
+                <copy
+                  
file="${project.build.directory}/${project.build.finalName}.jar"
+                  
todir="D:\Amdatu-svn\trunk\amdatu-release\target\org.amdatu.amdatu-release-0.1.0-SNAPSHOT-dev\deploy"
 overwrite="true" />
+                <copy
+                  file="org.amdatu.searchandindex.solr.cfg"
+                  
todir="D:\Amdatu-svn\trunk\amdatu-release\target\org.amdatu.amdatu-release-0.1.0-SNAPSHOT-dev\deploy"
 overwrite="true" />
+              </tasks>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 </project>

Added: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrCoreProvider.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrCoreProvider.java
  Tue Jan 25 10:53:10 2011
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.searchandindex.solr;
+
+import java.net.URL;
+
+public interface SolrCoreProvider {
+    /**
+     * The unique name of this core. The name should match the regular 
expression ([a-z][A-Z][0-9])*.
+     * @return The unique name of this core
+     */
+    String getCoreName();
+
+    /**
+     * Returns the URL of the schema to use for this core. May be null in 
which case the default schema is used.
+     * @return the URL of the schema to use for this core.
+     */
+    URL getSchema();
+
+    /**
+     * Returns the URL of the configuration to use for this core. May be null 
in which case the default configuration is used.
+     * @return the URL of the configuration to use for this core.
+     */
+    URL getSolrConfig();
+}

Modified: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrService.java
==============================================================================
--- 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrService.java
       (original)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/SolrService.java
       Tue Jan 25 10:53:10 2011
@@ -16,12 +16,11 @@
  */
 package org.amdatu.searchandindex.solr;
 
-import org.amdatu.web.httpcontext.ResourceProvider;
 
 /**
  * Interface for the UserService.
  */
-public interface SolrService extends ResourceProvider {
+public interface SolrService {
     /**
      * The "Administrators" group.
      */

Copied: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDaemonServiceImpl.java
 (from r704, 
/sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrServiceImpl.java)
==============================================================================
--- 
/sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrServiceImpl.java
     (original)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDaemonServiceImpl.java
        Tue Jan 25 10:53:10 2011
@@ -19,27 +19,27 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.List;
-import java.util.Map;
-
-import javax.servlet.Filter;
 
 import org.amdatu.core.config.templates.ConfigTemplateManager;
-import org.amdatu.core.tenant.TenantEntity;
-import org.amdatu.core.tenant.TenantException;
+import org.amdatu.core.tenant.Tenant;
 import org.amdatu.core.tenant.TenantManagementService;
+import org.amdatu.searchandindex.solr.SolrCoreProvider;
 import org.amdatu.searchandindex.solr.SolrService;
-import org.amdatu.searchandindex.solr.osgi.Activator;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
-import org.apache.felix.dm.Component;
+import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ServiceDependency;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.NakamuraSolrResourceLoader;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrResourceLoader;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.log.LogService;
@@ -47,7 +47,7 @@
 /**
  * Implementation of the {@link SolrService} interface.
  */
-public class SolrServiceImpl implements SolrService, ManagedService {
+public class SolrDaemonServiceImpl implements SolrService, ManagedService {
     // Statics
     private static final String SOLR_CONFIG_XML = "solr.xml";
     private static final String CONFIG_DIR = "conf";
@@ -55,16 +55,15 @@
     // Services injected by the Felix dependency manager
     private volatile LogService m_logService;
     private volatile BundleContext m_bundleContext;
-
     private volatile DependencyManager m_dependencyManager;
-    private volatile HttpContextServiceFactory m_httpContextServiceFactory;
     private volatile TenantManagementService m_tenantService;
     private volatile ConfigTemplateManager m_configTemplateManager;
-    private volatile Component m_contextComponent;
 
     // Private members
-    private SolrDispatchFilter solrDispatchFilter = null;
+    private CoreContainer m_coreContainer;
+
     private File m_workDir;
+    private List<Tenant> m_tenants;
 
     /**
      * The init() method is invoked by the Felix dependency manager.
@@ -74,9 +73,6 @@
         try {
             m_logService.log(LogService.LOG_INFO, "Initializing Solr 
configuration");
 
-            // Create our own http context and register resources
-            m_contextComponent = 
m_httpContextServiceFactory.create(m_bundleContext, this);
-
             // Initialize storage configuration
             // Load the URL of the storage-conf.xml and write it file using 
the config template
             // manager, which automatically replaces configuration entries in 
that file
@@ -92,51 +88,21 @@
                 System.setProperty("solr.solr.home", 
storageConfigFile.getParentFile().getAbsolutePath());
 
                 // Update the main config
-                File mainconfdir = new File(m_workDir, "/" + CONFIG_DIR);
-                mainconfdir.mkdirs();
+                File mainConfigDir = new File(m_workDir, "/" + CONFIG_DIR);
+                mainConfigDir.mkdirs();
 
                 // Find all entries in our 'conf' directory.
                 final Enumeration<URL> resources = 
bundle.findEntries(CONFIG_DIR, "*.*", true);
                 if (resources != null) {
                     while (resources.hasMoreElements()) {
                         final URL resource = resources.nextElement();
-                        File coreConfFile = new File(mainconfdir, 
resource.getFile().replace(CONFIG_DIR + "/", ""));
+                        File coreConfFile = new File(mainConfigDir, 
resource.getFile().replace(CONFIG_DIR + "/", ""));
                         if (!coreConfFile.exists()) {
                             // Only write this file if it does not yet exist
                             
m_configTemplateManager.writeConfiguration(resource, coreConfFile);
                         }
                     }
                 }
-
-                // Update the core configs
-                List<String> cores = new ArrayList<String>();
-                cores.add("Keyspace1/profile");
-                cores.add("Keyspace2/profile");
-                cores.add("Keyspace3/profile");
-
-                for (String core : cores) {
-                    File coreconfdir = new File(m_workDir, core + "/conf");
-                    if (coreconfdir.exists()) {
-                        coreconfdir.delete();
-                    }
-                    coreconfdir.mkdirs();
-
-                    // Find all entries in our 'conf' directory.
-                    final Enumeration<URL> resources = 
bundle.findEntries("conf_core_profile", "*.*", true);
-                    if (resources != null) {
-                        while (resources.hasMoreElements()) {
-                            final URL resource = resources.nextElement();
-                            File coreconffile =
-                                new File(coreconfdir, 
resource.getFile().replaceAll("conf_core_profile/", ""));
-                            if (!coreconffile.exists()) {
-                                // Only write this file if it does not yet 
exist
-                                
m_configTemplateManager.writeConfiguration(resource, coreconffile);
-                            }
-                        }
-                    }
-
-                }
-
             } catch (IOException e) {
                 m_logService.log(LogService.LOG_ERROR, "Could not replace 
configuration entries in storage-conf.xml", e);
             }
@@ -146,75 +112,58 @@
         }
     }
 
-    /**
-     * The start() method is invoked by the Felix dependency manager.
-     */
     public void start() {
-        m_logService.log(LogService.LOG_ERROR, getClass().getName() + " 
service Start");
+        try {
+            // Start the Solr daemon
+            startSolrDaemon();
 
-        // Create and register a http servlet filter. This filter is mapped on 
.*
-        Dictionary<String, String> filterProperties = new Hashtable<String, 
String>();
-        filterProperties.put("pattern", "/" + Activator.RESOURCE_ID + 
"(|\\?.*|/.*)");
-        filterProperties.put("service.ranking", "10");
-        filterProperties.put("contextId", Activator.RESOURCE_ID);
+            // Register the Solr dispatch filter
+            registerRestAPI();
+        }
+        catch (Exception e) {
+            m_logService.log(LogService.LOG_ERROR, "Failed to start Solr 
Daemon", e);
+        }
+    }
 
-        Map<String, String> tenantMap = new HashMap<String, String>();
-        try {
-            for (TenantEntity tenant : m_tenantService.getTenants()) {
-                String tenanthostname = tenant.getProperties().get("hostname");
-                if (tenanthostname != null) {
-                    System.err.println("put: " + tenanthostname + " " + 
tenant.getId());
-                    tenantMap.put(tenanthostname, tenant.getId());
+    // Invoked when a new SolrIndexProvider comes available.
+    public synchronized void onIndexAdded(ServiceReference ref, Object 
service) {
+        if (service instanceof SolrCoreProvider) {
+            SolrCoreProvider indexProvider = (SolrCoreProvider) service;
+            m_logService.log(LogService.LOG_INFO, "New Solr index available: " 
+ indexProvider.getCoreName());
+
+            // For each tenant, prepare a Solr index (if it doesn't exist yet)
+            // First create the core configuration. The name of that core will 
be
+            // <tenant id>/<index name>
+            for (Tenant tenant : m_tenants) {
+                String id = indexProvider.getCoreName();
+                String core = tenant.getId() + "/" + id;
+                try {
+                    createCoreConfiguration(core);
+                }
+                catch (IOException e) {
+                    m_logService.log(LogService.LOG_ERROR, "Could not create 
Solr core configuration for '" + core + "'", e);
                 }
             }
-        } catch (TenantException e) {
-            e.printStackTrace();
         }
 
-        solrDispatchFilter =
-            new SolrDispatchFilter("/" + Activator.RESOURCE_ID, 
m_workDir.getAbsolutePath(), tenantMap);
-        
m_dependencyManager.add(m_dependencyManager.createComponent().setImplementation(solrDispatchFilter)
-            .setInterface(Filter.class.getName(), filterProperties));
-
     }
 
-    /**
-     * The stop() method is invoked by the Felix dependency manager.
-     */
-    public void stop() {
-        if (solrDispatchFilter != null) {
-            solrDispatchFilter.destroy();
-        }
-
-        m_logService.log(LogService.LOG_ERROR, getClass().getName() + " 
service stopped");
+    public synchronized void onIndexRemoved(ServiceReference ref, Object 
service) {
     }
 
-    /**
-     * The destroy() method is invoked by the Felix dependency manager.
-     */
-    public void destroy() {
-        try {
-            if (m_contextComponent != null) {
-                m_contextComponent.stop();
-            }
-            m_logService.log(LogService.LOG_ERROR, getClass().getName() + " 
service destroyed");
-        } catch (Exception e) {
-            e.printStackTrace();
+    // Invoked when a new SolrIndexProvider comes available.
+    public synchronized void onTenantAdded(ServiceReference ref, Object 
service) {
+        if (service instanceof Tenant) {
+            Tenant tenant = (Tenant) service;
+            m_tenants.add(tenant);
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public URL getResource(String input) {
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getResourceId() {
-        return Activator.RESOURCE_ID;
+    public synchronized void onTenantRemoved(ServiceReference ref, Object 
service) {
+        if (service instanceof Tenant) {
+            Tenant tenant = (Tenant) service;
+            m_tenants.remove(tenant);
+        }
     }
 
     @SuppressWarnings("unchecked")
@@ -227,4 +176,84 @@
             m_workDir = new File(workBaseDir, (String) 
dictionary.get(CONFIG_WORKDIR));
         }
     }
+
+    @SuppressWarnings("unchecked")
+    private void createCoreConfiguration(String core) throws IOException {
+        File coreconfdir = new File(m_workDir, core + "/conf");
+        if (coreconfdir.exists()) {
+            coreconfdir.delete();
+        }
+        coreconfdir.mkdirs();
+        Bundle bundle = m_bundleContext.getBundle();
+
+        // Find all entries in our 'conf' directory.
+        final Enumeration<URL> resources = 
bundle.findEntries("conf_core_profile", "*.*", true);
+        if (resources != null) {
+            while (resources.hasMoreElements()) {
+                final URL resource = resources.nextElement();
+                File coreconffile = new File(coreconfdir, 
resource.getFile().replace("conf_core_profile/", ""));
+                if (!coreconffile.exists()) {
+                    // Only write this file if it does not yet exist
+                    m_configTemplateManager.writeConfiguration(resource, 
coreconffile);
+                }
+            }
+        }
+    }
+
+    private void startSolrDaemon() throws Exception {
+        // Save the current context classloader first
+        final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+        try {
+
+            // overwrite the context classloader, restore it later
+            final ClassLoader classLoader = this.getClass().getClassLoader();
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            // Create the resource loader and core container
+            SolrResourceLoader loader = new 
NakamuraSolrResourceLoader(m_workDir.getAbsolutePath(), classLoader);
+            m_coreContainer = new CoreContainer(loader);
+
+            // Create the core initializer
+            boolean abortOnConfigurationError = true;
+            CoreContainer.Initializer init = new CoreContainer.Initializer();
+            init.initialize();
+            abortOnConfigurationError = init.isAbortOnConfigurationError();
+
+            // Optionally abort if we found a sever error
+            if (abortOnConfigurationError && SolrConfig.severeErrors.size() > 
0) {
+                StringBuffer sb = new StringBuffer();
+                sb.append("Severe errors in solr configuration.\n");
+                sb.append("Check your log files for more detailed information 
on what may be wrong.\n");
+                sb.append("If you want solr to continue after configuration 
errors, change: \n");
+                sb.append(" 
<abortOnConfigurationError>false</abortOnConfigurationError>\n");
+                sb.append("in " + init.getSolrConfigFilename() + "\n");
+                for (Throwable t : SolrConfig.severeErrors) {
+                    
sb.append("-------------------------------------------------------------\n");
+                    sb.append(t.toString());
+                }
+            }
+        } catch (Exception e) {
+            SolrConfig.severeErrors.add(e);
+            SolrCore.log(e);
+            m_logService.log(LogService.LOG_ERROR, "Failed to initialize 
Solr", e);
+            throw e;
+        } finally {
+            // Restore classloader
+            Thread.currentThread().setContextClassLoader(contextClassLoader);
+        }
+    }
+
+    // Register the REST service
+    private void registerRestAPI() {
+        SolrRestServiceImpl restService = new SolrRestServiceImpl(m_workDir);
+        m_dependencyManager.add(m_dependencyManager.createComponent()
+            .setImplementation(restService)
+            .setInterface(ResourceProvider.class.getName(), null)
+            .add(createServiceDependency(LogService.class))
+            .add(createServiceDependency(HttpContextServiceFactory.class)));
+    }
+
+    private ServiceDependency createServiceDependency(Class<?> clazz) {
+        return 
m_dependencyManager.createServiceDependency().setService(clazz).setRequired(true);
+    }
 }

Modified: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDispatchFilter.java
==============================================================================
--- 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDispatchFilter.java
   (original)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrDispatchFilter.java
   Tue Jan 25 10:53:10 2011
@@ -16,8 +16,6 @@
  */
 package org.amdatu.searchandindex.solr.impl;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -39,18 +37,13 @@
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.NakamuraSolrConfig;
-import org.apache.solr.core.NakamuraSolrResourceLoader;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrResourceLoader;
 import org.apache.solr.request.BinaryQueryResponseWriter;
 import org.apache.solr.request.QueryResponseWriter;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.request.SolrQueryResponse;
 import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.servlet.SolrRequestParsers;
 import org.apache.solr.servlet.cache.HttpCacheHeaderUtil;
 import org.apache.solr.servlet.cache.Method;
@@ -70,114 +63,17 @@
     protected String abortErrorMessage = null;
     protected String solrConfigFilename = null;
     protected final Map<SolrConfig, SolrRequestParsers> parsers = new 
WeakHashMap<SolrConfig, SolrRequestParsers>();
-    // SolrRequestParsers adminRequestParser;
     private final Map<String, String> myTenantMap = new HashMap<String, 
String>();
 
-    // protected final
-
-    /**
-     * Constructor.
-     */
-    public SolrDispatchFilter(String path, String homedir, Map<String, String> 
tenantMap) {
+    public SolrDispatchFilter(String path, String homedir) {
         this.pathPrefix = path;
         this.myHomeDir = homedir;
-        if (tenantMap != null) {
+        /*if (tenantMap != null) {
             myTenantMap.putAll(tenantMap);
-        }
+        }*/
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public void init(FilterConfig filterConfig) throws ServletException {
-        // save the current context classloader
-        final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
-
-        try {
-            try {
-                final ClassLoader classLoader = 
this.getClass().getClassLoader();
-
-                // overwrite the context classloader, restore it later
-                Thread.currentThread().setContextClassLoader(classLoader);
-                SolrResourceLoader loader = new 
NakamuraSolrResourceLoader(myHomeDir, classLoader);
-                final CoreContainer coreContainer = new CoreContainer(loader);
-
-                if (false) {
-                    // adminRequestParser =
-                    // new SolrRequestParsers(new Config(null, "solr", new 
ByteArrayInputStream("<root/>".getBytes()),
-                    // ""));
-
-                    String solrconfig =
-                        
"D:\\users\\dionm\\SVN\\projects\\apache-solr-1.4.1\\example\\solr\\core1\\conf\\solrconfig.xml";
-                    String schemaloc =
-                        
"D:\\users\\dionm\\SVN\\projects\\apache-solr-1.4.1\\example\\solr\\core1\\conf\\schema.xml";
-
-                    File coreDir = new 
File("D:\\users\\dionm\\SVN\\projects\\apache-solr-1.4.1\\example\\solr\\core1");
-                    SolrConfig config =
-                        new NakamuraSolrConfig(loader, "solrconfig.xml", new 
FileInputStream(new File(solrconfig)));
-                    IndexSchema schema = new IndexSchema(config, null, new 
FileInputStream(new File(schemaloc)));
-                    CoreDescriptor desc = new CoreDescriptor(coreContainer, 
"core1", coreDir.getAbsolutePath());
-                    SolrCore nakamuraCore = new SolrCore("core1", 
coreDir.getAbsolutePath(), config, schema, desc);
-                    coreContainer.register("core1", nakamuraCore, false);
-                }
-
-                this.cores = coreContainer;
-            } catch (Exception e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-
-            boolean abortOnConfigurationError = true;
-            CoreContainer.Initializer init = createInitializer();
-            try {
-                // web.xml configuration
-                
init.setSolrConfigFilename(filterConfig.getInitParameter("solrconfig-filename"));
-
-                this.cores = init.initialize();
-                abortOnConfigurationError = init.isAbortOnConfigurationError();
-                log.info("user.dir=" + System.getProperty("user.dir"));
-            } catch (Throwable t) {
-                // catch this so our filter still works
-                log.error("Could not start SOLR. Check solr/home property", t);
-                SolrConfig.severeErrors.add(t);
-                SolrCore.log(t);
-            }
-
-            // Optionally abort if we found a sever error
-            if (abortOnConfigurationError && SolrConfig.severeErrors.size() > 
0) {
-                StringWriter sw = new StringWriter();
-                PrintWriter out = new PrintWriter(sw);
-                out.println("Severe errors in solr configuration.\n");
-                out.println("Check your log files for more detailed 
information on what may be wrong.\n");
-                out.println("If you want solr to continue after configuration 
errors, change: \n");
-                out.println(" 
<abortOnConfigurationError>false</abortOnConfigurationError>\n");
-                out.println("in " + init.getSolrConfigFilename() + "\n");
-
-                for (Throwable t : SolrConfig.severeErrors) {
-                    
out.println("-------------------------------------------------------------");
-                    t.printStackTrace(out);
-                }
-                out.flush();
-
-                // Servlet containers behave slightly differently if you throw 
an exception during
-                // initialization. Resin will display that error for every 
page, jetty prints it in
-                // the logs, but continues normally. (We will see a 404 rather 
then the real error)
-                // rather then leave the behavior undefined, lets cache the 
error and spit it out
-                // for every request.
-                abortErrorMessage = sw.toString();
-                // throw new ServletException( abortErrorMessage );
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            // restore
-            Thread.currentThread().setContextClassLoader(contextClassLoader);
-        }
-    }
-
-    /** Method to override to change how CoreContainer initialization is 
performed. */
-    protected CoreContainer.Initializer createInitializer() {
-        return new CoreContainer.Initializer();
     }
 
     /**

Added: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrRestServiceImpl.java
==============================================================================
--- (empty file)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/impl/SolrRestServiceImpl.java
  Tue Jan 25 10:53:10 2011
@@ -0,0 +1,105 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.searchandindex.solr.impl;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.amdatu.searchandindex.solr.osgi.Activator;
+import org.amdatu.web.httpcontext.HttpContextServiceFactory;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * This class provides a REST interface on the Solr index service. The REST 
API can be used to create, update
+ * and remove indices from Solr as well as performing index queries.
+ * The base URL for this REST service is /rest/index
+ * @author ivol
+ */
+ at Path("index")
+public class SolrRestServiceImpl implements ResourceProvider {
+    // Services injected by the Felix dependency manager
+    private volatile LogService m_logService;
+    private volatile Component m_contextComponent;
+    private volatile HttpContextServiceFactory m_httpContextServiceFactory;
+    private volatile BundleContext m_bundleContext;
+    private volatile DependencyManager m_dependencyManager;
+
+    // Private members
+    private File m_workDir;
+
+    public SolrRestServiceImpl(File workDir) {
+        m_workDir = workDir;
+    }
+
+    public void init() {
+        m_logService.log(LogService.LOG_INFO, "Initializing Solr REST 
interface");
+        m_contextComponent = 
m_httpContextServiceFactory.create(m_bundleContext, this);
+        registerSolrDispatchFilter();
+    }
+
+    public void destroy() {
+        if (m_contextComponent != null) {
+            m_contextComponent.stop();
+        }
+        m_logService.log(LogService.LOG_INFO, getClass().getName() + " service 
destroyed");
+    }
+
+    public URL getResource(String input) {
+        return null;
+    }
+
+    public String getResourceId() {
+        return Activator.RESOURCE_ID;
+    }
+
+    // Registers the Solr dispatch filter
+    private void registerSolrDispatchFilter() {
+        // Create and register a http servlet filter. This filter is mapped on 
.*
+        Dictionary<String, String> filterProperties = new Hashtable<String, 
String>();
+        filterProperties.put("pattern", "/" + Activator.RESOURCE_ID + 
"(|\\?.*|/.*)");
+        filterProperties.put("service.ranking", "10");
+        filterProperties.put("contextId", Activator.RESOURCE_ID);
+
+        SolrDispatchFilter filter = new SolrDispatchFilter("/" + 
Activator.RESOURCE_ID, m_workDir.getAbsolutePath());
+        m_dependencyManager.add(m_dependencyManager.createComponent()
+            .setImplementation(filter)
+            .setInterface(Filter.class.getName(), filterProperties));
+    }
+
+    /**
+     * This method can be used to check the availability of the Index Service.
+     * GET /rest/index
+     * @return The text "Index service online"
+     */
+    @GET
+    @Produces( { MediaType.TEXT_PLAIN })
+    public String status() {
+        return "Index service online";
+    }
+}

Modified: 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/osgi/Activator.java
==============================================================================
--- 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/osgi/Activator.java
    (original)
+++ 
sandbox/ivol/amdatu-searchandindex/solr/src/main/java/org/amdatu/searchandindex/solr/osgi/Activator.java
    Tue Jan 25 10:53:10 2011
@@ -17,14 +17,13 @@
 package org.amdatu.searchandindex.solr.osgi;
 
 import org.amdatu.core.config.templates.ConfigTemplateManager;
+import org.amdatu.core.tenant.Tenant;
 import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.searchandindex.solr.SolrService;
-import org.amdatu.searchandindex.solr.impl.SolrServiceImpl;
-import org.amdatu.web.httpcontext.HttpContextServiceFactory;
+import org.amdatu.searchandindex.solr.impl.SolrDaemonServiceImpl;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.http.HttpService;
 import org.osgi.service.log.LogService;
 
 /**
@@ -43,13 +42,12 @@
         // Create and register the Solr service.
         manager.add(createComponent()
             .setInterface(SolrService.class.getName(), null)
-            .setImplementation(SolrServiceImpl.class)
+            .setImplementation(SolrDaemonServiceImpl.class)
             
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-            
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
             
.add(createServiceDependency().setService(ConfigTemplateManager.class).setRequired(true))
-            
.add(createServiceDependency().setService(HttpService.class).setRequired(true))
             
.add(createServiceDependency().setService(TenantManagementService.class).setRequired(true))
-            .add(createConfigurationDependency().setPid(SolrService.PID)));
+            .add(createConfigurationDependency().setPid(SolrService.PID))
+            
.add(createServiceDependency().setService(Tenant.class).setCallbacks("onTenantAdded",
 "onTenantRemoved")));
     }
 
     public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {

Modified: sandbox/ivol/amdatu-searchandindex/solr/src/main/resources/solr.xml
==============================================================================
--- sandbox/ivol/amdatu-searchandindex/solr/src/main/resources/solr.xml 
(original)
+++ sandbox/ivol/amdatu-searchandindex/solr/src/main/resources/solr.xml Tue Jan 
25 10:53:10 2011
@@ -1,34 +1,31 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-       <!--
-               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
+  <!--
+    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.
-       -->
+    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.
+  -->
 
-       <!--
-               All (relative) paths are relative to the installation path 
persistent:
-               Save changes made via the API to this file sharedLib: path to a 
lib
-               directory that will be shared across all cores
-       -->
+  <!--
+    All (relative) paths are relative to the installation path persistent:
+    Save changes made via the API to this file sharedLib: path to a lib
+    directory that will be shared across all cores
+  -->
 
 <solr persistent="true">
-       <!--
-               adminPath: RequestHandler path to manage cores. If 'null' (or 
absent),
-               cores will not be manageable via request handler
-       -->
-       <cores adminPath="/admin/cores">
-               <core name="Keyspace1_profile" instanceDir="Keyspace1/profile" 
/>
-               <core name="Keyspace2_profile" instanceDir="Keyspace2/profile" 
/>
-               <core name="Keyspace3_profile" instanceDir="Keyspace3/profile" 
/>
-       </cores>
+  <!--
+    adminPath: RequestHandler path to manage cores. If 'null' (or absent),
+    cores will not be manageable via request handler
+  -->
+  <cores adminPath="/solr/admin/cores">
+  </cores>
 </solr>
\ No newline at end of file

Reply via email to