org.apache.solr.core.PluginInfo Java Examples

The following examples show how to use org.apache.solr.core.PluginInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Counter} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Counter> counterSupplier(SolrResourceLoader loader, PluginInfo info) {
  if (info == null || info.className == null || info.className.trim().isEmpty()) {
    return new DefaultCounterSupplier();
  }

  MetricRegistry.MetricSupplier<Counter> supplier;
  try {
    supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
  } catch (Exception e) {
    log.warn("Error creating custom Counter supplier (will use default): {}", info, e);
    supplier = new DefaultCounterSupplier();
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example #2
Source File: SolrConfigHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
private boolean verifyClass(CommandOperation op, String clz, @SuppressWarnings({"rawtypes"})Class expected) {
  if (clz == null) return true;
  if (!"true".equals(String.valueOf(op.getStr("runtimeLib", null)))) {
    PluginInfo info = new PluginInfo(SolrRequestHandler.TYPE, op.getDataMap());
    //this is not dynamically loaded so we can verify the class right away
    try {
      if(expected == Expressible.class) {
        @SuppressWarnings("resource")
        SolrResourceLoader resourceLoader = info.pkgName == null ?
            req.getCore().getResourceLoader() :
            req.getCore().getResourceLoader(info.pkgName);
        resourceLoader.findClass(info.className, expected);
      } else {
        req.getCore().createInitInstance(info, expected, clz, "");
      }
    } catch (Exception e) {
      log.error("Error checking plugin : ", e);
      op.addError(e.getMessage());
      return false;
    }

  }
  return true;
}
 
Example #3
Source File: SolrMetricManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private List<PluginInfo> prepareCloudPlugins(PluginInfo[] pluginInfos, String group,
                                             Map<String, String> defaultAttributes,
                                             Map<String, Object> defaultInitArgs) {
  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, defaultAttributes, defaultInitArgs);
    if (info != null) {
      result.add(info);
    }
  }
  return result;
}
 
Example #4
Source File: SolrMetricManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private PluginInfo preparePlugin(PluginInfo info, Map<String, String> defaultAttributes,
                                 Map<String, Object> defaultInitArgs) {
  if (info == null) {
    return null;
  }
  String classNameAttr = info.attributes.get("class");

  Map<String, String> attrs = new HashMap<>(info.attributes);
  defaultAttributes.forEach((k, v) -> {
    if (!attrs.containsKey(k)) {
      attrs.put(k, v);
    }
  });
  attrs.put("class", classNameAttr);
  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);
}
 
Example #5
Source File: SolrMetricManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void loadShardReporters(PluginInfo[] pluginInfos, SolrCore core) {
  // don't load for non-cloud cores
  if (core.getCoreDescriptor().getCloudDescriptor() == null) {
    return;
  }
  // prepare default plugin if none present in the config
  Map<String, String> attrs = new HashMap<>();
  attrs.put("name", "shardDefault");
  attrs.put("group", SolrInfoBean.Group.shard.toString());
  Map<String, Object> initArgs = new HashMap<>();
  initArgs.put("period", DEFAULT_CLOUD_REPORTER_PERIOD);

  String registryName = core.getCoreMetricManager().getRegistryName();
  // collect infos and normalize
  List<PluginInfo> infos = prepareCloudPlugins(pluginInfos, SolrInfoBean.Group.shard.toString(),
      attrs, initArgs);
  for (PluginInfo info : infos) {
    try {
      loadReporter(registryName, core, info, core.getMetricTag());
    } catch (Exception e) {
      log.warn("Could not load shard reporter, pluginInfo={}", info, e);
    }
  }
}
 
Example #6
Source File: SolrMetricManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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(),
      attrs, initArgs);
  String registryName = getRegistryName(SolrInfoBean.Group.cluster);
  for (PluginInfo info : infos) {
    try {
      loadReporter(registryName, cc, info);
    } catch (Exception e) {
      log.warn("Could not load cluster reporter, pluginInfo={}", info, e);
    }
  }
}
 
Example #7
Source File: SolrMetricReporter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a {@link SolrMetricReporter} with the plugin's configuration.
 *
 * @param pluginInfo the plugin's configuration
 */
