use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrMetricManager method prepareCloudPlugins.
private List<PluginInfo> prepareCloudPlugins(PluginInfo[] pluginInfos, String group, String className, Map<String, String> defaultAttributes, Map<String, Object> defaultInitArgs, PluginInfo defaultPlugin) {
List<PluginInfo> result = new ArrayList<>();
if (pluginInfos == null) {
pluginInfos = new PluginInfo[0];
}
for (PluginInfo info : pluginInfos) {
String groupAttr = info.attributes.get("group");
if (!group.equals(groupAttr)) {
continue;
}
info = preparePlugin(info, className, defaultAttributes, defaultInitArgs);
if (info != null) {
result.add(info);
}
}
if (result.isEmpty() && defaultPlugin != null) {
defaultPlugin = preparePlugin(defaultPlugin, className, defaultAttributes, defaultInitArgs);
if (defaultPlugin != null) {
result.add(defaultPlugin);
}
}
return result;
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrCoreMetricManager method loadReporters.
/**
* Load reporters configured globally and specific to {@link org.apache.solr.core.SolrInfoBean.Group#core}
* group or with a registry name specific to this core.
*/
public void loadReporters() {
NodeConfig nodeConfig = core.getCoreContainer().getConfig();
PluginInfo[] pluginInfos = nodeConfig.getMetricsConfig().getMetricReporters();
metricManager.loadReporters(pluginInfos, core.getResourceLoader(), tag, SolrInfoBean.Group.core, registryName);
if (cloudMode) {
metricManager.loadShardReporters(pluginInfos, core);
}
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class IndexSchemaFactory method getResourceNameToBeUsed.
/**
* Returns the resource name that will be used: if the schema is managed, the resource
* name will be drawn from the schema factory configuration in the given SolrConfig.
* Otherwise, the given resourceName will be returned.
*
* @param resourceName The name to use if the schema is not managed
* @param config The SolrConfig from which to get the schema factory config
* @return If the schema is managed, the resource name from the given SolrConfig,
* otherwise the given resourceName.
*/
public static String getResourceNameToBeUsed(String resourceName, SolrConfig config) {
PluginInfo info = config.getPluginInfo(IndexSchemaFactory.class.getName());
final String nonManagedResourceName = null == resourceName ? IndexSchema.DEFAULT_SCHEMA_FILE : resourceName;
if (null == info) {
return nonManagedResourceName;
}
String managedSchemaResourceName = (String) info.initArgs.get(ManagedIndexSchemaFactory.MANAGED_SCHEMA_RESOURCE_NAME);
if (null == managedSchemaResourceName) {
managedSchemaResourceName = ManagedIndexSchemaFactory.DEFAULT_MANAGED_SCHEMA_RESOURCE_NAME;
}
if ((new File(config.getResourceLoader().getConfigDir(), managedSchemaResourceName)).exists()) {
return managedSchemaResourceName;
}
return nonManagedResourceName;
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class UpdateHandler method parseEventListeners.
private void parseEventListeners() {
final Class<SolrEventListener> clazz = SolrEventListener.class;
final String label = "Event Listener";
for (PluginInfo info : core.getSolrConfig().getPluginInfos(SolrEventListener.class.getName())) {
String event = info.attributes.get("event");
if ("postCommit".equals(event)) {
SolrEventListener obj = core.createInitInstance(info, clazz, label, null);
commitCallbacks.add(obj);
log.info("added SolrEventListener for postCommit: " + obj);
} else if ("postOptimize".equals(event)) {
SolrEventListener obj = core.createInitInstance(info, clazz, label, null);
optimizeCallbacks.add(obj);
log.info("added SolrEventListener for postOptimize: " + obj);
}
}
}
use of org.apache.solr.core.PluginInfo 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