Search in sources :

Example 6 with IndexReference

use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.

the class SolrYardComponent method activate.

@Activate
protected void activate(ComponentContext ctx) throws ConfigurationException {
    this.context = ctx.getBundleContext();
    @SuppressWarnings("unchecked") SolrYardConfig config = new SolrYardConfig((Dictionary<String, Object>) ctx.getProperties());
    log.info("activate {} (name:{})", getClass().getSimpleName(), config.getId());
    String indexLocation = config.getSolrServerLocation();
    if (indexLocation.startsWith("http") && indexLocation.indexOf("://") > 0) {
        solrServer = new HttpSolrServer(indexLocation);
        //directly register configs that use a remote server
        updateSolrYardRegistration(solrServer, config);
    } else {
        //locally managed Server
        IndexReference solrServerRef = IndexReference.parse(config.getSolrServerLocation());
        //default
        if (config.isAllowInitialisation() && solrServerRef.getServer() != null) {
            throw new ConfigurationException(SolrYardConfig.SOLR_SERVER_LOCATION, "The SolrServerLocation ({server-name}:{index-name}) MUST NOT define a " + "{server-name} if '" + SolrYardConfig.ALLOW_INITIALISATION_STATE + "' is enabled. Change the cofiguration to use just a {index-name}");
        }
        //check if we need to init the SolrIndex
        initManagedSolrIndex(managedSolrServer, config);
    }
    //globally set the config
    this.config = config;
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) HttpSolrServer(org.apache.solr.client.solrj.impl.HttpSolrServer) IndexReference(org.apache.stanbol.commons.solr.IndexReference) Activate(org.apache.felix.scr.annotations.Activate)

Example 7 with IndexReference

use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.

the class ConfiguredSolrCoreTracker method unbindManagedSolrServer.

protected void unbindManagedSolrServer(ManagedSolrServer managedSolrServer) {
    if (this.managedSolrServer == managedSolrServer || solrCoreId != null) {
        IndexReference indexReference = IndexReference.parse(solrCoreId);
        if (!indexReference.checkServer(managedSolrServer.getServerName())) {
            return;
        }
        String indexName = indexReference.getIndex();
        IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
        if (indexMetadata != null && indexMetadata.isActive()) {
            managedSolrServer.deactivateIndex(indexName);
        }
        this.managedSolrServer = null;
    }
}
Also used : IndexMetadata(org.apache.stanbol.commons.solr.managed.IndexMetadata) IndexReference(org.apache.stanbol.commons.solr.IndexReference)

Example 8 with IndexReference

use of org.apache.stanbol.commons.solr.IndexReference 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

IndexReference (org.apache.stanbol.commons.solr.IndexReference)8 SolrServer (org.apache.solr.client.solrj.SolrServer)5 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)5 SolrYard (org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)4 IOException (java.io.IOException)3 SolrYardConfig (org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig)3 BeforeClass (org.junit.BeforeClass)3 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)2 HttpSolrServer (org.apache.solr.client.solrj.impl.HttpSolrServer)2 RegisteredSolrServerTracker (org.apache.stanbol.commons.solr.RegisteredSolrServerTracker)2 IndexMetadata (org.apache.stanbol.commons.solr.managed.IndexMetadata)2 StandaloneManagedSolrServer (org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2 SAXException (org.xml.sax.SAXException)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)1 Activate (org.apache.felix.scr.annotations.Activate)1