Search in sources :

Example 1 with EmbeddedSolrServerConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration in project jackrabbit-oak by apache.

the class EmbeddedSolrServerConfigurationProvider method activate.

@Activate
protected void activate(ComponentContext componentContext) throws Exception {
    solrHome = String.valueOf(componentContext.getProperties().get(SOLR_HOME_PATH));
    File file = new File(solrHome);
    if (!file.exists()) {
        assert file.createNewFile();
    }
    solrCoreName = String.valueOf(componentContext.getProperties().get(SOLR_CORE_NAME));
    solrServerConfiguration = new EmbeddedSolrServerConfiguration(solrHome, solrCoreName);
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) File(java.io.File) Activate(org.apache.felix.scr.annotations.Activate)

Example 2 with EmbeddedSolrServerConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration in project jackrabbit-oak by apache.

the class EmbeddedSolrServerProviderTest method testEmbeddedSolrServerInitialization.

@Test
public void testEmbeddedSolrServerInitialization() throws Exception {
    URI uri = getClass().getResource("/solr").toURI();
    File file = new File(uri);
    EmbeddedSolrServerConfiguration solrServerConfiguration = new EmbeddedSolrServerConfiguration(file.getAbsolutePath(), "oak");
    EmbeddedSolrServerProvider embeddedSolrServerProvider = new EmbeddedSolrServerProvider(solrServerConfiguration);
    SolrClient solrServer = embeddedSolrServerProvider.getSolrServer();
    assertNotNull(solrServer);
    SolrPingResponse ping = solrServer.ping();
    assertNotNull(ping);
    assertEquals(0, ping.getStatus());
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) SolrClient(org.apache.solr.client.solrj.SolrClient) URI(java.net.URI) File(java.io.File) Test(org.junit.Test)

Example 3 with EmbeddedSolrServerConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration in project jackrabbit-oak by apache.

the class OakSolrServer method getServer.

private synchronized SolrClient getServer(SolrRequest request) throws Exception {
    boolean isIndex = request.getPath().contains("/update");
    SolrServerRegistry.Strategy strategy = isIndex ? SolrServerRegistry.Strategy.INDEXING : SolrServerRegistry.Strategy.SEARCHING;
    SolrClient solrServer = SolrServerRegistry.get(solrServerConfiguration, strategy);
    if (solrServer == null) {
        if (solrServerConfiguration instanceof EmbeddedSolrServerConfiguration) {
            solrServer = solrServerProvider.getSolrServer();
            // the same Solr server has to be used for both
            SolrServerRegistry.register(solrServerConfiguration, solrServer, SolrServerRegistry.Strategy.INDEXING);
            SolrServerRegistry.register(solrServerConfiguration, solrServer, SolrServerRegistry.Strategy.SEARCHING);
        } else {
            solrServer = isIndex ? solrServerProvider.getIndexingSolrServer() : solrServerProvider.getSearchingSolrServer();
            SolrServerRegistry.register(solrServerConfiguration, solrServer, strategy);
        }
    }
    return solrServer;
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 4 with EmbeddedSolrServerConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration in project jackrabbit-oak by apache.

the class NodeStateSolrServerConfigurationProvider method getSolrServerConfiguration.

@Nonnull
@Override
public SolrServerConfiguration<SolrServerProvider> getSolrServerConfiguration() {
    String type = getStringValueFor(Properties.SERVER_TYPE, null);
    if ("embedded".equalsIgnoreCase(type)) {
        String solrHomePath = getStringValueFor(Properties.SOLRHOME_PATH, SolrServerConfigurationDefaults.SOLR_HOME_PATH);
        String coreName = getStringValueFor(Properties.CORE_NAME, SolrServerConfigurationDefaults.CORE_NAME);
        String context = getStringValueFor(Properties.CONTEXT, null);
        Integer httpPort = Integer.valueOf(getStringValueFor(Properties.HTTP_PORT, "0"));
        if (context != null && httpPort > 0) {
            return (SolrServerConfiguration) new EmbeddedSolrServerConfiguration(solrHomePath, coreName).withHttpConfiguration(context, httpPort);
        } else {
            return (SolrServerConfiguration) new EmbeddedSolrServerConfiguration(solrHomePath, coreName);
        }
    } else if ("remote".equalsIgnoreCase(type)) {
        String solrZkHost = getStringValueFor(Properties.ZK_HOST, null);
        String solrCollection = getStringValueFor(Properties.COLLECTION, SolrServerConfigurationDefaults.COLLECTION);
        int solrReplicationFactor = getIntValueFor(Properties.REPLICATION_FACTOR, SolrServerConfigurationDefaults.REPLICATION_FACTOR);
        String solrConfDir = getStringValueFor(Properties.CONFIGURATION_DIRECTORY, SolrServerConfigurationDefaults.CONFIGURATION_DIRECTORY);
        String solrHttpUrls = getStringValueFor(Properties.HTTP_URL, SolrServerConfigurationDefaults.HTTP_URL);
        int solrShardsNo = getIntValueFor(Properties.SHARDS_NO, SolrServerConfigurationDefaults.SHARDS_NO);
        int socketTimeout = getIntValueFor(Properties.SOCKET_TIMEOUT, SolrServerConfigurationDefaults.SOCKET_TIMEOUT);
        int connectionTimeout = getIntValueFor(Properties.CONNECTION_TIMEOUT, SolrServerConfigurationDefaults.CONNECTION_TIMEOUT);
        return (SolrServerConfiguration) new RemoteSolrServerConfiguration(solrZkHost, solrCollection, solrShardsNo, solrReplicationFactor, solrConfDir, socketTimeout, connectionTimeout, solrHttpUrls);
    } else {
        throw new RuntimeException("unexpected Solr server type: " + type);
    }
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) RemoteSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.RemoteSolrServerConfiguration) RemoteSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.RemoteSolrServerConfiguration) EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) SolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfiguration) Nonnull(javax.annotation.Nonnull)

