org.apache.solr.core.SolrResourceLoader Java Examples

The following examples show how to use org.apache.solr.core.SolrResourceLoader. 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: SolrIndexConfig.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a MergePolicy using the configured MergePolicyFactory
 * or if no factory is configured uses the configured mergePolicy PluginInfo.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
private MergePolicy buildMergePolicy(SolrResourceLoader resourceLoader, IndexSchema schema) {

  final String mpfClassName;
  final MergePolicyFactoryArgs mpfArgs;
  if (mergePolicyFactoryInfo == null) {
    mpfClassName = DEFAULT_MERGE_POLICY_FACTORY_CLASSNAME;
    mpfArgs = new MergePolicyFactoryArgs();
  } else {
    mpfClassName = mergePolicyFactoryInfo.className;
    mpfArgs = new MergePolicyFactoryArgs(mergePolicyFactoryInfo.initArgs);
  }

  final MergePolicyFactory mpf = resourceLoader.newInstance(
      mpfClassName,
      MergePolicyFactory.class,
      NO_SUB_PACKAGES,
      new Class[] { SolrResourceLoader.class, MergePolicyFactoryArgs.class, IndexSchema.class },
      new Object[] {resourceLoader, mpfArgs, schema });

  return mpf.getMergePolicy();
}
 
Example #2
Source File: ContentStreamTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testFileStream() throws IOException {
  File file = new File(createTempDir().toFile(), "README");
  try (SolrResourceLoader srl = new SolrResourceLoader(); InputStream is = srl.openResource("solrj/README");
       FileOutputStream os = new FileOutputStream(file)) {
    assertNotNull(is);
    IOUtils.copy(is, os);
  }

  ContentStreamBase stream = new ContentStreamBase.FileStream(file);
  try (InputStream s = stream.getStream();
       FileInputStream fis = new FileInputStream(file);
       InputStreamReader isr = new InputStreamReader(
           new FileInputStream(file), StandardCharsets.UTF_8);
       Reader r = stream.getReader()) {
    assertEquals(file.length(), stream.getSize().intValue());
    // Test the code that sets content based on < being the 1st character
    assertEquals("application/xml", stream.getContentType());
    assertTrue(IOUtils.contentEquals(fis, s));
    assertTrue(IOUtils.contentEquals(isr, r));
  }
}
 
Example #3
Source File: TestManagedResourceStorage.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Runs persisted managed resource creation and update tests on Zookeeper storage.
 */
@Test
public void testZkBasedJsonStorage() throws Exception {
  
  // test using ZooKeeper
  assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());
  SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
  // Solr unit tests can only write to their working directory due to
  // a custom Java Security Manager installed in the test environment
  NamedList<String> initArgs = new NamedList<>();
  try {
    ZooKeeperStorageIO zkStorageIO = new ZooKeeperStorageIO(zkServer.getZkClient(), "/test");
    zkStorageIO.configure(loader, initArgs);
    doStorageTests(loader, zkStorageIO);
  } finally {
    loader.close();
  }
}
 
Example #4
Source File: NodeLostTrigger.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  super.configure(loader, cloudManager, properties);
  preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
  preferredOp = preferredOp.toLowerCase(Locale.ROOT);
  // verify
  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
  switch (action) {
    case MOVEREPLICA:
    case DELETENODE:
    case NONE:
      break;
    default:
      throw new TriggerValidationException("Unsupported preferredOperation=" + preferredOp + " specified for node lost trigger");
  }
}
 
Example #5
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 #6
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 #7
Source File: EnglishLemmatisationFilterFactory.java    From jate with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void inform(ResourceLoader loader) throws IOException {
    if (lemmatiserResourceDir != null ) {
        try {
            String path=((SolrResourceLoader) loader).getConfigDir();
            if(!path.endsWith(File.separator))
                    path=path+File.separator;
            lemmatiser = new EngLemmatiser(path+lemmatiserResourceDir,
                    false, false);
        } catch (Exception e) {
            StringBuilder sb = new StringBuilder("Initiating ");
            sb.append(this.getClass().getName()).append(" failed due to:\n");
            sb.append(ExceptionUtils.getFullStackTrace(e));
            throw new IllegalArgumentException(sb.toString());
        }
    }
}
 