@SuppressWarnings("unchecked")
public void init(PluginInfo pluginInfo) {
  if (pluginInfo != null) {
    this.pluginInfo = pluginInfo.copy();
    if (this.pluginInfo.initArgs != null) {
      SolrPluginUtils.invokeSetters(this, this.pluginInfo.initArgs);
    }
  }
  validate();
  if (!enabled) {
    log.info("Reporter disabled for registry {}", registryName);
    return;
  }
  log.debug("Initializing for registry {}", registryName);
  doInit();
}
 
Example #8
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Histogram} supplier.
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Histogram> histogramSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Histogram> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultHistogramSupplier(loader);
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Histogram supplier (will use default): {}", info, e);
      supplier = new DefaultHistogramSupplier(loader);
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example #9
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Timer} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Timer> timerSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Timer> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultTimerSupplier(loader);
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Timer supplier (will use default): {}", info, e);
      supplier = new DefaultTimerSupplier(loader);
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example #10
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Meter} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Meter> meterSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Meter> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultMeterSupplier();
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Meter supplier (will use default): {}",info, e);
      supplier = new DefaultMeterSupplier();
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example #11
Source File: SolrMetricManagerTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
private PluginInfo createPluginInfo(String name, String group, String registry) {
  Map<String,String> attrs = new HashMap<>();
  attrs.put("name", name);
  attrs.put("class", MockMetricReporter.class.getName());
  if (group != null) {
    attrs.put("group", group);
  }
  if (registry != null) {
    attrs.put("registry", registry);
  }
  @SuppressWarnings({"rawtypes"})
  NamedList initArgs = new NamedList();
  initArgs.add("configurable", "true");
  return new PluginInfo("SolrMetricReporter", attrs, initArgs, null);
}
 
Example #12
Source File: LRUStatsCache.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void init(PluginInfo info) {
  super.init(info);
  if (info != null && info.attributes != null) {
    lruCacheInitArgs.putAll(info.attributes);
  }
  lruCacheInitArgs.computeIfAbsent(SolrCache.SIZE_PARAM, s -> String.valueOf(DEFAULT_MAX_SIZE));
  lruCacheInitArgs.computeIfAbsent(SolrCache.MAX_IDLE_TIME_PARAM, t -> String.valueOf(DEFAULT_MAX_IDLE_TIME));
  Map<String, Object> map = new HashMap<>(lruCacheInitArgs);
  map.put(CommonParams.NAME, "globalTermStats");
  currentGlobalTermStats.init(lruCacheInitArgs, null, null);
  currentGlobalTermStats.setState(SolrCache.State.LIVE);
  map = new HashMap<>(lruCacheInitArgs);
  map.put(CommonParams.NAME, "globalColStats");
  currentGlobalColStats.init(lruCacheInitArgs, null, null);
  currentGlobalColStats.setState(SolrCache.State.LIVE);  }
 
Example #13
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static Clock getClock(PluginInfo info, String param) {
  if (info == null) {
    return Clock.defaultClock();
  }
  String clock = null;
  if (info.attributes != null) {
    clock = info.attributes.get(param);
  }
  if (clock == null && info.initArgs != null) {
    clock = (String)info.initArgs.get(param);
  }
  Clock clk = Clock.defaultClock();
  if (clock != null) {
    if (clock.equalsIgnoreCase(CLOCK_USER)) {
      clk = USER_CLOCK;
    } else if (clock.equalsIgnoreCase(CLOCK_CPU)) {
      clk = CPU_CLOCK;
    }
  }
  return clk;
}
 
Example #14
Source File: BlobHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void init(PluginInfo info) {
  super.init(info.initArgs);
  if (info.initArgs != null) {
    @SuppressWarnings({"rawtypes"})
    NamedList invariants = (NamedList) info.initArgs.get(PluginInfo.INVARIANTS);
    if (invariants != null) {
      Object o = invariants.get("maxSize");
      if (o != null) {
        maxSize = Long.parseLong(String.valueOf(o));
        maxSize = maxSize * 1024 * 1024;
      }
    }

  }
}
 
