Search in sources :

Example 1 with StandaloneManagedSolrServer

use of org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer in project stanbol by apache.

the class SolrYardIndexingDestination method initialise.

@Override
public void initialise() {
    log.info("initialise {}", getClass().getSimpleName());
    //The constructors and the setConfiguration(..) only validate the parsed
    //parameters and initialise the member variables. This method performs 
    //the the actual initialisation of the SolrYard!
    //copy a custom configuration (if present)
    EmbeddedSolrServer server;
    IndexReference solrServerRef = IndexReference.parse(solrYardConfig.getSolrServerLocation());
    if (solrIndexConfig != null) {
        //copy the configuration
        try {
            log.info(" ... copy Solr Configuration form {} to {}", solrIndexConfig, solrIndexLocation);
            FileUtils.copyDirectory(solrIndexConfig, solrIndexLocation);
        } catch (IOException e) {
            throw new IllegalStateException(String.format("Unable to copy the Solr index configuration from %s to %s!", solrIndexConfig, solrIndexLocation), e);
        }
        solrYardConfig.setAllowInitialisation(Boolean.FALSE);
        server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrServerRef.getIndex());
        this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
    } else {
        //allow the default initialisation
        solrYardConfig.setAllowInitialisation(Boolean.TRUE);
        StandaloneEmbeddedSolrServerProvider.getInstance();
        server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrServerRef, solrYardConfig.getIndexConfigurationName());
        if (server != null) {
            log.info("   ... initialised SolrCore with default configuration");
            this.core = server.getCoreContainer().getCore(solrServerRef.getIndex());
        } else if (solrServerRef.isPath() && new File(solrServerRef.getIndex()).isAbsolute()) {
            //the parsed absolute path is not within the managed SolrServer
            //so we need to create some CoreContainer and init/register
            //the core at the parsed location
            StandaloneManagedSolrServer s;
            if (solrServerRef.getServer() == null) {
                s = StandaloneManagedSolrServer.getManagedServer();
            } else {
                s = StandaloneManagedSolrServer.getManagedServer(solrServerRef.getServer());
            }
            CoreContainer cc = s.getCoreContainer();
            CoreDescriptor cd = new CoreDescriptor(cc, "dummy", solrServerRef.getIndex());
            this.core = cc.create(cd);
            cc.register(core, false);
            server = new EmbeddedSolrServer(cc, "dummy");
            log.info("   ... initialised existing SolrCore at {}", solrServerRef.getIndex());
        } else {
            throw new IllegalStateException("Unable to initialise SolrCore " + solrServerRef);
        }
    }
    log.info("   ... create SolrYard");
    this.solrYard = new SolrYard(server, solrYardConfig, namespacePrefixService);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CoreDescriptor(org.apache.solr.core.CoreDescriptor) StandaloneManagedSolrServer(org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer) IOException(java.io.IOException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) IndexReference(org.apache.stanbol.commons.solr.IndexReference) File(java.io.File) SolrYard(org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)1 CoreContainer (org.apache.solr.core.CoreContainer)1 CoreDescriptor (org.apache.solr.core.CoreDescriptor)1 IndexReference (org.apache.stanbol.commons.solr.IndexReference)1 StandaloneManagedSolrServer (org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer)1 SolrYard (org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)1