Example #8
Source File: LogWatcher.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create and register a LogWatcher.
 *
 * JUL and Log4j watchers are supported out-of-the-box.  You can register your own
 * LogWatcher implementation via the plugins architecture
 *
 * @param config a LogWatcherConfig object, containing the configuration for this LogWatcher.
 * @param loader a SolrResourceLoader, to be used to load plugin LogWatcher implementations.
 *               Can be null if
 *
 * @return a LogWatcher configured for the container's logging framework
 */
@SuppressWarnings({"rawtypes"})
public static LogWatcher newRegisteredLogWatcher(LogWatcherConfig config, SolrResourceLoader loader) {

  if (!config.isEnabled()) {
    log.debug("A LogWatcher is not enabled");
    return null;
  }

  LogWatcher logWatcher = createWatcher(config, loader);

  if (logWatcher != null) {
    if (config.getWatcherSize() > 0) {
      if (log.isDebugEnabled()) {
        log.debug("Registering Log Listener [{}]", logWatcher.getName());
      }
      logWatcher.registerListener(config.asListenerConfig());
    }
  }

  return logWatcher;
}
 
Example #9
Source File: AlfrescoCoreAdminHandlerTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void maxTransactionScheduledParameterAndConfigurationIsNull_shouldGetTheHardCodedDefault()
{
    params.set(CORE, ALFRESCO_CORE_NAME);

    Properties coreProperties = new Properties();

    CoreContainer coreContainer = mock(CoreContainer.class);
    SolrCore core = mock(SolrCore.class);
    SolrResourceLoader resourceLoader = mock(SolrResourceLoader.class);
    when(coreContainer.getCore(ALFRESCO_CORE_NAME)).thenReturn(core);
    when(core.getResourceLoader()).thenReturn(resourceLoader);
    when(resourceLoader.getCoreProperties()).thenReturn(coreProperties);

    admin = new AlfrescoCoreAdminHandler(coreContainer);

    assertEquals(Integer.MAX_VALUE, admin.getMaxTransactionToSchedule(params));
}
 
Example #10
Source File: ModelTracker.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ModelTracker(String solrHome, Properties p, SOLRAPIClient client, String coreName,
            InformationServer informationServer)
{
    super(p, client, coreName, informationServer, Tracker.Type.MODEL);
    String normalSolrHome = SolrResourceLoader.normalizeDir(solrHome);
    alfrescoModelDir = new File(ConfigUtil.locateProperty("solr.model.dir", normalSolrHome+"alfrescoModels"));
    LOGGER.info("Alfresco Model dir {}", alfrescoModelDir);
    if (!alfrescoModelDir.exists())
    {
        alfrescoModelDir.mkdir();
    }

    loadPersistedModels();

    RUN_LOCK_BY_CORE.put(coreName, new Semaphore(1, true));
    WRITE_LOCK_BY_CORE.put(coreName, new Semaphore(1, true));
}
 
Example #11
Source File: NodeAddedTrigger.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  super.configure(loader, cloudManager, properties);
  preferredOp = (String) properties.getOrDefault(PREFERRED_OP, CollectionParams.CollectionAction.MOVEREPLICA.toLower());
  preferredOp = preferredOp.toLowerCase(Locale.ROOT);
  String replicaTypeStr = (String) properties.getOrDefault(REPLICA_TYPE, Replica.Type.NRT.name());
  // verify
  try {
    replicaType = Replica.Type.valueOf(replicaTypeStr);
  } catch (IllegalArgumentException | NullPointerException e) {
    throw new TriggerValidationException("Unsupported replicaType=" + replicaTypeStr + " specified for node added trigger");
  }

  CollectionParams.CollectionAction action = CollectionParams.CollectionAction.get(preferredOp);
  switch (action) {
    case ADDREPLICA:
    case MOVEREPLICA:
    case NONE:
      break;
    default:
      throw new TriggerValidationException("Unsupported preferredOperation=" + preferredOp + " specified for node added trigger");
  }
}
 