Example #15
Source File: SolrJmxReporterTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testReloadCore() throws Exception {
  Random random = random();

  String scope = PREFIX + SolrMetricTestUtils.getRandomScope(random, true);
  SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
  Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random, true);
  SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
  coreMetricManager.registerMetricProducer(scope, producer);
  Set<ObjectInstance> objects = TEST_MBEAN_SERVER.queryMBeans(null, null);
  assertEquals(metrics.size(), objects.stream().
      filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) &&
      o.getObjectName().getDomain().equals(rootName)).count());

  h.getCoreContainer().reload(h.getCore().getName());
  PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
  metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore(),
      pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
  coreMetricManager.registerMetricProducer(scope, producer);

  objects = TEST_MBEAN_SERVER.queryMBeans(null, null);
  assertEquals(metrics.size(), objects.stream().
      filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) &&
          rootName.equals(o.getObjectName().getDomain())).count());
}
 
Example #16
Source File: AbstractReSearcherComponent.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PluginInfo info) {
  for (PluginInfo child : info.children) {
    if ("shardHandlerFactory".equals(child.type)) {
      this.shfInfo = child;
      break;
    }
  }
  init(info.initArgs);
}
 
Example #17
Source File: SolrJmxReporterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeTest() throws Exception {
  initCore("solrconfig-basic.xml", "schema.xml");

  final SolrCore core = h.getCore();
  domain = core.getName();
  rootName = PREFIX + TestUtil.randomSimpleString(random(), 5, 10);

  coreMetricManager = core.getCoreMetricManager();
  metricManager = core.getCoreContainer().getMetricManager();
  PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
  metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore(),
      pluginInfo, coreMetricManager.getTag());

  Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
  assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
  String reporterName = pluginInfo.name;
  String taggedName = reporterName + "@" + coreMetricManager.getTag();
  assertNotNull("reporter " + taggedName + " not present among " + reporters, reporters.get(taggedName));
  assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof SolrJmxReporter);

  SolrJmxReporter reporter = (SolrJmxReporter) reporters.get(taggedName);
  assertNotNull("MBean server not found on reporter", reporter.getMBeanServer());
  assertEquals("Wrong MBeanServer found on reporter",
               TEST_MBEAN_SERVER,
               reporter.getMBeanServer());
}
 
Example #18
Source File: SolrJmxReporterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private PluginInfo createReporterPluginInfo(String rootName, boolean enabled) {
  Random random = random();
  String className = SolrJmxReporter.class.getName();
  String reporterName = PREFIX + TestUtil.randomSimpleString(random, 5, 10);
    
  
  Map<String, Object> attrs = new HashMap<>();
  attrs.put(FieldType.CLASS_NAME, className);
  attrs.put(CoreAdminParams.NAME, reporterName);
  attrs.put("rootName", rootName);
  attrs.put("enabled", enabled);

  try {
    String agentId = (String) TEST_MBEAN_SERVER.getAttribute
      (new ObjectName("JMImplementation:type=MBeanServerDelegate"),
       "MBeanServerId");
    attrs.put("agentId", agentId);
  } catch (Exception e) {
    throw new RuntimeException("Unable to determine agentId of MBeanServer: " + e.getMessage(), e);
  }
  boolean shouldOverrideDomain = random.nextBoolean();
  if (shouldOverrideDomain) {
    domain = PREFIX + TestUtil.randomSimpleString(random);
    attrs.put("domain", domain);
  }

  return new PluginInfo(TestUtil.randomUnicodeString(random), attrs);
}
 
Example #19
Source File: SolrConfigHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private Map<String, Object> getConfigDetails(String componentType, SolrQueryRequest req) {
  String componentName = componentType == null ? null : req.getParams().get("componentName");
  boolean showParams = req.getParams().getBool("expandParams", false);
  Map<String, Object> map = this.req.getCore().getSolrConfig().toMap(new LinkedHashMap<>());
  if (componentType != null && !SolrRequestHandler.TYPE.equals(componentType)) return map;
  @SuppressWarnings({"rawtypes"})
  Map reqHandlers = (Map) map.get(SolrRequestHandler.TYPE);
  if (reqHandlers == null) map.put(SolrRequestHandler.TYPE, reqHandlers = new LinkedHashMap<>());
  List<PluginInfo> plugins = this.req.getCore().getImplicitHandlers();
  for (PluginInfo plugin : plugins) {
    if (SolrRequestHandler.TYPE.equals(plugin.type)) {
      if (!reqHandlers.containsKey(plugin.name)) {
        reqHandlers.put(plugin.name, plugin);
      }
    }
  }
  if (!showParams) return map;
  for (Object o : reqHandlers.entrySet()) {
    @SuppressWarnings({"rawtypes"})
    Map.Entry e = (Map.Entry) o;
    if (componentName == null || e.getKey().equals(componentName)) {
      Map<String, Object> m = expandUseParams(req, e.getValue());
      e.setValue(m);
    }
  }

  return map;
}
 
