use of org.apache.solr.core.CoreDescriptor in project stanbol by apache.
the class RegisteredSolrServerTracker method addingService.
@Override
public SolrServer addingService(ServiceReference reference) {
log.info(" ... in addingService for {} (ref: {})", this.reference, reference);
String coreName;
CoreContainer server;
Object service = super.addingService(reference);
if (service == null) {
log.warn("addingService({}) returned null -> unable to create " + "EmbeddedSolrServer for IndexReference {}", reference, this.reference);
}
if (trackingSolrCore) {
SolrCore core;
//might not be the same as for this classloader
if (service instanceof SolrCore) {
core = (SolrCore) service;
} else {
log.warn("SolrCore fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
context.ungetService(reference);
return null;
}
coreName = core.getName();
CoreDescriptor descriptor = core.getCoreDescriptor();
if (descriptor == null) {
//core not registered with a container!
context.ungetService(reference);
//ignore
return null;
} else {
server = descriptor.getCoreContainer();
}
} else {
if (service instanceof CoreContainer) {
server = (CoreContainer) service;
} else {
log.warn("Solr CoreContainer fitting to IndexReference {} is incompatible to the" + "classloader of bundle [{}]{} - Service [{}] ignored!", new Object[] { reference, context.getBundle().getBundleId(), context.getBundle().getSymbolicName() }, reference.getProperty(Constants.SERVICE_ID));
context.ungetService(reference);
return null;
}
coreName = this.coreName;
}
return new EmbeddedSolrServer(server, coreName);
}
use of org.apache.solr.core.CoreDescriptor in project stanbol by apache.
the class SolrServerAdapter method registerCore.
/**
* Registers a SolrCore based on the parsed configuration. If a SolrCore
* with the same name as provided by the configuration is already present
* it will be replace by this one.
* @param parsedCoreConfig The configuration.
* @return The ServiceReference to the SolrCore.
* @throws SolrException If the core could not be registered
*/
public ServiceReference registerCore(SolrCoreProperties parsedCoreConfig) {
SolrCoreProperties coreConfig = parsedCoreConfig.clone();
String coreName = coreConfig.getCoreName();
log.info("Register Core {} to SolrServerAdapter (coreContainer: {})", coreName, serverProperties.getServerName());
if (coreName == null) {
coreName = server.getDefaultCoreName();
}
File coreDir = coreConfig.getCoreDir();
if (coreDir == null) {
coreDir = new File(serverProperties.getServerDir(), coreName);
}
//SolrCore old = null;
ClassLoader classLoader = updateContextClassLoader();
SolrCore core;
try {
//NOTE: this code depends on the fact that the create method of the
// CoreContainer is overridden by the SolrServerAdapter
// to use the OSGI specific SolrResourceLoader!
core = server.create(new CoreDescriptor(server, coreName, coreDir.getPath()));
//CloseHook is now appied by the overridden registerCore(..) method
//of the wrapped CoreContainer!
//core.addCloseHook(closeHook);
// parse ture as third argument to avoid closing the current core for now
//old =
server.register(coreName, core, true);
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
//NOTE: core registration is now done as part of the registration of the
// SolrCore to the CoreContainer
// ServiceReference coreRef = registerCoreService(coreName,core);
// if(old != null){
// //cleanup the old core
// cleanupSolrCore(old);
// }
// // persist the new core to have it available on the next start
// //server.persist();
// //update the OSGI service is now done by the overridden CoreContainer#create(..)
// //method
// updateServerRegistration();
//so just get the ServiceReference for the ServiceRegistration
CoreRegistration reg = registrations.get(coreName);
if (reg == null) {
throw new IllegalStateException("No OSGI ServiceRegistration present after " + "adding SolrCore '" + coreName + "' to SolrCore!");
} else {
return reg.getServiceReference();
}
}
use of org.apache.solr.core.CoreDescriptor in project stanbol by apache.
the class StandaloneManagedSolrServer method registerCore.
/**
* registers a {@link SolrCore} to the {@link #server} managed by this
* instance. Will replace an already existing {@link SolrCore} with the
* same name
* @param coreName the name of the {@link SolrCore} to register
* @param coreDir the directory for the Core. If <code>null</code> is parsed
* {@link #managedSolrDir}/coreName is used as default.
*/
private void registerCore(String coreName, File coreDir) {
if (coreName == null) {
coreName = server.getDefaultCoreName();
}
if (coreDir == null) {
//use the coreName as default
coreDir = new File(managedSolrDir, coreName);
}
if (!coreDir.isDirectory()) {
throw new IllegalArgumentException("The Core Directory '" + coreDir + " for the Core '" + coreName + "' does not exist or is not an directory");
}
SolrCore core;
CoreDescriptor coreDescriptor = new CoreDescriptor(server, coreName, coreDir.getAbsolutePath());
core = server.create(coreDescriptor);
//this will also replace an existing core with the same name
server.register(coreName, core, false);
//store the new/updated SolrCore in the solr.xml
server.persist();
}
use of org.apache.solr.core.CoreDescriptor 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);
}
use of org.apache.solr.core.CoreDescriptor in project ddf by codice.
the class EmbeddedSolrFactory method getEmbeddedSolrServer.
/**
* Creates a new {@link EmbeddedSolrServer} using the Solr core and configuration file names,
* schema and configuration file proxy provided.
*
* @param coreName name of the Solr core
* @param solrConfigXml name of the Solr configuration file. Defaults to
* {@value HttpSolrClientFactory#DEFAULT_SOLRCONFIG_XML} if
* {@code null}.
* @param schemaXml file name of the Solr core schema. Defaults to
* {@value HttpSolrClientFactory#DEFAULT_SCHEMA_XML} if
* {@code null}.
* @param givenConfigFileProxy {@link ConfigurationFileProxy} instance to use. If {@code null},
* a new {@link ConfigurationFileProxy} will be used.
* @return a new {@link EmbeddedSolrServer} instance
*/
public static EmbeddedSolrServer getEmbeddedSolrServer(String coreName, @Nullable String solrConfigXml, @Nullable String schemaXml, @Nullable ConfigurationFileProxy givenConfigFileProxy) {
LOGGER.debug("Retrieving embedded solr with the following properties: [{},{},{}]", solrConfigXml, schemaXml, givenConfigFileProxy);
String solrConfigFileName = HttpSolrClientFactory.DEFAULT_SOLRCONFIG_XML;
String schemaFileName = HttpSolrClientFactory.DEFAULT_SCHEMA_XML;
if (isNotBlank(solrConfigXml)) {
solrConfigFileName = solrConfigXml;
}
if (isNotBlank(schemaXml)) {
schemaFileName = schemaXml;
}
ConfigurationFileProxy configProxy = givenConfigFileProxy;
if (givenConfigFileProxy == null) {
configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance());
}
configProxy.writeSolrConfiguration(coreName);
File solrConfigFile = getConfigFile(solrConfigFileName, configProxy, coreName);
File solrSchemaFile = getConfigFile(schemaFileName, configProxy, coreName);
if (solrSchemaFile == null) {
solrSchemaFile = getConfigFile("managed-schema", configProxy, coreName);
if (solrSchemaFile == null) {
throw new IllegalArgumentException("Unable to find Solr schema file.");
}
}
File solrConfigHome = new File(solrConfigFile.getParent());
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(EmbeddedSolrFactory.class.getClassLoader());
// NamedSPILoader uses the thread context classloader to lookup
// codecs, posting formats, and analyzers
SolrConfig solrConfig = new SolrConfig(Paths.get(solrConfigHome.getParent()), solrConfigFileName, new InputSource(FileUtils.openInputStream(solrConfigFile)));
IndexSchema indexSchema = new IndexSchema(solrConfig, schemaFileName, new InputSource(FileUtils.openInputStream(solrSchemaFile)));
SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrConfigHome.getAbsolutePath()));
SolrCoreContainer container = new SolrCoreContainer(loader);
String dataDirPath = null;
if (!ConfigurationStore.getInstance().isInMemory()) {
File dataDir = configProxy.getDataDirectory();
if (dataDir != null) {
dataDirPath = Paths.get(dataDir.getAbsolutePath(), coreName, "data").toString();
LOGGER.debug("Using data directory [{}]", dataDirPath);
}
} else {
PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName());
if (info != null && !"solr.RAMDirectoryFactory".equals(info.className)) {
LOGGER.debug("Using in-memory configuration without RAMDirectoryFactory.");
}
}
CoreDescriptor coreDescriptor = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstancePath());
SolrCore core = new SolrCore(coreName, dataDirPath, solrConfig, indexSchema, null, coreDescriptor, null, null, null);
container.register(coreName, core, false, true);
return new EmbeddedSolrServer(container, coreName);
} catch (ParserConfigurationException | IOException | SAXException e) {
throw new IllegalArgumentException("Unable to parse Solr configuration file: " + solrConfigFileName, e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
Aggregations