SOLR-8700 eliminate the java class for implicit plugins

This commit is contained in:
Noble Paul 2016-02-21 20:49:55 +05:30
parent 2b3529c3b8
commit 5a15fed9f5
7 changed files with 143 additions and 168 deletions

View File

@ -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<PluginInfo> getHandlers(SolrCore solrCore){
List<PluginInfo> 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<String, Object> 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);
}
}

View File

@ -115,7 +115,7 @@ public final class RequestHandlers {
*/
void initHandlersFromConfig(SolrConfig config) {
List<PluginInfo> implicits = ImplicitPlugins.getHandlers(core);
List<PluginInfo> implicits = core.getImplicitHandlers();
// use link map so we iterate in the same order
Map<String, PluginInfo> infoMap= new LinkedHashMap<>();
//deduping implicit and explicit requesthandlers

View File

@ -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<PluginInfo> getImplicitHandlers() {
List<PluginInfo> implicits = new ArrayList<>();
Map requestHandlers = (Map) implicitPluginsInfo.get(SolrRequestHandler.TYPE);
for (Object o : requestHandlers.entrySet()) {
Map.Entry<String, Map> entry = (Map.Entry<String, Map>) o;
Map info = Utils.getDeepCopy(entry.getValue(), 4);
info.put(NAME, entry.getKey());
implicits.add(new PluginInfo(SolrRequestHandler.TYPE, info));
}
return implicits;
}
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<String, Object> map = req.getCore().getSolrConfig().toMap();
Map reqHandlers = (Map) map.get(SolrRequestHandler.TYPE);
if (reqHandlers == null) map.put(SolrRequestHandler.TYPE, reqHandlers = new LinkedHashMap<>());
List<PluginInfo> plugins = ImplicitPlugins.getHandlers(req.getCore());
List<PluginInfo> plugins = req.getCore().getImplicitHandlers();
for (PluginInfo plugin : plugins) {
if (SolrRequestHandler.TYPE.equals(plugin.type)) {
if (!reqHandlers.containsKey(plugin.name)) {

View File

@ -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
}
}
}
}