Example #20
Source File: SolrMetricReporterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInit() throws Exception {
  Random random = random();

  SolrMetricManager metricManager = new SolrMetricManager();

  final String registryName = TestUtil.randomSimpleString(random);
  final MockMetricReporter reporter = new MockMetricReporter(metricManager, registryName);

  Map<String, Object> attrs = new HashMap<>();
  attrs.put(FieldType.CLASS_NAME, MockMetricReporter.class.getName());
  attrs.put(CoreAdminParams.NAME, TestUtil.randomUnicodeString(random));
  attrs.put("enabled", random.nextBoolean());

  boolean shouldDefineConfigurable = random.nextBoolean();
  String configurable = TestUtil.randomUnicodeString(random);
  if (shouldDefineConfigurable) attrs.put("configurable", configurable);

  boolean shouldDefinePlugin = random.nextBoolean();
  String type = TestUtil.randomUnicodeString(random);
  PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(type, attrs) : null;

  try {
    reporter.init(pluginInfo);
    assertNotNull(pluginInfo);
    assertEquals(configurable, attrs.get("configurable"));
    assertTrue(reporter.didValidate);
    assertNotNull(reporter.configurable);
    assertEquals(configurable, reporter.configurable);
  } catch (IllegalStateException e) {
    assertTrue(pluginInfo == null || attrs.get("configurable") == null);
    assertTrue(reporter.didValidate);
    assertNull(reporter.configurable);
  } finally {
    reporter.close();
  }
}
 
Example #21
Source File: SolrCoreMetricManagerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadReporter() throws Exception {
  Random random = random();

  String className = MockMetricReporter.class.getName();
  String reporterName = TestUtil.randomUnicodeString(random);
  String taggedName = reporterName + "@" + coreMetricManager.getTag();

  Map<String, Object> attrs = new HashMap<>();
  attrs.put(FieldType.CLASS_NAME, className);
  attrs.put(CoreAdminParams.NAME, reporterName);

  boolean shouldDefineConfigurable = random.nextBoolean();
  String configurable = TestUtil.randomUnicodeString(random);
  if (shouldDefineConfigurable) attrs.put("configurable", configurable);

  boolean shouldDefinePlugin = random.nextBoolean();
  PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(TestUtil.randomUnicodeString(random), attrs) : null;

  try {
    metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore(),
        pluginInfo, coreMetricManager.getTag());
    assertNotNull(pluginInfo);
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
    assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
    assertNotNull("reporter " + reporterName + " not present among " + reporters, reporters.get(taggedName));
    assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof MockMetricReporter);
  } catch (IllegalArgumentException e) {
    assertTrue(pluginInfo == null || attrs.get("configurable") == null);
    assertNull(metricManager.getReporters(coreMetricManager.getRegistryName()).get(taggedName));
  }
}
 
Example #22
Source File: UpdateRequestProcessorChain.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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 = null;
    PluginBag.PluginHolder<UpdateRequestProcessorFactory> holder = core.getUpdateProcessors().getRegistry().get(s);
    if (holder instanceof PackagePluginHolder) {
      p = new LazyUpdateRequestProcessorFactory(holder);
    } else {
      p = core.getUpdateProcessors().get(s);
    }
    if (p == null) {
      @SuppressWarnings({"unchecked"})
      Class<UpdateRequestProcessorFactory> factoryClass = implicits.get(s);
      if(factoryClass != null) {
        PluginInfo pluginInfo = new PluginInfo("updateProcessor",
            Utils.makeMap("name", s,
                "class", factoryClass.getName()));
        UpdateRequestProcessorFactory plugin = p = core.getUpdateProcessors().createPlugin(pluginInfo).get();
        if (plugin instanceof SolrCoreAware) ((SolrCoreAware) plugin).inform(core);
        core.getUpdateProcessors().put(s, plugin);
      }
      if (p == null)
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
    }
    result.add(p);
  }
  return result;
}
 
