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);
}
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());
}
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;
}
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);
}
}
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));
}
Aggregations