Java Code Examples for org.apache.solr.core.SolrResourceLoader

The following examples show how to use org.apache.solr.core.SolrResourceLoader. These examples are extracted from open source projects. 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
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 2
@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 3
Source Project: lucene-solr   Source File: ContentStreamTest.java    License: 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 4
Source Project: lucene-solr   Source File: ContentStreamTest.java    License: 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 5
@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 6
Source Project: lucene-solr   Source File: NodeAddedTrigger.java    License: 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 7
Source Project: lucene-solr   Source File: ManagedResourceStorage.java    License: 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 8
Source Project: lucene-solr   Source File: IndexSchemaFactory.java    License: 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 9
Source Project: lucene-solr   Source File: TestManagedResourceStorage.java    License: 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 10
Source Project: lucene-solr   Source File: NodeLostTrigger.java    License: 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 11
Source Project: lucene-solr   Source File: MetricSuppliers.java    License: 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 12
Source Project: lucene-solr   Source File: MetricSuppliers.java    License: 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 13
Source Project: lucene-solr   Source File: LogWatcher.java    License: 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 14
Source Project: lucene-solr   Source File: SolrIndexConfig.java    License: 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 15
Source Project: lucene-solr   Source File: FieldMutatingUpdateProcessor.java    License: 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 16
Source Project: lucene-solr   Source File: TestRestManager.java    License: 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 Project: lucene-solr   Source File: SolrConfigHandler.java    License: 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 Project: lucene-solr   Source File: InactiveShardPlanAction.java    License: 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. ");
  }
}
 
Example 19
Source Project: lucene-solr   Source File: CloudConfigSetService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"rawtypes"})
protected NamedList loadConfigSetFlags(CoreDescriptor cd, SolrResourceLoader loader) {
  try {
    return ConfigSetProperties.readFromResourceLoader(loader, ".");
  } catch (Exception ex) {
    log.debug("No configSet flags", ex);
    return null;
  }
}
 
Example 20
Source Project: lucene-solr   Source File: TriggerActionBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, Map<String, Object> properties) throws TriggerValidationException {
  this.loader = loader;
  this.cloudManager = cloudManager;
  if (properties != null) {
    this.properties.putAll(properties);
  }
  // validate the config
  Map<String, String> results = new HashMap<>();
  TriggerUtils.checkProperties(this.properties, results, requiredProperties, validProperties);
  if (!results.isEmpty()) {
    throw new TriggerValidationException(getName(), results);
  }
}
 
Example 21
Source Project: lucene-solr   Source File: BackupRepositoryFactory.java    License: Apache License 2.0 5 votes vote down vote up
public BackupRepository newInstance(SolrResourceLoader loader) {
  if (defaultBackupRepoPlugin != null) {
    return newInstance(loader, defaultBackupRepoPlugin.name);
  }

  LocalFileSystemRepository repo = new LocalFileSystemRepository();
  repo.init(new NamedList<>());
  return repo;
}
 
Example 22
Source Project: lucene-solr   Source File: ManagedFeatureStore.java    License: Apache License 2.0 5 votes vote down vote up
private static Feature fromFeatureMap(SolrResourceLoader solrResourceLoader,
    Map<String,Object> featureMap) {
  final String className = (String) featureMap.get(CLASS_KEY);

  final String name = (String) featureMap.get(NAME_KEY);

  @SuppressWarnings("unchecked")
  final Map<String,Object> params = (Map<String,Object>) featureMap.get(PARAMS_KEY);

  return Feature.getInstance(solrResourceLoader, className, name, params);
}
 
Example 23
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 24
Source Project: lucene-solr   Source File: ManagedModelStore.java    License: 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 25
Source Project: lucene-solr   Source File: ManagedModelStore.java    License: 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 26
Source Project: lucene-solr   Source File: ScheduledTriggers.java    License: 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 27
Source Project: lucene-solr   Source File: TestModelManager.java    License: 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 28
Source Project: lucene-solr   Source File: HttpTriggerListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configure(SolrResourceLoader loader, SolrCloudManager cloudManager, AutoScalingConfig.TriggerListenerConfig config) throws TriggerValidationException {
  super.configure(loader, cloudManager, config);
  urlTemplate = (String)config.properties.get("url");
  payloadTemplate = (String)config.properties.get("payload");
  contentType = (String)config.properties.get("contentType");
  config.properties.forEach((k, v) -> {
    if (k.startsWith("header.")) {
      headerTemplates.put(k.substring(7), String.valueOf(v));
    }
  });
  timeout = PropertiesUtil.toInteger(String.valueOf(config.properties.get("timeout")), HttpClientUtil.DEFAULT_CONNECT_TIMEOUT);
  followRedirects = PropertiesUtil.toBoolean(String.valueOf(config.properties.get("followRedirects")));
}
 
Example 29
Source Project: lucene-solr   Source File: SchemaManager.java    License: 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 30
Source Project: lucene-solr   Source File: ManagedResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this managed resource, including setting up JSON-based storage using
 * the provided storageIO implementation, such as ZK.
 */
protected ManagedResource(String resourceId, SolrResourceLoader loader, StorageIO storageIO)
    throws SolrException {

  this.resourceId = resourceId;
  this.solrResourceLoader = loader;    
  this.storage = createStorage(storageIO, loader);
}