Java Code Examples for org.apache.solr.core.SolrResourceLoader#getManagedResourceRegistry()

The following examples show how to use org.apache.solr.core.SolrResourceLoader#getManagedResourceRegistry() . 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: 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 2
Source File: RestManager.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the RestManager with the storageIO being optionally created outside of this implementation
 * such as to use ZooKeeper instead of the local FS. 
 */
public void init(SolrResourceLoader loader,
                 NamedList<String> initArgs, 
                 StorageIO storageIO) 
    throws SolrException
{
  log.debug("Initializing RestManager with initArgs: {}", initArgs);

  if (storageIO == null)
    throw new IllegalArgumentException(
        "Must provide a valid StorageIO implementation to the RestManager!");
  
  this.storageIO = storageIO;
  this.loader = loader;
  
  registry = loader.getManagedResourceRegistry();
  
  // the RestManager provides metadata about managed resources via the /managed endpoint
  // and allows you to create new ManagedResources dynamically by PUT'ing to this endpoint
  endpoint = new RestManagerManagedResource(this);
  endpoint.loadManagedDataAndNotify(null); // no observers for my endpoint
  // responds to requests to /config/managed and /schema/managed
  managed.put(SCHEMA_BASE_PATH+MANAGED_ENDPOINT, endpoint);
          
  // init registered managed resources
  if (log.isDebugEnabled()) {
    log.debug("Initializing {} registered ManagedResources", registry.registered.size());
  }
  for (ManagedResourceRegistration reg : registry.registered.values()) {
    // keep track of this for lookups during request processing
    managed.put(reg.resourceId, createManagedResource(reg));
  }
  
  // this is for any new registrations that don't come through the API
  // such as from adding a new fieldType to a managed schema that uses a ManagedResource
  registry.initializedRestManager = this;
}