use of org.apache.solr.handler.SolrConfigHandler in project lucene-solr by apache.
the class SolrCore method getConfListener.
public static Runnable getConfListener(SolrCore core, ZkSolrResourceLoader zkSolrResourceLoader) {
final String coreName = core.getName();
final CoreContainer cc = core.getCoreContainer();
final String overlayPath = zkSolrResourceLoader.getConfigSetZkPath() + "/" + ConfigOverlay.RESOURCE_NAME;
final String solrConfigPath = zkSolrResourceLoader.getConfigSetZkPath() + "/" + core.getSolrConfig().getName();
String schemaRes = null;
if (core.getLatestSchema().isMutable() && core.getLatestSchema() instanceof ManagedIndexSchema) {
ManagedIndexSchema mis = (ManagedIndexSchema) core.getLatestSchema();
schemaRes = mis.getResourceName();
}
final String managedSchmaResourcePath = schemaRes == null ? null : zkSolrResourceLoader.getConfigSetZkPath() + "/" + schemaRes;
return () -> {
log.info("config update listener called for core {}", coreName);
SolrZkClient zkClient = cc.getZkController().getZkClient();
int solrConfigversion, overlayVersion, managedSchemaVersion = 0;
SolrConfig cfg = null;
try (SolrCore solrCore = cc.solrCores.getCoreFromAnyList(coreName, true)) {
if (solrCore == null || solrCore.isClosed())
return;
cfg = solrCore.getSolrConfig();
solrConfigversion = solrCore.getSolrConfig().getOverlay().getZnodeVersion();
overlayVersion = solrCore.getSolrConfig().getZnodeVersion();
if (managedSchmaResourcePath != null) {
managedSchemaVersion = ((ManagedIndexSchema) solrCore.getLatestSchema()).getSchemaZkVersion();
}
}
if (cfg != null) {
cfg.refreshRequestParams();
}
if (checkStale(zkClient, overlayPath, solrConfigversion) || checkStale(zkClient, solrConfigPath, overlayVersion) || checkStale(zkClient, managedSchmaResourcePath, managedSchemaVersion)) {
log.info("core reload {}", coreName);
SolrConfigHandler configHandler = ((SolrConfigHandler) core.getRequestHandler("/config"));
if (configHandler.getReloadLock().tryLock()) {
try {
cc.reload(coreName);
} catch (SolrCoreState.CoreIsClosedException e) {
/*no problem this core is already closed*/
} finally {
configHandler.getReloadLock().unlock();
}
} else {
log.info("Another reload is in progress. Not doing anything.");
}
return;
}
//some files in conf directory may have other than managedschema, overlay, params
try (SolrCore solrCore = cc.solrCores.getCoreFromAnyList(coreName, true)) {
if (solrCore == null || solrCore.isClosed())
return;
for (Runnable listener : solrCore.confListeners) {
try {
listener.run();
} catch (Exception e) {
log.error("Error in listener ", e);
}
}
}
};
}
use of org.apache.solr.handler.SolrConfigHandler in project lucene-solr by apache.
the class TestApiFramework method testFramework.
public void testFramework() {
Map<String, Object[]> calls = new HashMap<>();
Map<String, Object> out = new HashMap<>();
CoreContainer mockCC = TestCoreAdminApis.getCoreContainerMock(calls, out);
PluginBag<SolrRequestHandler> containerHandlers = new PluginBag<>(SolrRequestHandler.class, null, false);
containerHandlers.put(COLLECTIONS_HANDLER_PATH, new TestCollectionAPIs.MockCollectionsHandler());
containerHandlers.put(CORES_HANDLER_PATH, new CoreAdminHandler(mockCC));
containerHandlers.put(CONFIGSETS_HANDLER_PATH, new ConfigSetsHandler(mockCC));
out.put("getRequestHandlers", containerHandlers);
PluginBag<SolrRequestHandler> coreHandlers = new PluginBag<>(SolrRequestHandler.class, null, false);
coreHandlers.put("/schema", new SchemaHandler());
coreHandlers.put("/config", new SolrConfigHandler());
coreHandlers.put("/admin/ping", new PingRequestHandler());
Map<String, String> parts = new HashMap<>();
String fullPath = "/collections/hello/shards";
Api api = V2HttpCall.getApiInfo(containerHandlers, fullPath, "POST", fullPath, parts);
assertNotNull(api);
assertConditions(api.getSpec(), Utils.makeMap("/methods[0]", "POST", "/commands/create", NOT_NULL));
assertEquals("hello", parts.get("collection"));
parts = new HashMap<>();
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards", "POST", null, parts);
assertConditions(api.getSpec(), Utils.makeMap("/methods[0]", "POST", "/commands/split", NOT_NULL, "/commands/add-replica", NOT_NULL));
parts = new HashMap<>();
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1", "POST", null, parts);
assertConditions(api.getSpec(), Utils.makeMap("/methods[0]", "POST", "/commands/force-leader", NOT_NULL));
assertEquals("hello", parts.get("collection"));
assertEquals("shard1", parts.get("shard"));
parts = new HashMap<>();
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello", "POST", null, parts);
assertConditions(api.getSpec(), Utils.makeMap("/methods[0]", "POST", "/commands/add-replica-property", NOT_NULL, "/commands/delete-replica-property", NOT_NULL));
assertEquals("hello", parts.get("collection"));
api = V2HttpCall.getApiInfo(containerHandlers, "/collections/hello/shards/shard1/replica1", "DELETE", null, parts);
assertConditions(api.getSpec(), Utils.makeMap("/methods[0]", "DELETE", "/url/params/onlyIfDown/type", "boolean"));
assertEquals("hello", parts.get("collection"));
assertEquals("shard1", parts.get("shard"));
assertEquals("replica1", parts.get("replica"));
SolrQueryResponse rsp = invoke(containerHandlers, null, "/collections/_introspect", GET, mockCC);
assertConditions(rsp.getValues().asMap(2), Utils.makeMap("/spec[0]/methods[0]", "DELETE", "/spec[1]/methods[0]", "POST", "/spec[2]/methods[0]", "GET"));
rsp = invoke(coreHandlers, "/schema/_introspect", "/collections/hello/schema/_introspect", GET, mockCC);
assertConditions(rsp.getValues().asMap(2), Utils.makeMap("/spec[0]/methods[0]", "POST", "/spec[0]/commands", NOT_NULL, "/spec[1]/methods[0]", "GET"));
rsp = invoke(coreHandlers, "/", "/collections/hello/_introspect", GET, mockCC);
assertConditions(rsp.getValues().asMap(2), Utils.makeMap("/availableSubPaths", NOT_NULL, "availableSubPaths /collections/hello/config/jmx", NOT_NULL, "availableSubPaths /collections/hello/schema", NOT_NULL, "availableSubPaths /collections/hello/shards", NOT_NULL, "availableSubPaths /collections/hello/shards/{shard}", NOT_NULL, "availableSubPaths /collections/hello/shards/{shard}/{replica}", NOT_NULL));
}
Aggregations