Example #12
Source File: ManagedResourceStorage.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, NamedList<String> initArgs) throws SolrException {
  // validate connectivity and the configured znode base
  try {
    if (!zkClient.exists(znodeBase, retryOnConnLoss)) {
      zkClient.makePath(znodeBase, retryOnConnLoss);
    }
  } catch (Exception exc) {
    String errMsg = String.format
        (Locale.ROOT, "Failed to verify znode at %s due to: %s", znodeBase, exc.toString());
    log.error(errMsg, exc);
    throw new SolrException(ErrorCode.SERVER_ERROR, errMsg, exc);
  }
  
  log.info("Configured ZooKeeperStorageIO with znodeBase: {}", znodeBase);
}
 
Example #13
Source File: FieldMutatingUpdateProcessor.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private ConfigurableFieldNameSelectorHelper(final SolrResourceLoader loader,
                                      final SelectorParams params) {
  this.params = params;

  @SuppressWarnings({"rawtypes"})
  final Collection<Class> classes = new ArrayList<>(params.typeClass.size());

  for (String t : params.typeClass) {
    try {
      classes.add(loader.findClass(t, Object.class));
    } catch (Exception e) {
      throw new SolrException(SERVER_ERROR, "Can't resolve typeClass: " + t, e);
    }
  }
  this.classes = classes;
}
 
Example #14
Source File: ContentStreamTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testURLStreamGZIP() throws IOException {
  File file = new File(createTempDir().toFile(), "README.gz");

  try (SolrResourceLoader srl = new SolrResourceLoader(); InputStream is = srl.openResource("solrj/README");
       FileOutputStream os = new FileOutputStream(file);
       GZIPOutputStream zos = new GZIPOutputStream(os)) {
    IOUtils.copy(is, zos);
  }

  ContentStreamBase stream = new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
  try (InputStream s = stream.getStream();
       FileInputStream fis = new FileInputStream(file);
       GZIPInputStream zis = new GZIPInputStream(fis);
       InputStreamReader isr = new InputStreamReader(zis, StandardCharsets.UTF_8);
       FileInputStream fis2 = new FileInputStream(file);
       GZIPInputStream zis2 = new GZIPInputStream(fis2);
       Reader r = stream.getReader()) {
    // See the non-GZIP test case for an explanation of header handling.
    assertEquals("application/xml", stream.getContentType());
    assertTrue(IOUtils.contentEquals(isr, r));
    assertTrue(IOUtils.contentEquals(zis2, s));
    assertEquals(file.length(), stream.getSize().intValue());
  }
}
 
Example #15
Source File: IndexSchemaFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an index schema created from a local resource.  The input is usually from the core descriptor.
 */
public IndexSchema create(String resourceName, SolrConfig config) {
  SolrResourceLoader loader = config.getResourceLoader();
  InputStream schemaInputStream = null;

  if (null == resourceName) {
    resourceName = IndexSchema.DEFAULT_SCHEMA_FILE;
  }

  try {
    schemaInputStream = loader.openResource(resourceName);
  } catch (Exception e) {
    final String msg = "Error loading schema resource " + resourceName;
    log.error(msg, e);
    throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
  }
  InputSource inputSource = new InputSource(schemaInputStream);
  inputSource.setSystemId(SystemIdResolver.createSystemIdFromResourceName(resourceName));
  IndexSchema schema = new IndexSchema(resourceName, inputSource, config.luceneMatchVersion, loader, config.getSubstituteProperties());
  return schema;
}
 