Example #23
Source File: StreamHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static void addExpressiblePlugins(StreamFactory streamFactory, SolrCore core) {
  List<PluginInfo> pluginInfos = core.getSolrConfig().getPluginInfos(Expressible.class.getName());
  for (PluginInfo pluginInfo : pluginInfos) {
    if (pluginInfo.pkgName != null) {
      @SuppressWarnings("resource")
      ExpressibleHolder holder = new ExpressibleHolder(pluginInfo, core, SolrConfig.classVsSolrPluginInfo.get(Expressible.class.getName()));
      streamFactory.withFunctionName(pluginInfo.name,
          () -> holder.getClazz());
    } else {
      Class<? extends Expressible> clazz = core.getMemClassLoader().findClass(pluginInfo.className, Expressible.class);
      streamFactory.withFunctionName(pluginInfo.name, clazz);
    }
  }
}
 
Example #24
Source File: BackupRepositoryFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #25
Source File: HighlightComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void inform(SolrCore core) {
  List<PluginInfo> children = info.getChildren("highlighting");
  if(children.isEmpty()) {
    DefaultSolrHighlighter defHighlighter = new DefaultSolrHighlighter(core);
    defHighlighter.init(PluginInfo.EMPTY_INFO);
    solrConfigHighlighter = defHighlighter;
  } else {
    solrConfigHighlighter = core.createInitInstance(children.get(0),SolrHighlighter.class,null, DefaultSolrHighlighter.class.getName());
  }

}
 
Example #26
Source File: SpatialClusteringComponent.java    From solr-spatial-clustering with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PluginInfo info) {
    this.fieldNameId = getStringArgument(info.initArgs, PARAMETER_FIELD_NAME_ID);
    this.fieldNameLon = getStringArgument(info.initArgs, PARAMETER_FIELD_NAME_LON);
    this.fieldNameLat = getStringArgument(info.initArgs, PARAMETER_FIELD_NAME_LAT);

    this.fields = new HashSet<>();
    this.fields.add(this.fieldNameId);
    this.fields.add(this.fieldNameLon);
    this.fields.add(this.fieldNameLat);

    this.maxSize = getIntArgument(info.initArgs, PARAMETER_MAX_SIZE, MIN_SIZE, DEFAULT_MAX_SIZE);
}
 
Example #27
Source File: DumpRequestHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  super.init(args);
  if(args !=null) {
    @SuppressWarnings({"rawtypes"})
    NamedList nl = (NamedList) args.get(PluginInfo.DEFAULTS);
    if(nl!=null) subpaths = nl.getAll("subpath");
  }
}
 
Example #28
Source File: HdfsUpdateLog.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void init(PluginInfo info) {
  super.init(info);
  
  tlogDfsReplication = (Integer) info.initArgs.get( "tlogDfsReplication");
  if (tlogDfsReplication == null) tlogDfsReplication = 3;

  log.info("Initializing HdfsUpdateLog: tlogDfsReplication={}", tlogDfsReplication);
}
 
Example #29
Source File: SolrIndexConfig.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Internal constructor for setting defaults based on Lucene Version
 */
private SolrIndexConfig(SolrConfig solrConfig) {
  useCompoundFile = false;
  maxBufferedDocs = -1;
  ramBufferSizeMB = 100;
  ramPerThreadHardLimitMB = -1;
  writeLockTimeout = -1;
  lockType = DirectoryFactory.LOCK_TYPE_NATIVE;
  mergePolicyFactoryInfo = null;
  mergeSchedulerInfo = null;
  mergedSegmentWarmerInfo = null;
  // enable coarse-grained metrics by default
  metricsInfo = new PluginInfo("metrics", Collections.emptyMap(), null, null);
}
 
Example #30
Source File: FacetTreeParameters.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Construct the tree parameters from the arguments passed to the
 * component.
 * @param args the arguments passed to the component.
 */
public FacetTreeParameters(NamedList<? extends Object> args) {
	// Find "defaults" list
	@SuppressWarnings({ "unchecked", "rawtypes" })
	NamedList<? extends Object> defaultArgs = (NamedList) args.get(PluginInfo.DEFAULTS);
	
	if (defaultArgs != null) {
		// Assume all of the args are single strings for now
		defaultArgs.forEach(entry -> {
			defaults.put(entry.getKey(), (String)entry.getValue());
		});
	}
}