Search in sources :

Example 16 with PluginInfo

use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.

the class UpdateRequestProcessorChain method getReqProcessors.

static List<UpdateRequestProcessorFactory> getReqProcessors(String processor, SolrCore core) {
    if (processor == null)
        return Collections.emptyList();
    List<UpdateRequestProcessorFactory> result = new ArrayList<>();
    List<String> names = StrUtils.splitSmart(processor, ',');
    for (String s : names) {
        s = s.trim();
        if (s.isEmpty())
            continue;
        UpdateRequestProcessorFactory p = core.getUpdateProcessors().get(s);
        if (p == null) {
            try {
                PluginInfo pluginInfo = new PluginInfo("updateProcessor", Utils.makeMap("name", s, "class", s + "UpdateProcessorFactory", "runtimeLib", "true"));
                PluginBag.PluginHolder<UpdateRequestProcessorFactory> pluginHolder = core.getUpdateProcessors().createPlugin(pluginInfo);
                core.getUpdateProcessors().put(s, p = pluginHolder.get());
            } catch (SolrException e) {
            }
            if (p == null)
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
        }
        result.add(p);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PluginInfo(org.apache.solr.core.PluginInfo) PluginBag(org.apache.solr.core.PluginBag) SolrException(org.apache.solr.common.SolrException)

Example 17 with PluginInfo

use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.

the class BackupRepositoryFactory method newInstance.

public BackupRepository newInstance(SolrResourceLoader loader, String name) {
    Objects.requireNonNull(loader);
    Objects.requireNonNull(name);
    PluginInfo repo = Objects.requireNonNull(backupRepoPluginByName.get(name), "Could not find a backup repository with name " + name);
    BackupRepository result = loader.newInstance(repo.className, BackupRepository.class);
    result.init(repo.initArgs);
    return result;
}
Also used : PluginInfo(org.apache.solr.core.PluginInfo)

Example 18 with PluginInfo

use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.

the class SolrMetricManager method preparePlugin.

private PluginInfo preparePlugin(PluginInfo info, String className, Map<String, String> defaultAttributes, Map<String, Object> defaultInitArgs) {
    if (info == null) {
        return null;
    }
    String classNameAttr = info.attributes.get("class");
    if (className != null) {
        if (classNameAttr != null && !className.equals(classNameAttr)) {
            log.warn("Conflicting class name attributes, expected " + className + " but was " + classNameAttr + ", skipping " + info);
            return null;
        }
    }
    Map<String, String> attrs = new HashMap<>(info.attributes);
    defaultAttributes.forEach((k, v) -> {
        if (!attrs.containsKey(k)) {
            attrs.put(k, v);
        }
    });
    attrs.put("class", className);
    Map<String, Object> initArgs = new HashMap<>();
    if (info.initArgs != null) {
        initArgs.putAll(info.initArgs.asMap(10));
    }
    defaultInitArgs.forEach((k, v) -> {
        if (!initArgs.containsKey(k)) {
            initArgs.put(k, v);
        }
    });
    return new PluginInfo(info.type, attrs, new NamedList(initArgs), null);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NamedList(org.apache.solr.common.util.NamedList) PluginInfo(org.apache.solr.core.PluginInfo)

Example 19 with PluginInfo

use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.

the class SolrMetricManager method loadClusterReporters.

public void loadClusterReporters(PluginInfo[] pluginInfos, CoreContainer cc) {
    // don't load for non-cloud instances
    if (!cc.isZooKeeperAware()) {
        return;
    }
    Map<String, String> attrs = new HashMap<>();
    attrs.put("name", "clusterDefault");
    attrs.put("group", SolrInfoBean.Group.cluster.toString());
    Map<String, Object> initArgs = new HashMap<>();
    initArgs.put("period", DEFAULT_CLOUD_REPORTER_PERIOD);
    List<PluginInfo> infos = prepareCloudPlugins(pluginInfos, SolrInfoBean.Group.cluster.toString(), SolrClusterReporter.class.getName(), attrs, initArgs, null);
    String registryName = getRegistryName(SolrInfoBean.Group.cluster);
    for (PluginInfo info : infos) {
        try {
            SolrMetricReporter reporter = loadReporter(registryName, cc.getResourceLoader(), info, null);
            ((SolrClusterReporter) reporter).setCoreContainer(cc);
        } catch (Exception e) {
            log.warn("Could not load node reporter, pluginInfo=" + info, e);
        }
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PluginInfo(org.apache.solr.core.PluginInfo) SolrClusterReporter(org.apache.solr.metrics.reporters.solr.SolrClusterReporter) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException)

Example 20 with PluginInfo

use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.

the class SolrMetricManager method loadReporters.

// reporter management
/**
   * Create and register {@link SolrMetricReporter}-s specific to a {@link org.apache.solr.core.SolrInfoBean.Group}.
   * Note: reporters that specify neither "group" nor "registry" attributes are treated as universal -
   * they will always be loaded for any group. These two attributes may also contain multiple comma- or
   * whitespace-separated values, in which case the reporter will be loaded for any matching value from
   * the list. If both attributes are present then only "group" attribute will be processed.
   * @param pluginInfos plugin configurations
   * @param loader resource loader
   * @param tag optional tag for the reporters, to distinguish reporters logically created for different parent
   *            component instances.
   * @param group selected group, not null
   * @param registryNames optional child registry name elements
   */
public void loadReporters(PluginInfo[] pluginInfos, SolrResourceLoader loader, String tag, SolrInfoBean.Group group, String... registryNames) {
    if (pluginInfos == null || pluginInfos.length == 0) {
        return;
    }
    String registryName = getRegistryName(group, registryNames);
    for (PluginInfo info : pluginInfos) {
        String target = info.attributes.get("group");
        if (target == null) {
            // no "group"
            target = info.attributes.get("registry");
            if (target != null) {
                String[] targets = target.split("[\\s,]+");
                boolean found = false;
                for (String t : targets) {
                    t = overridableRegistryName(t);
                    if (registryName.equals(t)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    continue;
                }
            } else {
            // neither group nor registry specified.
            // always register this plugin for all groups and registries
            }
        } else {
            // check groups
            String[] targets = target.split("[\\s,]+");
            boolean found = false;
            for (String t : targets) {
                if (group.toString().equals(t)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                continue;
            }
        }
        try {
            loadReporter(registryName, loader, info, tag);
        } catch (Exception e) {
            log.warn("Error loading metrics reporter, plugin info: " + info, e);
        }
    }
}
Also used : PluginInfo(org.apache.solr.core.PluginInfo) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException)

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