Search in sources :

Example 1 with SolrConfigHandler

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);
                }
            }
        }
    };
}
Also used : SolrConfigHandler(org.apache.solr.handler.SolrConfigHandler) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) ManagedIndexSchema(org.apache.solr.schema.ManagedIndexSchema) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) SolrException(org.apache.solr.common.SolrException) FileNotFoundException(java.io.FileNotFoundException) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with SolrConfigHandler

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));
}
Also used : SchemaHandler(org.apache.solr.handler.SchemaHandler) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) HashMap(java.util.HashMap) SolrConfigHandler(org.apache.solr.handler.SolrConfigHandler) PingRequestHandler(org.apache.solr.handler.PingRequestHandler) PluginBag(org.apache.solr.core.PluginBag) CoreContainer(org.apache.solr.core.CoreContainer) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) Api(org.apache.solr.api.Api) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler)

Aggregations

SolrConfigHandler (org.apache.solr.handler.SolrConfigHandler)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 HashMap (java.util.HashMap)1 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)1 Api (org.apache.solr.api.Api)1 CompositeApi (org.apache.solr.api.V2HttpCall.CompositeApi)1 SolrException (org.apache.solr.common.SolrException)1 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)1 CoreContainer (org.apache.solr.core.CoreContainer)1 PluginBag (org.apache.solr.core.PluginBag)1 PingRequestHandler (org.apache.solr.handler.PingRequestHandler)1 SchemaHandler (org.apache.solr.handler.SchemaHandler)1 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1 ManagedIndexSchema (org.apache.solr.schema.ManagedIndexSchema)1 KeeperException (org.apache.zookeeper.KeeperException)1