Example #16
Source File: TestRestManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testReloadFromPersistentStorage() throws Exception {
  SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
  File unitTestStorageDir = createTempDir("testRestManager").toFile();
  assertTrue(unitTestStorageDir.getAbsolutePath()+" is not a directory!", 
      unitTestStorageDir.isDirectory());    
  assertTrue(unitTestStorageDir.canRead());
  assertTrue(unitTestStorageDir.canWrite());

  NamedList<String> ioInitArgs = new NamedList<>();
  ioInitArgs.add(ManagedResourceStorage.STORAGE_DIR_INIT_ARG, 
      unitTestStorageDir.getAbsolutePath());
  
  StorageIO storageIO = new ManagedResourceStorage.FileStorageIO();
  storageIO.configure(loader, ioInitArgs);
  
  NamedList<String> initArgs = new NamedList<>();
  RestManager restManager = new RestManager();
  restManager.init(loader, initArgs, storageIO);
  
  // verifies a RestManager can be reloaded from a previous RestManager's data
  RestManager restManager2 = new RestManager();
  restManager2.init(loader, initArgs, storageIO);    
}
 
Example #17
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 #18
Source File: ScheduledTrigger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  super.configure(loader, cloudManager, properties);
  String timeZoneStr = (String) properties.get("timeZone");
  this.timeZone = TimeZoneUtils.parseTimezone(timeZoneStr); // defaults to UTC

  String startTimeStr = (String) properties.get("startTime");
  this.everyStr = (String) properties.get("every");
  this.graceDurationStr = (String) properties.getOrDefault("graceDuration", DEFAULT_GRACE_DURATION);

  preferredOp = (String) properties.get(PREFERRED_OP);
  if (preferredOp != null &&
      CollectionParams.CollectionAction.get(preferredOp) == null) {
    throw new TriggerValidationException(getName(), PREFERRED_OP, "unrecognized value of: '" + preferredOp + "'");
  }

  // attempt parsing to validate date math strings
  // explicitly set NOW because it may be different for simulated time
  Date now = new Date(TimeUnit.NANOSECONDS.toMillis(cloudManager.getTimeSource().getEpochTimeNs()));
  Instant startTime = parseStartTime(now, startTimeStr, timeZoneStr);
  DateMathParser.parseMath(now, startTime + everyStr, timeZone);
  DateMathParser.parseMath(now, startTime + graceDurationStr, timeZone);

  // We set lastRunAt to be the startTime (which could be a date math expression such as 'NOW')
  // Ordinarily, NOW will always be evaluated in this constructor so it may seem that
  // the trigger will always fire the first time.
  // However, the lastRunAt is overwritten with the value from ZK
  // during restoreState() operation (which is performed before run()) so the trigger works correctly
  this.lastRunAt = startTime;
}
 
Example #19
Source File: UninvertDocValuesMergePolicyFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public UninvertDocValuesMergePolicyFactory(SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
  super(resourceLoader, args, schema);
  final Boolean sic = (Boolean)args.remove("skipIntegrityCheck");
  if (sic != null) {
    this.skipIntegrityCheck = sic.booleanValue();
  } else {
    this.skipIntegrityCheck = false;
  }
  if (!args.keys().isEmpty()) {
    throw new IllegalArgumentException("Arguments were "+args+" but "+getClass().getSimpleName()+" takes no arguments.");
  }
}
 
Example #20
Source File: SchemaManager.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private ManagedIndexSchema getFreshManagedSchema(SolrCore core) throws IOException,
    KeeperException, InterruptedException {

  SolrResourceLoader resourceLoader = core.getResourceLoader();
  String name = core.getLatestSchema().getResourceName();
  if (resourceLoader instanceof ZkSolrResourceLoader) {
    final ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)resourceLoader;
    SolrZkClient zkClient = zkLoader.getZkController().getZkClient();
    try {
      if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + name, true)) {
        String backupName = name + ManagedIndexSchemaFactory.UPGRADED_SCHEMA_EXTENSION;
        if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName, true)) {
          log.warn("Unable to retrieve fresh managed schema, neither {} nor {} exist.", name, backupName);
          // use current schema
          return (ManagedIndexSchema) core.getLatestSchema();
        } else {
          name = backupName;
        }
      }
    } catch (Exception e) {
      log.warn("Unable to retrieve fresh managed schema {}", name, e);
      // use current schema
      return (ManagedIndexSchema) core.getLatestSchema();
    }
    InputStream in = resourceLoader.openResource(name);
    if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
      int version = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
      log.info("managed schema loaded . version : {} ", version);
      return new ManagedIndexSchema(core.getSolrConfig(), name, new InputSource(in), true, name, version,
          core.getLatestSchema().getSchemaUpdateLock());
    } else {
      return (ManagedIndexSchema) core.getLatestSchema();
    }
  } else {
    return (ManagedIndexSchema) core.getLatestSchema();
  }
}
 
