Search in sources :

Example 21 with PluginInfo

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;
}
Also used : ArrayList(java.util.ArrayList) PluginInfo(org.apache.solr.core.PluginInfo)

Example 22 with PluginInfo

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);
    }
}
Also used : PluginInfo(org.apache.solr.core.PluginInfo) NodeConfig(org.apache.solr.core.NodeConfig)

Example 23 with PluginInfo

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;
}
Also used : PluginInfo(org.apache.solr.core.PluginInfo) File(java.io.File)

Example 24 with PluginInfo

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);
        }
    }
}
Also used : SolrEventListener(org.apache.solr.core.SolrEventListener) PluginInfo(org.apache.solr.core.PluginInfo)

Example 25 with PluginInfo

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);
    }
}
Also used : SolrConfig(org.apache.solr.core.SolrConfig) InputSource(org.xml.sax.InputSource) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) DirectoryFactory(org.apache.solr.core.DirectoryFactory) IndexSchema(org.apache.solr.schema.IndexSchema) PluginInfo(org.apache.solr.core.PluginInfo) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)

Aggregations

PluginInfo (org.apache.solr.core.PluginInfo)25 HashMap (java.util.HashMap)8 Random (java.util.Random)5 IOException (java.io.IOException)4 MockMetricReporter (org.apache.solr.metrics.reporters.MockMetricReporter)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ObjectInstance (javax.management.ObjectInstance)3 NodeConfig (org.apache.solr.core.NodeConfig)3 SolrCore (org.apache.solr.core.SolrCore)3 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)3 Counter (com.codahale.metrics.Counter)2 File (java.io.File)2 NamedList (org.apache.solr.common.util.NamedList)2 SolrInfoBean (org.apache.solr.core.SolrInfoBean)2 SolrMetricProducer (org.apache.solr.metrics.SolrMetricProducer)2 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)2 Before (org.junit.Before)2