Author: rwesten
Date: Wed Nov 23 09:09:34 2011
New Revision: 1205334

URL: http://svn.apache.org/viewvc?rev=1205334&view=rev
Log:
missed this files on my last commit. 

Added:
    incubator/stanbol/trunk/commons/solr/managed/pom.xml   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java
   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java
   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java
   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java
   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.SolrServerProvider
    
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.managed.ManagedSolrServer
    
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties
   (with props)
    
incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java
   (with props)

Added: incubator/stanbol/trunk/commons/solr/managed/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/pom.xml?rev=1205334&view=auto
==============================================================================
--- incubator/stanbol/trunk/commons/solr/managed/pom.xml (added)
+++ incubator/stanbol/trunk/commons/solr/managed/pom.xml Wed Nov 23 09:09:34 
2011
@@ -0,0 +1,327 @@
+<?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
+
+               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.
+       -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+       <modelVersion>4.0.0</modelVersion>
+
+       <parent>
+               <groupId>org.apache.stanbol</groupId>
+               <artifactId>stanbol-parent</artifactId>
+               <version>0.9.0-incubating-SNAPSHOT</version>
+               <relativePath>../../../parent</relativePath>
+       </parent>
+
+       <groupId>org.apache.stanbol</groupId>
+       <artifactId>org.apache.stanbol.commons.solr.managed</artifactId>
+       <packaging>bundle</packaging>
+
+       <name>Apache Stanbol Solr Managed Bundle</name>
+       <description>This bundle provides support for manageing
+  Solr Servers (CoreContainer and SolrCores) within the Stanbol JVM.
+  Managed CoreContainer and SolrCores are registered as OSGI services
+  and may be published via the OSGI http service.
+  </description>
+
+       <inceptionYear>2010</inceptionYear>
+
+       <scm>
+               <connection>
+      
scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/solr/managed
+    </connection>
+               <developerConnection>
+      
scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/commons/solr/managed
+    </developerConnection>
+               <url>http://incubator.apache.org/stanbol</url>
+       </scm>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Export-Package>
+                                                       
org.apache.stanbol.commons.solr.managed;version=${project.version}
+                        </Export-Package>
+                                               <Import-Package>
+                                                       *
+                        </Import-Package>
+                                               <Private-Package>
+                                                       
org.apache.stanbol.commons.solr.managed.impl;version=${project.version},
+                                                       
org.apache.stanbol.commons.solr.managed.standalone;version=${project.version}
+                        </Private-Package>
+                                               
<Embed-Dependency></Embed-Dependency>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-scr-plugin</artifactId>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <dependencies>
+               <!-- Stanbol Commomns dependencies -->
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.commons.stanboltools.datafileprovider</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.commons.solr.core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.stanbol</groupId>
+                       
<artifactId>org.apache.stanbol.commons.solr.web</artifactId>
+               </dependency>
+
+               <!-- OSGI dependencies -->
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.core</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>org.osgi.compendium</artifactId>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.felix</groupId>
+                       
<artifactId>org.apache.felix.scr.annotations</artifactId>
+               </dependency>
+               <!-- generic stuff -->
+               <dependency>
+                       <groupId>commons-io</groupId>
+                       <artifactId>commons-io</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.commons</groupId>
+                       <artifactId>commons-compress</artifactId>
+               </dependency>
+        
+               <!-- Logging -->
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+               </dependency>
+               <!--
+                       for tests NOTE: We also need all the Solr dependencies 
for the Unit
+                       Tests!
+               -->
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+                       <scope>test</scope>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-solrj</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-httpclient</groupId>
+                       <artifactId>commons-httpclient</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-xercesImpl</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-core</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-dataimporthandler</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-dataimporthandler-extras</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-noggit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-commons-csv</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-core</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-analyzers</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-highlighter</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-memory</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-misc</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-queries</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-spellchecker</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-spatial</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-icu</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-icu4j</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.solr</groupId>
+                       <artifactId>solr-analysis-extras</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>jakarta-regexp</groupId>
+                       <artifactId>jakarta-regexp</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>javax.portlet</groupId>
+                       <artifactId>portlet-api</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-codec</groupId>
+                       <artifactId>commons-codec</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-fileupload</groupId>
+                       <artifactId>commons-fileupload</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <!--
+                       already used <dependency> <groupId>commons-io</groupId>
+                       <artifactId>commons-io</artifactId> <scope>test</scope> 
</dependency>
+               -->
+               <dependency>
+                       <groupId>commons-lang</groupId>
+                       <artifactId>commons-lang</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-beanutils</groupId>
+                       <artifactId>commons-beanutils</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>commons-collections</groupId>
+                       <artifactId>commons-collections</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>xml-resolver</groupId>
+                       <artifactId>xml-resolver</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>stax</groupId>
+                       <artifactId>stax-api</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.codehaus.woodstox</groupId>
+                       <artifactId>wstx-asl</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>xalan</groupId>
+                       <artifactId>xalan</artifactId>
+                       <version>2.7.1</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>xalan</groupId>
+                       <artifactId>serializer</artifactId>
+                       <version>2.7.1</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>xml-apis</groupId>
+                       <artifactId>xml-apis</artifactId>
+                       <version>1.3.04</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>javax.servlet</groupId>
+                       <artifactId>servlet-api</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.velocity</groupId>
+                       <artifactId>velocity</artifactId>
+                       <version>1.6.2</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.velocity</groupId>
+                       <artifactId>velocity-tools</artifactId>
+                       <version>2.0</version>
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
+
+</project>