Example #21
Source File: InvokeOp.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static Map<String, Object> invokeAClass(SolrQueryRequest req, String c) {
  SolrResourceLoader loader = null;
  if (req.getCore() != null) loader = req.getCore().getResourceLoader();
  else if (req.getContext().get(CoreContainer.class.getName()) != null) {
    CoreContainer cc = (CoreContainer) req.getContext().get(CoreContainer.class.getName());
    loader = cc.getResourceLoader();
  }

  CoreAdminHandler.Invocable invokable = loader.newInstance(c, CoreAdminHandler.Invocable.class);
  Map<String, Object> result = invokable.invoke(req);
  log.info("Invocable_invoked {}", result);
  return result;
}
 
Example #22
Source File: FieldMutatingUpdateProcessor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method that can be used to define a FieldNameSelector
 * using the same types of rules as the FieldMutatingUpdateProcessor init 
 * code.  This may be useful for Factories that wish to define default 
 * selectors in similar terms to what the configuration would look like.
 * Uses {@code schema} for checking field existence.
 * @lucene.internal
 */
public static FieldNameSelector createFieldNameSelector
  (final SolrResourceLoader loader,
   final IndexSchema schema,
   final SelectorParams params,
   final FieldNameSelector defSelector) {

  if (params.noSelectorsSpecified()) {
    return defSelector;
  }

  final ConfigurableFieldNameSelectorHelper helper =
    new ConfigurableFieldNameSelectorHelper(loader, params);
  return fieldName -> helper.shouldMutateBasedOnSchema(fieldName, schema);
}
 
Example #23
Source File: TestSystemIdResolver.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testUnsafeResolving() throws Exception {
  System.setProperty("solr.allow.unsafe.resourceloading", "true");
  
  final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
  final ResourceLoader loader = new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
  final SystemIdResolver resolver = new SystemIdResolver(loader);
  
  assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-schema.xml"),
    SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");    
}
 
Example #24
Source File: StandardQueryTokenizerFactory.java    From mecab-ko-lucene-analyzer with Apache License 2.0 5 votes vote down vote up
private void setMeCabDicDir(Map<String,String> args) {
  String path = get(
      args,
      "mecabDicDir",
      StandardIndexTokenizerFactory.DEFAULT_MECAB_DIC_DIR);
  if (path != null) {
    if (path.startsWith("/")) {
      mecabDicDir = path;
    } else {
      mecabDicDir = SolrResourceLoader.locateSolrHome() + path;
    }
  }
}
 
Example #25
Source File: SortingMergePolicyFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public SortingMergePolicyFactory(SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
  super(resourceLoader, args, schema);
  final String sortArg = (String) args.remove(SORT);
  if (sortArg == null) {
    throw new IllegalArgumentException(SortingMergePolicyFactory.class.getSimpleName()+" requires a '"+ SORT + "' argument.");
  }
  this.mergeSort = SortSpecParsing.parseSortSpec(sortArg, schema).getSort();
}
 
