use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class FstLinkingEngineTest method setup.
@BeforeClass
public static void setup() throws Exception {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: {}", solrServerDir);
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setAllowInitialisation(false);
// the dbpedia default data
config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
// init from datafile provider
config.setAllowInitialisation(true);
config.setName("DBpedia.org default data");
config.setDescription("Data used for FstLinkingEngie tests");
// create the Yard used for the tests
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrIndexRef, config.getIndexConfigurationName());
Assert.assertNotNull("Unable to initialise SolrServer for testing", server);
core = ((EmbeddedSolrServer) server).getCoreContainer().getCore(solrIndexRef.getIndex());
Assert.assertNotNull("Unable to get SolrCore '" + config.getIndexConfigurationName() + "' from SolrServer " + server, core);
yard = new SolrYard(server, config, null);
// setup the index configuration
LanguageConfiguration langConf = new LanguageConfiguration("not.used", new String[] { "en;field=dbpedia-ont:surfaceForm;generate=true" });
fstConfig = new IndexConfiguration(langConf, core, FieldEncodingEnum.SolrYard, "");
fstConfig.setExecutorService(Executors.newFixedThreadPool(1));
fstConfig.setTypeField("rdf:type");
fstConfig.setRankingField("entityhub:entityRank");
// fstConfig.setEntityCacheManager(new FastLRUCacheManager(2048));
fstConfig.setOrigin(new PlainLiteralImpl(TEST_ORIGIN));
// activate the FST config
// activate this configuration
fstConfig.activate();
// validate that the index contains the expected entities
validateTestIndex();
// now create the FST models
List<Future<?>> creationTasks = new ArrayList<Future<?>>();
for (CorpusInfo corpus : fstConfig.getCorpora()) {
Assert.assertTrue("Failure in UnitTest - all FST models need to be generate=true", corpus.allowCreation);
if (!corpus.isFstFile()) {
// create a task on the FST corpus creation service
creationTasks.add(fstConfig.getExecutorService().submit(new CorpusCreationTask(fstConfig, corpus)));
}
}
// typical hardware
for (Future<?> future : creationTasks) {
try {
future.get(FST_CREATION_WAIT_TIME, TimeUnit.SECONDS);
} catch (TimeoutException e) {
// we assert on future.isDone instead
}
Assert.assertTrue("FST Model creation not finished after " + FST_CREATION_WAIT_TIME + "seconds", future.isDone());
}
}
use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class ConfiguredSolrCoreTracker method configureSolrCore.
protected void configureSolrCore(Dictionary<String, Object> config, String solrCoreProperty, String defaultCoreId, String solrCoreConfigProperty) throws ConfigurationException {
Object solrCoreInfo = config.get(solrCoreProperty);
if (solrCoreInfo instanceof SolrServer) {
// Bind a fixed Solr server client instead of doing dynamic OSGi lookup using the service tracker.
// This can be useful both for unit-testing .
solrServer = (SolrServer) config.get(solrCoreProperty);
solrCoreConfig = TopicClassificationEngine.DEFAULT_SOLR_CORE_CONFIG;
} else {
if (context == null) {
throw new ConfigurationException(solrCoreProperty, solrCoreProperty + " should be a SolrServer instance for using" + " the engine without any OSGi context. Got: " + solrCoreId);
}
if (solrCoreInfo != null && !solrCoreInfo.toString().trim().isEmpty()) {
this.solrCoreId = solrCoreInfo.toString().trim();
} else {
this.solrCoreId = defaultCoreId;
}
solrCoreConfig = getRequiredStringParam(config, solrCoreConfigProperty, this.solrCoreId + ".solrindex.zip");
try {
IndexReference indexReference = IndexReference.parse(solrCoreId);
// String configName = getRequiredStringParam(config, SOLR_CONFIG, defaultValue)
indexReference = checkInitSolrIndex(indexReference, solrCoreConfig);
// track the solr core OSGi updates
indexTracker = new RegisteredSolrServerTracker(context.getBundleContext(), indexReference);
indexTracker.open();
} catch (Exception e) {
throw new ConfigurationException(solrCoreProperty, e.getMessage(), e);
}
}
}
use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class LDPathTestBase method setup.
@BeforeClass
public static void setup() throws Exception {
// get the working directory
// use property substitution to test this feature!
String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
String solrServerDir = prefix + TEST_INDEX_REL_PATH;
log.info("Test Solr Server Directory: {}", solrServerDir);
System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
config.setAllowInitialisation(false);
// the dbpedia default data
config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
// init from datafile provider
config.setAllowInitialisation(true);
config.setName("DBpedia.org default data");
config.setDescription("Data used for the LDPath setup");
// create the Yard used for the tests
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(solrIndexRef, config.getIndexConfigurationName());
Assert.assertNotNull("Unable to initialise SolrServer for testing", server);
yard = new SolrYard(server, config, null);
backend = new YardBackend(yard);
}
use of org.apache.stanbol.commons.solr.IndexReference in project stanbol by apache.
the class SolrYardComponent method initManagedSolrIndex.
/**
* initialise ManagedSolrIndex and that starts tracking for the {@link SolrCore}
* @param managedServer the managedServer to init the SolrCore (if necessary)
* @param config the {@link SolrYardConfig}
* @throws IllegalStateException if the initialization fails
*/
private void initManagedSolrIndex(final ManagedSolrServer managedServer, final SolrYardConfig config) {
if (managedServer == null || config == null) {
// component was not yet activated ... will be called again
return;
}
IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
if (config.isAllowInitialisation()) {
// are we allowed to create the SolrServer
// get the name of the config to be used (default: default.solrindex.zip")
String configName = config.getIndexConfigurationName();
IndexMetadata metadata = managedServer.getIndexMetadata(solrIndexRef.getIndex());
if (metadata == null) {
// create a new index
log.info(" ... creating Managed SolrIndex {} (configName: {}) on Server {}", new Object[] { solrIndexRef.getIndex(), configName, managedServer.getServerName() });
try {
metadata = managedServer.createSolrIndex(solrIndexRef.getIndex(), configName, null);
} catch (IOException e) {
throw new IllegalStateException("Unable to create Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
} else if (metadata.getState() != ManagedIndexState.ACTIVE) {
log.info(" ... activating Managed SolrIndex {} on Server {} (current state: {})", new Object[] { solrIndexRef.getIndex(), managedServer.getServerName(), metadata.getState() });
try {
managedServer.activateIndex(metadata.getIndexName());
} catch (IOException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
} catch (SAXException e) {
throw new IllegalStateException("Unable to activate Managed SolrIndex " + solrIndexRef.getIndex() + " (configName: " + configName + ") on Server " + managedServer.getServerName() + "!", e);
}
}
// else already active nothing todo
solrIndexRef = metadata.getIndexReference();
}
// else the SolrServer will be supplied (e.g. created by installing a full index)
try {
registeredServerTracker = new RegisteredSolrServerTracker(context, solrIndexRef, null) {
@Override
public void removedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.removedService(reference, service);
}
@Override
public void modifiedService(ServiceReference reference, Object service) {
updateSolrYardRegistration(registeredServerTracker.getService(), config);
super.modifiedService(reference, service);
}
@Override
public SolrServer addingService(ServiceReference reference) {
SolrServer server = super.addingService(reference);
if (solrServer != null) {
log.warn("Multiple SolrServer for IndexLocation {} available!", config.getSolrServerLocation());
} else {
updateSolrYardRegistration(server, config);
}
return server;
}
};
log.info(" ... start tracking for SolrCore based on {}", solrIndexRef);
// start tracking
registeredServerTracker.open();
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Unable to track Managed SolrIndex " + solrIndexRef.getIndex() + "on Server " + managedServer.getServerName() + "!", e);
}
}
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;
}
Aggregations