Propchange: incubator/stanbol/trunk/commons/solr/managed/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,321 @@
+/**
+ * 
+ */
+package org.apache.stanbol.commons.solr.managed;
+
+import static 
org.apache.stanbol.commons.solr.managed.ManagedIndexConstants.INDEX_ARCHIVES;
+import static 
org.apache.stanbol.commons.solr.managed.ManagedIndexConstants.INDEX_NAME;
+import static 
org.apache.stanbol.commons.solr.managed.ManagedIndexConstants.SERVER_NAME;
+import static 
org.apache.stanbol.commons.solr.managed.ManagedIndexConstants.SYNCHRONIZED;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.InvalidPropertiesFormatException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.commons.solr.IndexReference;
+import 
org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extends {@link Properties} with getter and setter for the metadata used
+ * by managed Solr indexes.
+ * @author Rupert Westenthaler
+ *
+ */
+public final class IndexMetadata extends Properties {
+    
+    private final Logger log = LoggerFactory.getLogger(IndexMetadata.class);
+    
+    /**
+     * generated
+     */
+    private static final long serialVersionUID = 5831848470486994628L;
+    /**
+     * The Archive currently used for the index
+     */
+    protected static final String ARCHIVE = "Archive";
+    /**
+     * The current state of this index
+     */
+    protected static final String STATE = "State";
+    /**
+     * The Directory of this index on the local file system
+     */
+    protected static final String DIRECTORY = "Directory";
+    /**
+     * If the current {@link #getState()} == {@link ManagedIndexState#ERROR}
+     * this property is used to store the {@link Exception#printStackTrace() 
stack trace}
+     * as reported by the the {@link Exception} that caused the Error
+     */
+    protected static final String STACK_TRACE = "Stack-Trace";
+    
+    private static List<String> EMPTY_LIST_OF_STRING = Collections.emptyList();
+    
+    @Override
+    public synchronized void load(Reader reader) throws IOException {
+        super.load(reader);
+        validate(false);
+    }
+    @Override
+    public synchronized void load(InputStream inStream) throws IOException {
+        super.load(inStream);
+        validate(false);
+    }
+    @Override
+    public synchronized void loadFromXML(InputStream in) throws IOException,
+                                                        
InvalidPropertiesFormatException {
+        super.loadFromXML(in);
+        validate(false);
+    }
+    @Override
+    public void store(OutputStream out, String comments) throws IOException {
+        validate(true);
+        super.store(out, comments);
+    }
+    @Override
+    public void store(Writer writer, String comments) throws IOException {
+        validate(true);
+        super.store(writer, comments);
+    }
+    @Override
+    public synchronized void storeToXML(OutputStream os, String comment) 
throws IOException {
+        validate(true);
+        super.storeToXML(os, comment);
+    }
+    @Override
+    public synchronized void storeToXML(OutputStream os, String comment, 
String encoding) throws IOException {
+        validate(true);
+        super.storeToXML(os, comment, encoding);
+    }
+    @Override
+    @Deprecated
+    public synchronized void save(OutputStream out, String comments) throws 
UnsupportedOperationException{
+        throw new UnsupportedOperationException("deprecated Method not 
supported");
+    }
+    
+    /**
+     * validates the values of the IndexProperties
+     * @throws IOException
+     */
+    private void validate(boolean store) throws IOException {
+        if(isSynchronized() && getIndexArchives().isEmpty()){
+            throw new IOException("Unable to "+(store?"store":"read")+
+                " IndexPropertis where Synchronized=true and no Index-Archives 
are defined!");
+        }
+        ManagedIndexState state = getState();
+        if(state == null){
+            throw new IOException("Unable to "+(store?"store":"read")+
+                " IndexMetadata without the required key '"+STATE+
+                "' set to one of the values '"+
+                Arrays.toString(ManagedIndexState.values())+"'!");
+        }
+        if(isActive()){
+            if(getDirectory() == null){
+                throw new IOException("Unable to "+(store?"store":"read")+
+                    " IndexPropertis where Active=true and no Directory is 
defined!");
+            }
+        }
+        String name = getIndexName();
+        if(name == null || name.isEmpty()){
+            throw new IOException("Unable to "+(store?"store":"read")+
+               " IndexPropertis where the required key '"+
+               INDEX_NAME+"' is not defined or empty!");
+        }
+    }
+    
+    public List<String> getIndexArchives(){
+        String value = getProperty(INDEX_ARCHIVES);
+        return value == null || value.isEmpty() ? 
+                EMPTY_LIST_OF_STRING : Arrays.asList(value.split(","));
+    }
+    public void setIndexArchives(List<String> archives){
+        StringBuilder value = new StringBuilder();
+        boolean first = true;
+        for(String archive:archives){
+            if(archive != null && archive != null){
+                if(!first){
+                    value.append(',');
+                } else {
+                    first = false;
+                }
+                value.append(archive);
+            }
+        }
+        setProperty(INDEX_ARCHIVES, value.toString());
+    }
+    public boolean isSynchronized(){
+        String value = getProperty(SYNCHRONIZED);
+        return value == null ? false : Boolean.parseBoolean(value);
+    }
+    public void setSynchronized(boolean state){
+        setProperty(SYNCHRONIZED, Boolean.toString(state));
+    }
+    public String getArchive(){
+        return getProperty(ARCHIVE);
+    }
+    public void setArchive(String archive){
+        if(archive == null){
+            remove(ARCHIVE);
+        } else if (archive.isEmpty()){
+            throw new IllegalArgumentException("The parsed archive MUST NOT be 
empty!");
+        } else {
+            setProperty(ARCHIVE, archive);
+        }
+    }
+    public String getIndexName(){
+        return getProperty(INDEX_NAME);
+    }
+    public void setIndexName(String name){
+        if(name == null || name.isEmpty()){
+            throw new IllegalArgumentException("The Index-Name MUST NOT be 
NULL nor empty");
+        }
+        setProperty(INDEX_NAME, name);
+    }
+    public String getServerName(){
+        return getProperty(SERVER_NAME);
+    }
+    public void setServerName(String name){
+        if(name == null || name.isEmpty()){
+            throw new IllegalArgumentException("The Server-Name MUST NOT be 
NULL nor empty");
+        }
+        setProperty(SERVER_NAME, name);
+    }
+    public String getDirectory(){
+        return getProperty(DIRECTORY);
+    }
+    public void setDirectory(String directory){
+        if(directory == null){
+            remove(DIRECTORY);
+        } else if (directory.isEmpty()){
+            throw new IllegalArgumentException("The parsed directory MUST NOT 
be empty!");
+        } else {
+            setProperty(DIRECTORY, directory);
+        }
+    }
+    public ManagedIndexState getState(){
+        String state = getProperty(STATE);
+        if(state == null){
+            log.warn("No ManagedIndexState (key: '"+STATE+"') present in the" +
+                       "IndexMetadata for '"+getIndexReference()+"'! -> return 
null");
+            return null;
+        } else {
+            try {
+                return ManagedIndexState.valueOf(state);
+            } catch (IllegalArgumentException e) {
+                log.error("Unable to parse ManagedIndexState from value '"+
+                    state+"'! -> return null",e);
+                return null;
+            }
+        }
+    }
+    /**
+     * Checks if this index is in the {@link ManagedIndexState#ACTIVE} state
+     * @return if this index is active or not
+     * @see #getState()
+     */
+    public boolean isActive(){
+        ManagedIndexState state = getState();
+        return state != null && state == ManagedIndexState.ACTIVE;
+    }
+    /**
+     * Checks if this index is in the {@link ManagedIndexState#INACTIVE} state
+     * @return if this index is inactive or not
+     * @see #getState()
+     */
+    public boolean isInactive(){
+        ManagedIndexState state = getState();
+        return state != null && state == ManagedIndexState.INACTIVE;
+    }
+    /**
+     * Checks if this index is in the {@link ManagedIndexState#ERROR} state
+     * @return if this index has an error or not
+     * @see #getState()
+     */
+    public boolean isError(){
+        ManagedIndexState state = getState();
+        return state != null && state == ManagedIndexState.ERROR;
+    }
+    /**
+     * Checks if this index is in the {@link ManagedIndexState#UNINITIALISED} 
state
+     * @return if this index is still not initialised
+     * @see #getState()
+     */
+    public boolean isUninitialised(){
+        ManagedIndexState state = getState();
+        return state != null && state == ManagedIndexState.UNINITIALISED;
+    }
+    
+    public void setState(ManagedIndexState state){
+        if(state == null){
+            throw new IllegalArgumentException("The parsed ManagedIndexState 
MUST NOT be NULL!");
+        }
+        setProperty(STATE, state.name());
+        if(state != ManagedIndexState.ERROR){
+            remove(STACK_TRACE);
+        }
+    }
+    /**
+     * Getter for the {@link IndexReference} based on the {@link 
#getServerName()} and
+     * {@link #getIndexName()} values
+     * @return the {@link IndexReference} to the index described by this 
metadata
+     */
+    public IndexReference getIndexReference(){
+        return new IndexReference(getServerName(), getIndexName());
+    }
+    /**
+     * Sets the {@link #getState()} to {@link ManagedIndexState#ERROR} and also
+     * stores the stack trace of the parsed {@link Exception} to {@link 
#STACK_TRACE}.
+     * @param e The Exception or <code>null</code> it none
+     */
+    public void setError(Exception e) {
+        setState(ManagedIndexState.ERROR);
+        if(e != null){
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            PrintWriter writer = new PrintWriter(out);
+            //writer.append(e.getMessage());
+            //writer.append('\n');
+            e.printStackTrace(writer);
+            writer.close(); //close and flush the writer
+            setProperty(STACK_TRACE, out.toString());
+            IOUtils.closeQuietly(writer);
+            out = null;
+        }
+    }
+    /**
+     * The stack trace of the Exception caused this index to be in the
+     * {@link ManagedIndexState#ERROR} state or <code>null</code> if not 
present
+     * @return The stack trace or <code>null</code> if not present
+     */
+    public String getErrorStackTrace(){
+        return getProperty(STACK_TRACE);
+    }
+    
+    /**
+     * Converts the parsed {@link IndexMetadata} to an {@link Map} with 
+     * {@link String} keys and values as used by the  {@link DataFileProvider} 
+     * interface
+     * @return the Map with {@link String} as key and values
+     */
+    public static Map<String, String> toStringMap(IndexMetadata metadata){
+        Map<String,String> map = new HashMap<String,String>();
+        for(java.util.Map.Entry<?,?> entry : metadata.entrySet()){
+            map.put((String)entry.getKey(), 
+                entry.getValue() == null ? null : entry.getValue().toString());
+        }
+        return map;
+    }
+}
\ No newline at end of file

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/IndexMetadata.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,43 @@
+package org.apache.stanbol.commons.solr.managed;
+
+public final class ManagedIndexConstants {
+    
+    private ManagedIndexConstants() {/*do not create instances*/}
+    
+    /**
+     * Key used to configure the names for the Index-Archive(s) to be used for
+     * this core. Multiple archives can be parsed by using , as separator.<p>
+     * Note: that a single Archive can also be provided as second parameter. 
+     * If this is the case it will override this value if present in the third 
+     * parameter of 
+     * {@link ManagedSolrServer#createSolrIndex(String, String, 
java.util.Properties) createIndex} and
+     * {@link ManagedSolrServer#updateIndex(String, String, 
java.util.Properties) updateIndex}.
+     */
+    public static final String INDEX_ARCHIVES = "Index-Archive";
+    /**
+     * Key used to specify if an index is synchronized with the provided
+     * Index-Archive. If <code>false</code> the index will be initialised
+     * by the provided Archive and than stay independent (until explicit calls
+     * to {@link ManagedSolrServer#updateIndex(String, String, 
java.util.Properties)}.
+     * If synchronised the index will stay connected with the Archive.
+     * So deleting the archive will also cause the index to get inactive and 
+     * making the Index-Archive available again (e.g. a newer version) will
+     * case an re-initalisation of the index based on the new archive.
+     */
+    public static final String SYNCHRONIZED = "Synchronized";
+    /**
+     * The name of the index. Note that the name can be also specified as the
+     * first parameter of 
+     * {@link ManagedSolrServer#createSolrIndex(String, String, 
java.util.Properties) createIndex} and
+     * {@link ManagedSolrServer#updateIndex(String, String, 
java.util.Properties) updateIndex}.
+     * If this is the case it will override the value provided in the property
+     * file.
+     */
+    public static final String INDEX_NAME = "Index-Name";
+    /**
+     * The name of the server to install this index to. If present the
+     * server will check that the name corresponds to its own name.
+     */
+    public static final String SERVER_NAME = "Server-Name";
+
+}

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,28 @@
+package org.apache.stanbol.commons.solr.managed;
+
+/**
+ * Enumeration for the different states of a managed index
+ * @author Rupert Westenthaler
+ *
+ */
+public enum ManagedIndexState {
+    
+    /**
+     * The index was registered, but required data are still missing
+     */
+    UNINITIALISED,
+    /**
+     * The index is ready, but currently not activated
+     */
+    INACTIVE,
+    /**
+     * The index is active and can be used
+     */
+    ACTIVE,
+    /**
+     * The index encountered an error during Initialisation. The kind of the
+     * Error is available via the {@link IndexMetadata}.
+     */
+    ERROR,
+
+}

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedIndexState.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,269 @@
+/*
+ * 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.stanbol.commons.solr.managed;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Properties;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.stanbol.commons.solr.SolrConstants;
+import org.apache.stanbol.commons.solr.SolrServerProvider;
+import org.apache.stanbol.commons.solr.SolrServerTypeEnum;
+import org.apache.stanbol.commons.solr.utils.ConfigUtils;
+import 
org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.xml.sax.SAXException;
+
+/**
+ * Service that provides an managed Solr server ({@link CoreContainer}). 
+ * This interface allows to register activate, deactivate and remove indexes 
+ * ({@link SolrCore}s)
+ * <p> TODO: Update Javadoc to new Interface!
+ * Note that is only refers to the Files and not the Solr server (or 
EmbeddedSolrServer). Users need to use
+ * the {@link SolrServerProvider#getSolrServer(SolrServerTypeEnum, String, 
String...)} to get an {@link SolrServer} instance
+ * based on the directory provided by this Interface.
+ * <p>
+ * The {@link #MANAGED_SOLR_DIR_PROPERTY} property can be used to define the 
location of the internally
+ * managed index. Implementations need to load this property by the {@link 
ComponentContext} if running within
+ * an OSGI container or otherwise use the system properties. In cases a 
relative path is configured the
+ * "user.dir" need to be used as base. Implementations need also to provide an 
default value in case no
+ * configuration is present.<br>
+ * Implementations need also support property substitution based on the system 
properties for the
+ * {@link #MANAGED_SOLR_DIR_PROPERTY}. E.g. parsing the value 
"${user.home}/.stanbol/indexes" will create the
+ * managed solr indexes within the home directory of the user.
+ * <p>
+ * This Service is also useful if one needs to initialise an own Solr Core for 
the manage Solr Server. In this
+ * case the {@link #getManagedDirectory()} method can be used to get the 
managed Solr directory and new
+ * indices can be added as sub directories. Utility methods for initialising 
cores are available as part of
+ * the {@link ConfigUtils}.
+ * 
+ * @author Rupert Westenthaler
+ * 
+ */
+public interface ManagedSolrServer {
+
+    /**
+     * The name of this server
+     * @return
+     */
+    public String getServerName();
+    /**
+     * This property can be used to configure the location of the internally 
managed EmbeddedSolrServer.
+     * <p>
+     * Configuring an absolute path (starting with {@link File#separatorChar}) 
will cause the index to be
+     * initialised in this directory.
+     * <p>
+     * Configuring an relative value will use
+     * <ul>
+     * <li>the working directory (<code>Systen.getProperty("user.dir")</code>) 
outside of an OSGI environment
+     * <li>the data directory provided by the SolrYard bundle (by calling
+     * {@link BundleContext#getDataFile(String)} with the relative path.
+     * </ul>
+     * In case this property is not present the {@link #DEFAULT_SOLR_DATA_DIR} 
(an relative path) is used.
+     */
+    String MANAGED_SOLR_DIR_PROPERTY = 
"org.apache.stanbol.commons.solr.managed.managedSolrDir";
+    /**
+     * Default value for the relative path used if the {@link 
#MANAGED_SOLR_DIR_PROPERTY} is not present. It
+     * is not required that implementations use this as default.
+     */
+    String DEFAULT_SOLR_DATA_DIR = "indexes";
+
+    
+    /**
+     * Checks if a solrIndex with the parsed name is managed or not. Note that
+     * an Index might be managed, but not yet be initialised. To check if an
+     * index is managed and can be used use {@link #getIndexState(String)
+     * @param index the name of the Solr index to check
+     * @return <code>true</code> only if a Solr index with the parsed name is
+     * already present within the manages Solr directory.
+     * @throws IllegalStateException In case the managed Solr directory can not
+     * be obtained (usually indicates that this component is currently 
+     * deactivated)
+     * @throws IllegalArgumentException In case <code>null</code> or an empty 
+     * string is parsed as solrIndexName
+     */
+    boolean isManagedIndex(String indexName);
+    /**
+     * Getter for the meta data for the index with the parsed name.
+     * @param indexName the name of the index
+     * @return the meta data or <code>null</code> if no index with the parsed 
name
+     * is managed by this server
+     * @throws IllegalArgumentException if <code>null</code> or an empty string
+     * is parsed as indexName.
+     */
+    IndexMetadata getIndexMetadata(String indexName);
+
+    /**
+     * Checks if the managed index is also initialised and ready to be used.
+     * <p>
+     * Indexes are managed as soon as they are announced to the 
SolrDirectoryManager. However when using the
+     * {@link #createSolrIndex(String, String, Properties)} it can not be 
assured that the archive with
+     * the actual data is already available.
+     * <p>
+     * 
+     * @param index
+     *            the name of the index
+     * @return the state of the index or <code>null</code> if not {@link 
#isManagedIndex(String)}
+     * @throws IllegalArgumentException if the parsed name is 
<code>null</code> or empty
+     */
+    ManagedIndexState getIndexState(String indexName);
+
+    /**
+     * Getter for all indexes in a specific state
+     * 
+     * @return A collection with the {@link IndexMetadata} of all managed
+     * indexes in that state. An empty collection in case no index is in the
+     * parsed state
+     * @throws IllegalArgumentException if <code>null</code> is parsed as state
+     */
+    Collection<IndexMetadata> getIndexes(ManagedIndexState state);
+
+    /**
+     * Getter for the directory of the parsed index. Implementations need to 
ensure that returned directories
+     * are valid Solr indices (or Solr Cores)
+     * <p>
+     * Directories returned by this method are typically used as second 
parameter of
+     * {@link SolrServerProvider#getSolrServer(SolrServerTypeEnum, String, 
String...)} to create an {@link SolrServer}
+     * instance.
+     * <p>
+     * If the requested Index is currently initialising, than this method MUST
+     * wait until the initialisation is finished before returning. 
+     * 
+     * @param name
+     *            the name of the requested solr index. 
+     * @return the directory (instanceDir) of the index or <code>null</code> a
+     *         SolrIndex with that name is not managed.
+     * @throws IllegalArgumentException
+     *             if the parsed solrIndexName is <code>null</code> or empty
+     */
+    File getSolrIndexDirectory(String indexName);
+
+    /**
+     * Creates a new Solr Index based on the data in the provided {@link 
ArchiveInputStream}
+     * 
+     * @param name
+     *            the name of the index to create
+     * @param ais
+     *            the stream providing the data for the new index
+     * @return the directory (instanceDir) of the index.
+     * @throws IOException
+     *             On any error while reading from the parsed input stream
+     * @throws SAXException
+     *             On any Error while parsing the {@link SolrCore} 
configuration
+     *             files when registering the core for the parsed data.
+     * @throws IllegalArgumentException
+     *             if the parsed solrIndexName is <code>null</code> or empty
+     */
+    IndexMetadata createSolrIndex(String indexName, ArchiveInputStream ais) 
throws IOException, SAXException;
+
+    /**
+     * Creates a new {@link SolrCore} based on looking up the Index data via 
the {@link DataFileProvider} service
+     * 
+     * @param coreName
+     *            The name of the solrIndex to create
+     * @param indexPath
+     *            the name of the dataFile looked up via the {@link 
DataFileProvider}
+     * @param properties
+     *            Additional properties describing the index
+     * @return the directory (instanceDir) of the index or null if the index 
data could not be found
+     * @throws IllegalArgumentException
+     * @throws IOException
+     */
+    IndexMetadata createSolrIndex(String indexName, String indexPath, 
Properties properties) throws IOException;
+    /**
+     * Creates/Updates the core with the parsed name to the data parsed within 
the
+     * {@link ArchiveInputStream}.
+     * @param name The name for the Index to create/update
+     * @param ais The {@link ArchiveInputStream} used to read the data for the 
+     *             Index to create/update
+     * @return The metadata for the created index
+     * @throws IOException
+     *             On ansy Error while copying the data provided by the parsed
+     *             {@link ArchiveInputStream}
+     * @throws SAXException
+     *             On any Error while parsing the {@link SolrCore} 
configuration
+     *             files when registering the core for the parsed data.
+     */
+    IndexMetadata updateIndex(String indexName,ArchiveInputStream ais) throws 
IOException, SAXException;
+    /**
+     * Updates the data of the core with the parsed name with the data provided
+     * by the resource with the parsed name. The resource is loaded by using 
the
+     * {@link DataFileProvider} infrastructure
+     * @param name
+     * @param resourceName
+     * @param properties
+     * @throws IOException
+     */
+    IndexMetadata updateIndex(String indexName,String resourceName,Properties 
properties) throws IOException;
+    /**
+     * Removes the index with the parsed name and optionally also deletes the
+     * data on the file system.
+     * @param name
+     */
+    void removeIndex(String indexName, boolean deleteFiles);
+    
+    /**
+     * Sets the index with the parsed name to the {@link 
ManagedIndexState#INACTIVE}
+     * state. If the referenced index in not {@link ManagedIndexState#ACTIVE} 
this
+     * method has no effect.
+     * @param indexName the name of the index
+     * @return The current meta data for that index or <code>null</code> if no
+     * index with the parsed name is managed.
+     * @throws IllegalArgumentException if the parsed indexName is 
<code>null</code>
+     * or an empty string
+     */
+    IndexMetadata deactivateIndex(String indexName);
+
+    /**
+     * Can be used to activate an {@link ManagedIndexState#INACTIVE} index. <p>
+     * This does not try to update the index data or to create an index with 
the
+     * parsed name.<p>
+     * If the referenced index is not within the INACTIVE state this call might
+     * be ignored. The resulting state of the index can be retrieved from the
+     * returned {@link IndexMetadata} instance. 
+     * @param indexName the name of the index
+     * @return the {@link IndexMetadata} or <code>null</code> if no index with
+     * the parsed name is managed by this server.
+     * @throws IOException
+     *             On ansy Error while copying the data provided by the parsed
+     *             {@link ArchiveInputStream}
+     * @throws SAXException
+     *             On any Error while parsing the {@link SolrCore} 
configuration
+     *             files when registering the core for the parsed data.
+     * @throws IllegalArgumentException if <code>null</code> or an empty string
+     * is parsed as indexName
+     */
+    IndexMetadata activateIndex(String indexName) throws IOException, 
SAXException;
+    /**
+     * Getter for the directory on the local file system used as working 
directory
+     * for the {@link CoreContainer} managed by this component.
+     * 
+     * @return the directory of the Solr Home used for the internally managed 
{@link CoreContainer} or
+     *         <code>null</code> if running within an OSGI Environment and 
this component is deactivated.
+     * @throws IllegalStateException
+     *             In case the managed Solr directory can not be obtained 
(usually indicates that this
+     *             component is currently deactivated) or initialised.
+     */
+    File getManagedDirectory();
+
+}
\ No newline at end of file

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.SolrServerProvider
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.SolrServerProvider?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.SolrServerProvider
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.SolrServerProvider
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.stanbol.commons.solr.managed.standalone.StandaloneEmbeddedSolrServerProvider

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.managed.ManagedSolrServer
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.managed.ManagedSolrServer?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.managed.ManagedSolrServer
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/META-INF/services/org.apache.stanbol.commons.solr.managed.ManagedSolrServer
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.stanbol.commons.solr.managed.standalone.DefaultStandaloneManagedSolrServerWrapper

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,41 @@
+# 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.
+
+# Properties for ReferencedSolrServer
+org.apache.stanbol.commons.solr.managed.impl.ReferencedSolrServer.name=Apache 
Stanbol Solr: Referenced Solr Server
+org.apache.stanbol.commons.solr.managed.impl.ReferencedSolrServer.description=Allows
 to create a Solr server (CoreContainer) for a directory on the local file 
system. The Solr server and all its cores are registered as OSGI services.
+
+
+org.apache.solr.core.CoreContainer.dir.name=Directory
+org.apache.solr.core.CoreContainer.dir.description=The directory on the local 
file System
+
+# Properties for ManagedSolrServerImpl
+org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl.name=Apache 
Stanbol Solr: Managed Solr Server
+org.apache.stanbol.commons.solr.managed.impl.ManagedSolrServerImpl.description=Allows
 to manage a Solr server by Stanbol. This includes creating, updating and 
removing of SolrCores by directly parsing the Data or by using the 
DataFileProvider infrastructure. Typically users will not need to border with 
this component, because instances are more likely created by other modules.
+
+org.apache.stanbol.commons.solr.managed.managedSolrDir.name=Managed Directory
+org.apache.stanbol.commons.solr.managed.managedSolrDir.description=Allows to 
manually specify the directory where the data for the managed Solr server are 
stored. If empty a reasonable default under the current working directory is 
used. This property supports substitutions (syntax: '${property-name}') with 
properties available for the Bundle context.
+
+
+# commonly used Properties
+
+org.apache.solr.core.CoreContainer.name.name=Name
+org.apache.solr.core.CoreContainer.name.description=The name under that this 
Solr server (CoreContainer) and all its SolrCores are registered as OSGI 
services.
+
+service.ranking.name=Rank
+service.ranking.description=The ranking of this Solr server. If two Solr 
servers with the same Name are registered the one with the higher ranking will 
be used.
+
+org.apache.solr.core.CoreContainer.publishREST.name=Publish RESTful Services
+org.apache.solr.core.CoreContainer.publishREST.description=If true, the 
RESTful API of this SolrServer is allowed to be published on the HTTP service 
of the OSGI Environment. NOTE: the actual publishing is not part of the 
functionality of this component but part of the functionality of the 
"org.apache.commons.solr.web" artifact.

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java?rev=1205334&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java
 (added)
+++ 
incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java
 Wed Nov 23 09:09:34 2011
@@ -0,0 +1,148 @@
+/*
+ * 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.stanbol.commons.solr.managed;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import junit.framework.Assert;
+
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ * Tests the standalone implemention - running outside an OSGI environment - of
+ * the {@link ManagedSolrServer} interface.
+ * @author Rupert Westenthaler
+ *
+ */
+public class ManagedSolrServerTest {
+
+    private static final Logger log = 
LoggerFactory.getLogger(ManagedSolrServerTest.class);
+
+    public static final String TEST_SOLR_CONFIG_NAME = "test";
+    public static final String TEST_YARD_ID = "testYard";
+    public static final String TEST_SOLR_CORE_NAME = "test";
+    protected static final String TEST_INDEX_REL_PATH = File.separatorChar + 
"target" + File.separatorChar
+                                                        + 
ManagedSolrServer.DEFAULT_SOLR_DATA_DIR;
+
+    private static ManagedSolrServer managedSolrServer;
+
+    private static File expectedManagedDirectory;
+    private static Collection<String> expectedIndexNames = 
Arrays.asList("entityhub", "cache");
+
+    @BeforeClass
+    public static void init() throws IOException {
+        // set to "${basedir}/some/rel/path" to test if property substitution 
works!
+        String prefix = System.getProperty("basedir") == null ? "." : 
"${basedir}";
+        String resolvedPrefix = System.getProperty("basedir") == null ? "." : 
System.getProperty("basedir");
+        String solrServerDir = prefix + TEST_INDEX_REL_PATH;
+        log.info("configured directory: " + solrServerDir);
+        System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, 
solrServerDir);
+        // create the SolrDirectoryManager used for the tests
+        Iterator<ManagedSolrServer> providerIt = 
ServiceLoader.load(ManagedSolrServer.class,
+            ManagedSolrServer.class.getClassLoader()).iterator();
+        if (providerIt.hasNext()) {
+            managedSolrServer = providerIt.next();
+        } else {
+            throw new IllegalStateException("Unable to instantiate "
+                                            + 
ManagedSolrServer.class.getSimpleName()
+                                            + " service by using " + 
ServiceLoader.class.getName() + "!");
+        }
+        expectedManagedDirectory = new File(resolvedPrefix, 
+            
TEST_INDEX_REL_PATH+File.separatorChar+managedSolrServer.getServerName());
+        // store the expected managed directory for later testing
+        expectedManagedDirectory = 
expectedManagedDirectory.getAbsoluteFile().getCanonicalFile();
+        log.info("expected managed directory: " + expectedManagedDirectory);
+        //setup the entityhub and the cache index (as it would be done by the 
Entityhub)
+        //to test this initialisation
+        managedSolrServer.createSolrIndex("entityhub", TEST_SOLR_CONFIG_NAME, 
null);
+        //for the cahce we use the default configuration
+        managedSolrServer.createSolrIndex("cache", TEST_SOLR_CONFIG_NAME, 
null);
+    }
+
+    @Test
+    public void testManagedDirectoryInitialisation() {
+        // the managed directory must be set based on the
+        
expectedManagedDirectory.equals(managedSolrServer.getManagedDirectory());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testNullIndexName() {
+        File file = managedSolrServer.getSolrIndexDirectory(null);
+        log.warn("Directory for NULL core: {}",file);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testEmptyIndexName() {
+        managedSolrServer.getSolrIndexDirectory("");
+    }
+
+    @Test
+    public void testGetManagedIndexes() {
+        Set<String> expected = new HashSet<String>(expectedIndexNames);
+        Collection<IndexMetadata> present = 
managedSolrServer.getIndexes(ManagedIndexState.ACTIVE);
+        Collection<String> presentNames = new ArrayList<String>();
+        for (IndexMetadata metadata : present) {
+            presentNames.add(metadata.getIndexName());
+            assertTrue(expected.remove(metadata.getIndexName()));
+            // test that the index dir is the expected location
+            File expectedLocation = new File(expectedManagedDirectory, 
metadata.getIndexName()+File.separatorChar);
+            assertEquals(expectedLocation, new File(metadata.getDirectory()));
+        }
+        // test that the expected indexes where returned
+        assertTrue("The expected Indexes "+expected+" are not present 
(present: "+
+            presentNames+")!",expected.isEmpty());
+    }
+
+    @Test
+    public void testIsManagedIndex() {
+        for (String name : expectedIndexNames) {
+            assertTrue(managedSolrServer.isManagedIndex(name));
+        }
+        assertFalse(managedSolrServer.isManagedIndex("notAnIndex" + 
System.currentTimeMillis()));
+    }
+
+    @Test
+    public void testDefaultIndexInitialisation() throws IOException {
+        // this is actually tested already by the initialisation of the
+        // SolrYardTest ...
+        String indexName = "testIndexInitialisation_" + 
System.currentTimeMillis();
+        IndexMetadata metadata = managedSolrServer.createSolrIndex(indexName, 
+            TEST_SOLR_CONFIG_NAME, null);
+        Assert.assertNotNull("The metadata returned after creating index "+
+            indexName+" MUST NOT be NULL!",metadata);
+        File indexDir = new File(metadata.getDirectory());
+        assertEquals(new File(expectedManagedDirectory, indexName), indexDir);
+        assertTrue(indexDir.isDirectory());
+    }
+}

Propchange: 
incubator/stanbol/trunk/commons/solr/managed/src/test/java/org/apache/stanbol/commons/solr/managed/ManagedSolrServerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to