From 5a15fed9f5249cf658ddfbccae55733bb5855190 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Sun, 21 Feb 2016 20:49:55 +0530 Subject: [PATCH] SOLR-8700 eliminate the java class for implicit plugins --- .../org/apache/solr/core/ImplicitPlugins.java | 152 ------------------ .../org/apache/solr/core/RequestHandlers.java | 2 +- .../java/org/apache/solr/core/SolrCore.java | 16 ++ .../apache/solr/core/SolrResourceLoader.java | 2 +- .../apache/solr/handler/SchemaHandler.java | 11 +- .../solr/handler/SolrConfigHandler.java | 26 +-- solr/core/src/resources/ImplicitPlugins.json | 102 ++++++++++++ 7 files changed, 143 insertions(+), 168 deletions(-) delete mode 100644 solr/core/src/java/org/apache/solr/core/ImplicitPlugins.java create mode 100644 solr/core/src/resources/ImplicitPlugins.json diff --git a/solr/core/src/java/org/apache/solr/core/ImplicitPlugins.java b/solr/core/src/java/org/apache/solr/core/ImplicitPlugins.java deleted file mode 100644 index f6a74dae94a..00000000000 --- a/solr/core/src/java/org/apache/solr/core/ImplicitPlugins.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.core; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.solr.common.util.NamedList; -import org.apache.solr.handler.PingRequestHandler; -import org.apache.solr.handler.RealTimeGetHandler; -import org.apache.solr.handler.ReplicationHandler; -import org.apache.solr.handler.SQLHandler; -import org.apache.solr.handler.SchemaHandler; -import org.apache.solr.handler.SolrConfigHandler; -import org.apache.solr.handler.StreamHandler; -import org.apache.solr.handler.UpdateRequestHandler; -import org.apache.solr.handler.admin.LoggingHandler; -import org.apache.solr.handler.admin.LukeRequestHandler; -import org.apache.solr.handler.admin.PluginInfoHandler; -import org.apache.solr.handler.admin.PropertiesRequestHandler; -import org.apache.solr.handler.admin.SegmentsInfoRequestHandler; -import org.apache.solr.handler.admin.ShowFileRequestHandler; -import org.apache.solr.handler.admin.SolrInfoMBeanHandler; -import org.apache.solr.handler.admin.SystemInfoHandler; -import org.apache.solr.handler.admin.ThreadDumpHandler; -import org.apache.solr.handler.component.SearchHandler; -import org.apache.solr.request.SolrRequestHandler; - -import static java.util.Collections.singletonMap; -import static org.apache.solr.common.params.CommonParams.JSON; -import static org.apache.solr.common.params.CommonParams.NAME; -import static org.apache.solr.common.params.CommonParams.WT; -import static org.apache.solr.common.util.Utils.makeMap; -import static org.apache.solr.core.PluginInfo.APPENDS; -import static org.apache.solr.core.PluginInfo.DEFAULTS; -import static org.apache.solr.core.PluginInfo.INVARIANTS; - -public class ImplicitPlugins { - - public static List getHandlers(SolrCore solrCore){ - List implicits = new ArrayList<>(); - - //update handle implicits - implicits.add(createPluginInfoWithDefaults("/update", UpdateRequestHandler.class, null)); - implicits.add(createPluginInfoWithDefaults(UpdateRequestHandler.JSON_PATH, UpdateRequestHandler.class, singletonMap("update.contentType", "application/json"))); - implicits.add(createPluginInfoWithDefaults(UpdateRequestHandler.CSV_PATH, UpdateRequestHandler.class, singletonMap("update.contentType", "application/csv"))); - implicits.add(createPluginInfoWithDefaults(UpdateRequestHandler.DOC_PATH, UpdateRequestHandler.class, makeMap("update.contentType", "application/json", "json.command", "false"))); - - //solrconfighandler - PluginInfo config = createPluginInfoWithDefaults("/config", SolrConfigHandler.class, null); - if (solrCore.getConfigSetProperties() != null) { - config.initArgs.addAll(solrCore.getConfigSetProperties()); - } - implicits.add(config); - //schemahandler - PluginInfo schema = createPluginInfoWithDefaults("/schema", SchemaHandler.class, null); - if (solrCore.getConfigSetProperties() != null) { - schema.initArgs.addAll(solrCore.getConfigSetProperties()); - } - implicits.add(schema); - //register replicationhandler always for SolrCloud - implicits.add(createPluginInfoWithDefaults("/replication", ReplicationHandler.class,null)); - - implicits.add(createPluginInfoWithDefaults("/get", RealTimeGetHandler.class, - makeMap( - "omitHeader", "true", - WT, JSON, - "indent", "true"))); - - PluginInfo exportInitArgs = createPluginInfo("/export", SearchHandler.class, - null, // defaults - null, // appends - // we need invariants here - makeMap( - "rq", "{!xport}", - "wt", "xsort", - "distrib", "false" - )); - exportInitArgs.initArgs.add("components", Collections.singletonList("query")); - implicits.add(exportInitArgs); - - implicits.add(createPluginInfo("/stream", StreamHandler.class, - null, // defaults - null, // appends - // we need invariants here - makeMap( - "wt", "json", - "distrib", "false" - ))); - - implicits.add(createPluginInfo("/sql", SQLHandler.class, - null, // defaults - null, // appends - // we need invariants here - makeMap( - "wt", "json", - "distrib", "false" - ))); - - //register adminHandlers - implicits.add(createPluginInfoWithDefaults("/admin/luke", LukeRequestHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/system", SystemInfoHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/mbeans", SolrInfoMBeanHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/plugins", PluginInfoHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/threads", ThreadDumpHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/properties", PropertiesRequestHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/logging", LoggingHandler.class, null)); - implicits.add(createPluginInfoWithDefaults("/admin/file", ShowFileRequestHandler.class, null)); - implicits.add(createPluginInfo("/admin/ping", PingRequestHandler.class, - null, // defaults - null, // appends - // invariants - makeMap("echoParams", "all", "q", "{!lucene}*:*"))); - implicits.add(createPluginInfoWithDefaults("/admin/segments", SegmentsInfoRequestHandler.class, null)); - return implicits; - } - - public static PluginInfo createPluginInfoWithDefaults(String name, Class clz, Map defaults) { - return createPluginInfo(name, clz, defaults, null, null); - } - - public static PluginInfo createPluginInfo(String name, Class clz, Map defaults, Map appends, Map invariants) { - if (defaults == null) defaults = Collections.emptyMap(); - Map m = makeMap(NAME, name, "class", clz.getName()); - Map args = new HashMap<>(1); - args.put(DEFAULTS, new NamedList<>(defaults)); - if (appends != null) { - args.put(APPENDS, new NamedList<>(appends)); - } - if (invariants != null) { - args.put(INVARIANTS, new NamedList<>(invariants)); - } - return new PluginInfo(SolrRequestHandler.TYPE, m, new NamedList<>(args), null); - } -} diff --git a/solr/core/src/java/org/apache/solr/core/RequestHandlers.java b/solr/core/src/java/org/apache/solr/core/RequestHandlers.java index d2fbdf98b78..0f5022aa42f 100644 --- a/solr/core/src/java/org/apache/solr/core/RequestHandlers.java +++ b/solr/core/src/java/org/apache/solr/core/RequestHandlers.java @@ -115,7 +115,7 @@ public final class RequestHandlers { */ void initHandlersFromConfig(SolrConfig config) { - List implicits = ImplicitPlugins.getHandlers(core); + List implicits = core.getImplicitHandlers(); // use link map so we iterate in the same order Map infoMap= new LinkedHashMap<>(); //deduping implicit and explicit requesthandlers diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 70954d5c851..5d7ebdce879 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -66,6 +66,7 @@ import org.apache.solr.common.util.IOUtils; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.ObjectReleaseTracker; import org.apache.solr.common.util.SimpleOrderedMap; +import org.apache.solr.common.util.Utils; import org.apache.solr.core.DirectoryFactory.DirContext; import org.apache.solr.handler.IndexFetcher; import org.apache.solr.handler.ReplicationHandler; @@ -117,6 +118,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkNotNull; +import static org.apache.solr.common.params.CommonParams.NAME; import static org.apache.solr.common.params.CommonParams.PATH; /** @@ -2668,6 +2670,20 @@ public final class SolrCore implements SolrInfoMBean, Closeable { cleanupThread.start(); } } + + private static final Map implicitPluginsInfo = (Map) Utils.fromJSONResource("ImplicitPlugins.json"); + + public List getImplicitHandlers() { + List implicits = new ArrayList<>(); + Map requestHandlers = (Map) implicitPluginsInfo.get(SolrRequestHandler.TYPE); + for (Object o : requestHandlers.entrySet()) { + Map.Entry entry = (Map.Entry) o; + Map info = Utils.getDeepCopy(entry.getValue(), 4); + info.put(NAME, entry.getKey()); + implicits.add(new PluginInfo(SolrRequestHandler.TYPE, info)); + } + return implicits; + } } diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java index 5db04ca7356..ae6739ee383 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -87,7 +87,7 @@ public class SolrResourceLoader implements ResourceLoader,Closeable static final String[] packages = { "", "analysis.", "schema.", "handler.", "search.", "update.", "core.", "response.", "request.", "update.processor.", "util.", "spelling.", "handler.component.", "handler.dataimport.", - "spelling.suggest.", "spelling.suggest.fst.", "rest.schema.analysis.", "security." + "spelling.suggest.", "spelling.suggest.fst.", "rest.schema.analysis.", "security.","handler.admin." }; protected URLClassLoader classLoader; diff --git a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java b/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java index 67d6610f5f8..046de46787e 100644 --- a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java @@ -29,6 +29,7 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.util.ContentStream; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; +import org.apache.solr.core.SolrCore; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.response.SolrQueryResponse; @@ -36,21 +37,20 @@ import org.apache.solr.schema.IndexSchema; import org.apache.solr.schema.ManagedIndexSchema; import org.apache.solr.schema.SchemaManager; import org.apache.solr.schema.ZkIndexSchemaReader; +import org.apache.solr.util.plugin.SolrCoreAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.apache.solr.common.params.CommonParams.JSON; import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG; -public class SchemaHandler extends RequestHandlerBase { +public class SchemaHandler extends RequestHandlerBase implements SolrCoreAware { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private boolean isImmutableConfigSet = false; @Override public void init(NamedList args) { super.init(args); - Object immutable = args.get(IMMUTABLE_CONFIGSET_ARG); - isImmutableConfigSet = immutable != null ? Boolean.parseBoolean(immutable.toString()) : false; } @Override @@ -180,4 +180,9 @@ public class SchemaHandler extends RequestHandlerBase { public String getDescription() { return "CRUD operations over the Solr schema"; } + + @Override + public void inform(SolrCore core) { + isImmutableConfigSet = SolrConfigHandler.getImmutable(core); + } } diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java index e862e054bb0..a566c0ed4f7 100644 --- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java @@ -48,7 +48,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -59,7 +58,6 @@ import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.Utils; import org.apache.solr.core.ConfigOverlay; -import org.apache.solr.core.ImplicitPlugins; import org.apache.solr.core.PluginInfo; import org.apache.solr.core.RequestParams; import org.apache.solr.core.SolrConfig; @@ -72,6 +70,7 @@ import org.apache.solr.schema.SchemaManager; import org.apache.solr.util.CommandOperation; import org.apache.solr.util.DefaultSolrThreadFactory; import org.apache.solr.util.RTimer; +import org.apache.solr.util.plugin.SolrCoreAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,7 +86,7 @@ import static org.apache.solr.core.SolrConfig.PluginOpts.REQUIRE_NAME; import static org.apache.solr.core.SolrConfig.PluginOpts.REQUIRE_NAME_IN_OVERLAY; import static org.apache.solr.schema.FieldType.CLASS_NAME; -public class SolrConfigHandler extends RequestHandlerBase { +public class SolrConfigHandler extends RequestHandlerBase implements SolrCoreAware { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public static final String CONFIGSET_EDITING_DISABLED_ARG = "disable.configEdit"; public static final boolean configEditing_disabled = Boolean.getBoolean(CONFIGSET_EDITING_DISABLED_ARG); @@ -105,13 +104,6 @@ public class SolrConfigHandler extends RequestHandlerBase { namedPlugins = Collections.unmodifiableMap(map); } - @Override - public void init(NamedList args) { - super.init(args); - Object immutable = args.get(IMMUTABLE_CONFIGSET_ARG); - isImmutableConfigSet = immutable != null ? Boolean.parseBoolean(immutable.toString()) : false; - } - @Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { @@ -133,6 +125,18 @@ public class SolrConfigHandler extends RequestHandlerBase { } } + @Override + public void inform(SolrCore core) { + isImmutableConfigSet = getImmutable(core); + } + + public static boolean getImmutable(SolrCore core) { + NamedList configSetProperties = core.getConfigSetProperties(); + if(configSetProperties == null) return false; + Object immutable = configSetProperties.get(IMMUTABLE_CONFIGSET_ARG); + return immutable != null ? Boolean.parseBoolean(immutable.toString()) : false; + } + private class Command { private final SolrQueryRequest req; @@ -232,7 +236,7 @@ public class SolrConfigHandler extends RequestHandlerBase { Map map = req.getCore().getSolrConfig().toMap(); Map reqHandlers = (Map) map.get(SolrRequestHandler.TYPE); if (reqHandlers == null) map.put(SolrRequestHandler.TYPE, reqHandlers = new LinkedHashMap<>()); - List plugins = ImplicitPlugins.getHandlers(req.getCore()); + List plugins = req.getCore().getImplicitHandlers(); for (PluginInfo plugin : plugins) { if (SolrRequestHandler.TYPE.equals(plugin.type)) { if (!reqHandlers.containsKey(plugin.name)) { diff --git a/solr/core/src/resources/ImplicitPlugins.json b/solr/core/src/resources/ImplicitPlugins.json new file mode 100644 index 00000000000..8c0549a2573 --- /dev/null +++ b/solr/core/src/resources/ImplicitPlugins.json @@ -0,0 +1,102 @@ +{ + "requestHandler": { + "/update": { + "class": "solr.UpdateRequestHandler" + }, + "/update/json": { + "class": "solr.UpdateRequestHandler", + "invariants": { + "update.contentType": "application/json" + } + }, + "/update/csv": { + "class": "solr.UpdateRequestHandler", + "invariants": { + "update.contentType": "application/csv" + } + }, + "/update/json/docs": { + "class": "solr.UpdateRequestHandler", + "invariants": { + "update.contentType": "application/json", + "json.command": "false" + } + }, + "/config": { + "class": "solr.SolrConfigHandler" + }, + "/schema": { + "class": "solr.SchemaHandler" + }, + "/replication": { + "class": "solr.ReplicationHandler" + }, + "/get": { + "class": "solr.RealTimeGetHandler", + "defaults": { + "omitHeader": true, + "wt": "json", + "indent": true + } + }, + "/admin/ping": { + "class": "solr.PingRequestHandler", + "invariants": { + "echoParams": "all", + "q": "{!lucene}*:*" + } + }, + "/admin/segments": { + "class": "solr.SegmentsInfoRequestHandler" + }, + "/admin/luke": { + "class": "solr.LukeRequestHandler" + }, + "/admin/system": { + "class": "solr.SystemInfoHandler" + }, + "/admin/mbeans": { + "class": "solr.SolrInfoMBeanHandler" + }, + "/admin/plugins": { + "class": "solr.PluginInfoHandler" + }, + "/admin/threads": { + "class": "solr.ThreadDumpHandler" + }, + "/admin/properties": { + "class": "solr.PropertiesRequestHandler" + }, + "/admin/logging": { + "class": "solr.LoggingHandler" + }, + "/admin/file": { + "class": "solr.ShowFileRequestHandler" + }, + "/export": { + "class": "solr.SearchHandler", + "components": [ + "query" + ], + "invariants": { + "rq": "{!xport}", + "wt": "xsort", + "distrib": false + } + }, + "/stream": { + "class": "solr.StreamHandler", + "invariants": { + "wt": "json", + "distrib": false + } + }, + "/sql": { + "class": "solr.SQLHandler", + "invariants": { + "wt": "json", + "distrib": false + } + } + } +} \ No newline at end of file