Example #26
Source File: TestModelManager.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  final SolrResourceLoader loader = new SolrResourceLoader(
      tmpSolrHome.toPath());

  final RestManager.Registry registry = loader.getManagedResourceRegistry();
  assertNotNull(
      "Expected a non-null RestManager.Registry from the SolrResourceLoader!",
      registry);

  final String resourceId = "/schema/fstore1";
  registry.registerManagedResource(resourceId, ManagedFeatureStore.class,
      new LTRQParserPlugin());

  final String resourceId2 = "/schema/mstore1";
  registry.registerManagedResource(resourceId2, ManagedModelStore.class,
      new LTRQParserPlugin());

  final NamedList<String> initArgs = new NamedList<>();

  final RestManager restManager = new RestManager();
  restManager.init(loader, initArgs,
      new ManagedResourceStorage.InMemoryStorageIO());

  final ManagedResource res = restManager.getManagedResource(resourceId);
  assertTrue(res instanceof ManagedFeatureStore);
  assertEquals(res.getResourceId(), resourceId);

}
 
Example #27
Source File: ScheduledTriggers.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public ScheduledTriggers(SolrResourceLoader loader, SolrCloudManager cloudManager) {
  scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(DEFAULT_TRIGGER_CORE_POOL_SIZE,
      new SolrNamedThreadFactory("ScheduledTrigger"));
  scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
  scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
  actionExecutor = ExecutorUtil.newMDCAwareSingleThreadExecutor(new SolrNamedThreadFactory("AutoscalingActionExecutor"));
  this.cloudManager = cloudManager;
  this.stateManager = cloudManager.getDistribStateManager();
  this.loader = loader;
  queueStats = new Stats();
  listeners = new TriggerListeners();
  // initialize cooldown timer
  cooldownStart.set(cloudManager.getTimeSource().getTimeNs() - cooldownPeriod.get());
}
 
Example #28
Source File: ManagedModelStore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static void initAdapterModel(SolrResourceLoader solrResourceLoader,
    AdapterModel adapterModel, ManagedFeatureStore managedFeatureStore) {
  adapterModel.init(solrResourceLoader);
  if (adapterModel instanceof WrapperModel) {
    initWrapperModel(solrResourceLoader, (WrapperModel)adapterModel, managedFeatureStore);
  }
}
 
Example #29
Source File: ManagedModelStore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static LTRScoringModel fromLTRScoringModelMap(SolrResourceLoader solrResourceLoader,
    Map<String,Object> modelMap, ManagedFeatureStore managedFeatureStore) {

  final FeatureStore featureStore =
      managedFeatureStore.getFeatureStore((String) modelMap.get(STORE_KEY));

  final List<Feature> features = new ArrayList<>();
  final List<Normalizer> norms = new ArrayList<>();

  final List<Object> featureList = (List<Object>) modelMap.get(FEATURES_KEY);
  if (featureList != null) {
    for (final Object feature : featureList) {
      final Map<String,Object> featureMap = (Map<String,Object>) feature;
      features.add(lookupFeatureFromFeatureMap(featureMap, featureStore));
      norms.add(createNormalizerFromFeatureMap(solrResourceLoader, featureMap));
    }
  }

  final LTRScoringModel ltrScoringModel = LTRScoringModel.getInstance(solrResourceLoader,
      (String) modelMap.get(CLASS_KEY), // modelClassName
      (String) modelMap.get(NAME_KEY), // modelName
      features,
      norms,
      featureStore.getName(),
      featureStore.getFeatures(),
      (Map<String,Object>) modelMap.get(PARAMS_KEY));

  if (ltrScoringModel instanceof AdapterModel) {
    initAdapterModel(solrResourceLoader, (AdapterModel)ltrScoringModel, managedFeatureStore);
  }

  return ltrScoringModel;
}
 
Example #30
Source File: InactiveShardPlanAction.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  super.configure(loader, cloudManager, properties);
  String cleanupStr = String.valueOf(properties.getOrDefault(TTL_PROP, String.valueOf(DEFAULT_TTL_SECONDS)));
  try {
    cleanupTTL = Integer.parseInt(cleanupStr);
  } catch (Exception e) {
    throw new TriggerValidationException(getName(), TTL_PROP, "invalid value '" + cleanupStr + "': " + e.toString());
  }
  if (cleanupTTL < 0) {
    throw new TriggerValidationException(getName(), TTL_PROP, "invalid value '" + cleanupStr + "', should be > 0. ");
  }
}