Example 5 with EmbeddedSolrServerConfiguration

use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration in project jackrabbit-oak by apache.

the class SolrOakRepositoryStub method preCreateRepository.

@Override
protected void preCreateRepository(Jcr jcr) {
    File f = new File("target" + File.separatorChar + "queryjcrtest-" + System.currentTimeMillis());
    final SolrClient solrServer;
    try {
        solrServer = new EmbeddedSolrServerProvider(new EmbeddedSolrServerConfiguration(f.getPath(), "oak")).getSolrServer();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    SolrServerProvider solrServerProvider = new SolrServerProvider() {

        @Override
        public void close() throws IOException {
        }

        @CheckForNull
        @Override
        public SolrClient getSolrServer() throws Exception {
            return solrServer;
        }

        @Override
        public SolrClient getIndexingSolrServer() throws Exception {
            return solrServer;
        }

        @Override
        public SolrClient getSearchingSolrServer() throws Exception {
            return solrServer;
        }
    };
    try {
        assertNotNull(solrServer);
        // safely remove any previous document on the index
        solrServer.deleteByQuery("*:*");
        solrServer.commit();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Nonnull
        @Override
        public CommitPolicy getCommitPolicy() {
            return CommitPolicy.HARD;
        }
    };
    OakSolrConfigurationProvider oakSolrConfigurationProvider = new DefaultSolrConfigurationProvider(configuration);
    jcr.with(new SolrIndexInitializer(false)).with(AggregateIndexProvider.wrap(new SolrQueryIndexProvider(solrServerProvider, oakSolrConfigurationProvider))).with(new NodeStateSolrServersObserver()).with(new SolrIndexEditorProvider(solrServerProvider, oakSolrConfigurationProvider));
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) DefaultSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfigurationProvider) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) SolrIndexInitializer(org.apache.jackrabbit.oak.plugins.index.solr.util.SolrIndexInitializer) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) OakSolrConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider) SolrClient(org.apache.solr.client.solrj.SolrClient) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) SolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.SolrServerProvider) SolrQueryIndexProvider(org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndexProvider) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) NodeStateSolrServersObserver(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServersObserver) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) File(java.io.File) SolrIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider)

Aggregations

EmbeddedSolrServerConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration)7 File (java.io.File)5 SolrClient (org.apache.solr.client.solrj.SolrClient)4 EmbeddedSolrServerProvider (org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider)3 IOException (java.io.IOException)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 Nonnull (javax.annotation.Nonnull)1 RepositoryException (javax.jcr.RepositoryException)1 Activate (org.apache.felix.scr.annotations.Activate)1 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)1 DefaultSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfigurationProvider)1 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)1 OakSolrConfigurationProvider (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfigurationProvider)1 RemoteSolrServerConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.RemoteSolrServerConfiguration)1 SolrServerConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfiguration)1 NodeStateSolrServersObserver (org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServersObserver)1 SolrIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider)1