use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestModelManager method test.
@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);
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class SpellCheckComponent method addSpellChecker.
private boolean addSpellChecker(SolrCore core, boolean hasDefault, NamedList spellchecker) {
String className = (String) spellchecker.get("classname");
if (className == null)
className = (String) spellchecker.get("class");
// so that it's mandatory in a future release?
if (className == null)
className = IndexBasedSpellChecker.class.getName();
SolrResourceLoader loader = core.getResourceLoader();
SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class);
if (checker != null) {
String dictionary = checker.init(spellchecker, core);
if (dictionary != null) {
boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME);
if (isDefault && !hasDefault) {
hasDefault = true;
} else if (isDefault && hasDefault) {
throw new RuntimeException("More than one dictionary is missing name.");
}
spellCheckers.put(dictionary, checker);
} else {
if (!hasDefault) {
spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker);
hasDefault = true;
} else {
throw new RuntimeException("More than one dictionary is missing name.");
}
}
// Register event listeners for this SpellChecker
core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false));
boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit"));
boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize"));
if (buildOnCommit || buildOnOptimize) {
LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName());
core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize));
}
} else {
throw new RuntimeException("Can't load spell checker: " + className);
}
return hasDefault;
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class SchemaManager method getFreshManagedSchema.
public static ManagedIndexSchema getFreshManagedSchema(SolrCore core) throws IOException, KeeperException, InterruptedException {
SolrResourceLoader resourceLoader = core.getResourceLoader();
String name = core.getLatestSchema().getResourceName();
if (resourceLoader instanceof ZkSolrResourceLoader) {
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();
}
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class ManagedIndexSchemaFactory method upgradeToManagedSchema.
/**
* Persist the managed schema and rename the non-managed schema
* by appending {@link #UPGRADED_SCHEMA_EXTENSION}.
*
* Failure to rename the non-managed schema will be logged as a warning,
* and no exception will be thrown.
*/
private void upgradeToManagedSchema() {
SolrResourceLoader loader = config.getResourceLoader();
if (loader instanceof ZkSolrResourceLoader) {
zkUgradeToManagedSchema();
} else {
// Configs are not on ZooKeeper
// Only create it - don't update it if it already exists
schema.persistManagedSchema(true);
if (resourceName.equals(managedSchemaResourceName)) {
log.info("On upgrading to managed schema, did not rename non-managed schema '" + resourceName + "' because it's the same as the managed schema's name.");
} else {
final File nonManagedSchemaFile = locateConfigFile(resourceName);
if (null == nonManagedSchemaFile) {
// Don't throw an exception for failure to rename the non-managed schema
log.warn("On upgrading to managed schema, did not rename non-managed schema " + resourceName + " because it's neither an absolute file " + "nor under SolrConfig.getConfigDir() or the current directory." + " PLEASE REMOVE THIS FILE.");
} else {
File upgradedSchemaFile = new File(nonManagedSchemaFile + UPGRADED_SCHEMA_EXTENSION);
if (nonManagedSchemaFile.renameTo(upgradedSchemaFile)) {
// Set the resource name to the managed schema so that the CoreAdminHandler returns a findable filename
schema.setResourceName(managedSchemaResourceName);
log.info("After upgrading to managed schema, renamed the non-managed schema " + nonManagedSchemaFile + " to " + upgradedSchemaFile);
} else {
// Don't throw an exception for failure to rename the non-managed schema
log.warn("Can't rename " + nonManagedSchemaFile.toString() + " to " + upgradedSchemaFile.toString() + " - PLEASE REMOVE THIS FILE.");
}
}
}
}
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class ClusteringComponent method inform.
@SuppressWarnings("unchecked")
@Override
public void inform(SolrCore core) {
if (initParams != null) {
log.info("Initializing Clustering Engines");
// Our target list of engines, split into search-results and document clustering.
SolrResourceLoader loader = core.getResourceLoader();
for (Map.Entry<String, Object> entry : initParams) {
if ("engine".equals(entry.getKey())) {
NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
Boolean optional = engineInitParams.getBooleanArg("optional");
optional = (optional == null ? Boolean.FALSE : optional);
String engineClassName = StringUtils.defaultIfBlank((String) engineInitParams.get("classname"), CarrotClusteringEngine.class.getName());
// Instantiate the clustering engine and split to appropriate map.
final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");
if (!engine.isAvailable()) {
if (optional) {
log.info("Optional clustering engine not available: " + name);
} else {
throw new SolrException(ErrorCode.SERVER_ERROR, "A required clustering engine failed to initialize, check the logs: " + name);
}
}
final ClusteringEngine previousEntry;
if (engine instanceof SearchClusteringEngine) {
previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
} else if (engine instanceof DocumentClusteringEngine) {
previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
} else {
log.warn("Unknown type of a clustering engine for class: " + engineClassName);
continue;
}
if (previousEntry != null) {
log.warn("Duplicate clustering engine component named '" + name + "'.");
}
}
}
// Set up the default engine key for both types of engines.
setupDefaultEngine("search results clustering", searchClusteringEngines);
setupDefaultEngine("document clustering", documentClusteringEngines);
log.info("Finished Initializing Clustering Engines");
}
}
Aggregations