You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/10/23 00:05:53 UTC
[32/52] [abbrv] [partial] lucene-solr:jira/gradle: Add gradle support
for Solr
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/core/Config.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/Config.java b/solr/core/src/java/org/apache/solr/core/Config.java
deleted file mode 100644
index 11a381e..0000000
--- a/solr/core/src/java/org/apache/solr/core/Config.java
+++ /dev/null
@@ -1,493 +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 javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.invoke.MethodHandles;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.lucene.util.Version;
-import org.apache.solr.cloud.ZkSolrResourceLoader;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.XMLErrorLogger;
-import org.apache.solr.util.DOMUtil;
-import org.apache.solr.util.SystemIdResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- *
- */
-public class Config {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private static final XMLErrorLogger xmllog = new XMLErrorLogger(log);
-
- static final XPathFactory xpathFactory = XPathFactory.newInstance();
-
- private final Document doc;
- private final Document origDoc; // with unsubstituted properties
- private final String prefix;
- private final String name;
- private final SolrResourceLoader loader;
- private int zkVersion = -1;
-
- /**
- * Builds a config from a resource name with no xpath prefix.
- */
- public Config(SolrResourceLoader loader, String name) throws ParserConfigurationException, IOException, SAXException
- {
- this( loader, name, null, null );
- }
-
- public Config(SolrResourceLoader loader, String name, InputSource is, String prefix) throws ParserConfigurationException, IOException, SAXException
- {
- this(loader, name, is, prefix, true);
- }
- /**
- * Builds a config:
- * <p>
- * Note that the 'name' parameter is used to obtain a valid input stream if no valid one is provided through 'is'.
- * If no valid stream is provided, a valid SolrResourceLoader instance should be provided through 'loader' so
- * the resource can be opened (@see SolrResourceLoader#openResource); if no SolrResourceLoader instance is provided, a default one
- * will be created.
- * </p>
- * <p>
- * Consider passing a non-null 'name' parameter in all use-cases since it is used for logging & exception reporting.
- * </p>
- * @param loader the resource loader used to obtain an input stream if 'is' is null
- * @param name the resource name used if the input stream 'is' is null
- * @param is the resource as a SAX InputSource
- * @param prefix an optional prefix that will be prepended to all non-absolute xpath expressions
- */
- public Config(SolrResourceLoader loader, String name, InputSource is, String prefix, boolean substituteProps) throws ParserConfigurationException, IOException, SAXException
- {
- if( loader == null ) {
- loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
- }
- this.loader = loader;
- this.name = name;
- this.prefix = (prefix != null && !prefix.endsWith("/"))? prefix + '/' : prefix;
- try {
- javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-
- if (is == null) {
- InputStream in = loader.openConfig(name);
- if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {
- zkVersion = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();
- log.debug("loaded config {} with version {} ",name,zkVersion);
- }
- is = new InputSource(in);
- is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
- }
-
- // only enable xinclude, if a SystemId is available
- if (is.getSystemId() != null) {
- try {
- dbf.setXIncludeAware(true);
- dbf.setNamespaceAware(true);
- } catch(UnsupportedOperationException e) {
- log.warn(name + " XML parser doesn't support XInclude option");
- }
- }
-
- final DocumentBuilder db = dbf.newDocumentBuilder();
- db.setEntityResolver(new SystemIdResolver(loader));
- db.setErrorHandler(xmllog);
- try {
- doc = db.parse(is);
- origDoc = copyDoc(doc);
- } finally {
- // some XML parsers are broken and don't close the byte stream (but they should according to spec)
- IOUtils.closeQuietly(is.getByteStream());
- }
- if (substituteProps) {
- DOMUtil.substituteProperties(doc, getSubstituteProperties());
- }
- } catch (ParserConfigurationException | SAXException | TransformerException e) {
- SolrException.log(log, "Exception during parsing file: " + name, e);
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
- }
-
- /*
- * Assert that assertCondition is true.
- * If not, prints reason as log warning.
- * If failCondition is true, then throw exception instead of warning
- */
- public static void assertWarnOrFail(String reason, boolean assertCondition, boolean failCondition) {
- if (assertCondition) {
- return;
- } else if (failCondition) {
- throw new SolrException(SolrException.ErrorCode.FORBIDDEN, reason);
- } else {
- log.warn(reason);
- }
- }
-
- protected Properties getSubstituteProperties() {
- return loader.getCoreProperties();
- }
-
- public Config(SolrResourceLoader loader, String name, Document doc) {
- this.prefix = null;
- this.doc = doc;
- try {
- this.origDoc = copyDoc(doc);
- } catch (TransformerException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
- }
- this.name = name;
- this.loader = loader;
- }
-
-
- private static Document copyDoc(Document doc) throws TransformerException {
- TransformerFactory tfactory = TransformerFactory.newInstance();
- Transformer tx = tfactory.newTransformer();
- DOMSource source = new DOMSource(doc);
- DOMResult result = new DOMResult();
- tx.transform(source, result);
- return (Document) result.getNode();
- }
-
- /**
- * @since solr 1.3
- */
- public SolrResourceLoader getResourceLoader()
- {
- return loader;
- }
-
- /**
- * @since solr 1.3
- */
- public String getResourceName() {
- return name;
- }
-
- public String getName() {
- return name;
- }
-
- public Document getDocument() {
- return doc;
- }
-
- public XPath getXPath() {
- return xpathFactory.newXPath();
- }
-
- private String normalize(String path) {
- return (prefix==null || path.startsWith("/")) ? path : prefix+path;
- }
-
- public void substituteProperties() {
- DOMUtil.substituteProperties(doc, getSubstituteProperties());
- }
-
-
- public Object evaluate(String path, QName type) {
- XPath xpath = xpathFactory.newXPath();
- try {
- String xstr=normalize(path);
-
- // TODO: instead of prepending /prefix/, we could do the search rooted at /prefix...
- Object o = xpath.evaluate(xstr, doc, type);
- return o;
-
- } catch (XPathExpressionException e) {
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + path +" for " + name,e);
- }
- }
-
- public Node getNode(String path, boolean errifMissing) {
- return getNode(path, doc, errifMissing);
- }
-
- public Node getUnsubstitutedNode(String path, boolean errIfMissing) {
- return getNode(path, origDoc, errIfMissing);
- }
-
- public Node getNode(String path, Document doc, boolean errIfMissing) {
- XPath xpath = xpathFactory.newXPath();
- String xstr = normalize(path);
-
- try {
- NodeList nodes = (NodeList)xpath.evaluate(xstr, doc,
- XPathConstants.NODESET);
- if (nodes==null || 0 == nodes.getLength() ) {
- if (errIfMissing) {
- throw new RuntimeException(name + " missing "+path);
- } else {
- log.debug(name + " missing optional " + path);
- return null;
- }
- }
- if ( 1 < nodes.getLength() ) {
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
- name + " contains more than one value for config path: " + path);
- }
- Node nd = nodes.item(0);
- log.trace(name + ":" + path + "=" + nd);
- return nd;
-
- } catch (XPathExpressionException e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);
- } catch (SolrException e) {
- throw(e);
- } catch (Exception e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);
- }
- }
-
- public NodeList getNodeList(String path, boolean errIfMissing) {
- XPath xpath = xpathFactory.newXPath();
- String xstr = normalize(path);
-
- try {
- NodeList nodeList = (NodeList)xpath.evaluate(xstr, doc, XPathConstants.NODESET);
-
- if (null == nodeList) {
- if (errIfMissing) {
- throw new RuntimeException(name + " missing "+path);
- } else {
- log.debug(name + " missing optional " + path);
- return null;
- }
- }
-
- log.trace(name + ":" + path + "=" + nodeList);
- return nodeList;
-
- } catch (XPathExpressionException e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr + " for " + name,e);
- } catch (SolrException e) {
- throw(e);
- } catch (Exception e) {
- SolrException.log(log,"Error in xpath",e);
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,"Error in xpath:" + xstr+ " for " + name,e);
- }
- }
-
- /**
- * Returns the set of attributes on the given element that are not among the given knownAttributes,
- * or null if all attributes are known.
- */
- public Set<String> getUnknownAttributes(Element element, String... knownAttributes) {
- Set<String> knownAttributeSet = new HashSet<>(Arrays.asList(knownAttributes));
- Set<String> unknownAttributeSet = null;
- NamedNodeMap attributes = element.getAttributes();
- for (int i = 0 ; i < attributes.getLength() ; ++i) {
- final String attributeName = attributes.item(i).getNodeName();
- if ( ! knownAttributeSet.contains(attributeName)) {
- if (null == unknownAttributeSet) {
- unknownAttributeSet = new HashSet<>();
- }
- unknownAttributeSet.add(attributeName);
- }
- }
- return unknownAttributeSet;
- }
-
- /**
- * Logs an error and throws an exception if any of the element(s) at the given elementXpath
- * contains an attribute name that is not among knownAttributes.
- */
- public void complainAboutUnknownAttributes(String elementXpath, String... knownAttributes) {
- SortedMap<String,SortedSet<String>> problems = new TreeMap<>();
- NodeList nodeList = getNodeList(elementXpath, false);
- for (int i = 0 ; i < nodeList.getLength() ; ++i) {
- Element element = (Element)nodeList.item(i);
- Set<String> unknownAttributes = getUnknownAttributes(element, knownAttributes);
- if (null != unknownAttributes) {
- String elementName = element.getNodeName();
- SortedSet<String> allUnknownAttributes = problems.get(elementName);
- if (null == allUnknownAttributes) {
- allUnknownAttributes = new TreeSet<>();
- problems.put(elementName, allUnknownAttributes);
- }
- allUnknownAttributes.addAll(unknownAttributes);
- }
- }
- if (problems.size() > 0) {
- StringBuilder message = new StringBuilder();
- for (Map.Entry<String,SortedSet<String>> entry : problems.entrySet()) {
- if (message.length() > 0) {
- message.append(", ");
- }
- message.append('<');
- message.append(entry.getKey());
- for (String attributeName : entry.getValue()) {
- message.append(' ');
- message.append(attributeName);
- message.append("=\"...\"");
- }
- message.append('>');
- }
- message.insert(0, "Unknown attribute(s) on element(s): ");
- String msg = message.toString();
- SolrException.log(log, msg);
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
- }
- }
-
- public String getVal(String path, boolean errIfMissing) {
- Node nd = getNode(path,errIfMissing);
- if (nd==null) return null;
-
- String txt = DOMUtil.getText(nd);
-
- log.debug(name + ' '+path+'='+txt);
- return txt;
-
- /******
- short typ = nd.getNodeType();
- if (typ==Node.ATTRIBUTE_NODE || typ==Node.TEXT_NODE) {
- return nd.getNodeValue();
- }
- return nd.getTextContent();
- ******/
- }
-
-
- public String get(String path) {
- return getVal(path,true);
- }
-
- public String get(String path, String def) {
- String val = getVal(path, false);
- if (val == null || val.length() == 0) {
- return def;
- }
- return val;
- }
-
- public int getInt(String path) {
- return Integer.parseInt(getVal(path, true));
- }
-
- public int getInt(String path, int def) {
- String val = getVal(path, false);
- return val!=null ? Integer.parseInt(val) : def;
- }
-
- public boolean getBool(String path) {
- return Boolean.parseBoolean(getVal(path, true));
- }
-
- public boolean getBool(String path, boolean def) {
- String val = getVal(path, false);
- return val!=null ? Boolean.parseBoolean(val) : def;
- }
-
- public float getFloat(String path) {
- return Float.parseFloat(getVal(path, true));
- }
-
- public float getFloat(String path, float def) {
- String val = getVal(path, false);
- return val!=null ? Float.parseFloat(val) : def;
- }
-
-
- public double getDouble(String path){
- return Double.parseDouble(getVal(path, true));
- }
-
- public double getDouble(String path, double def) {
- String val = getVal(path, false);
- return val!=null ? Double.parseDouble(val) : def;
- }
-
- public Version getLuceneVersion(String path) {
- return parseLuceneVersionString(getVal(path, true));
- }
-
- public Version getLuceneVersion(String path, Version def) {
- String val = getVal(path, false);
- return val!=null ? parseLuceneVersionString(val) : def;
- }
-
- private static final AtomicBoolean versionWarningAlreadyLogged = new AtomicBoolean(false);
-
- public static final Version parseLuceneVersionString(final String matchVersion) {
- final Version version;
- try {
- version = Version.parseLeniently(matchVersion);
- } catch (ParseException pe) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Invalid luceneMatchVersion. Should be of the form 'V.V.V' (e.g. 4.8.0)", pe);
- }
-
- if (version == Version.LATEST && !versionWarningAlreadyLogged.getAndSet(true)) {
- log.warn(
- "You should not use LATEST as luceneMatchVersion property: "+
- "if you use this setting, and then Solr upgrades to a newer release of Lucene, "+
- "sizable changes may happen. If precise back compatibility is important "+
- "then you should instead explicitly specify an actual Lucene version."
- );
- }
-
- return version;
- }
-
- /**If this config is loaded from zk the version is relevant other wise -1 is returned
- */
- public int getZnodeVersion(){
- return zkVersion;
- }
-
- public Config getOriginalConfig() {
- return new Config(loader, null, origDoc);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java b/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
deleted file mode 100644
index 3472999..0000000
--- a/solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
+++ /dev/null
@@ -1,269 +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.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.solr.common.MapSerializable;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.util.StrUtils;
-import org.apache.solr.common.util.Utils;
-import org.noggit.CharArr;
-import org.noggit.JSONWriter;
-
-/**
- * This class encapsulates the config overlay json file. It is immutable
- * and any edit operations performed on tbhis gives a new copy of the object
- * with the changed value
- */
-public class ConfigOverlay implements MapSerializable {
- private final int znodeVersion;
- private final Map<String, Object> data;
- private Map<String, Object> props;
- private Map<String, Object> userProps;
-
- public ConfigOverlay(Map<String, Object> jsonObj, int znodeVersion) {
- if (jsonObj == null) jsonObj = Collections.EMPTY_MAP;
- this.znodeVersion = znodeVersion;
- data = Collections.unmodifiableMap(jsonObj);
- props = (Map<String, Object>) data.get("props");
- if (props == null) props = Collections.EMPTY_MAP;
- userProps = (Map<String, Object>) data.get("userProps");
- if (userProps == null) userProps = Collections.EMPTY_MAP;
- }
-
- public Object getXPathProperty(String xpath) {
- return getXPathProperty(xpath, true);
- }
-
- public Object getXPathProperty(String xpath, boolean onlyPrimitive) {
- List<String> hierarchy = checkEditable(xpath, true, false);
- if (hierarchy == null) return null;
- return Utils.getObjectByPath(props, onlyPrimitive, hierarchy);
- }
-
- public ConfigOverlay setUserProperty(String key, Object val) {
- Map copy = new LinkedHashMap(userProps);
- copy.put(key, val);
- Map<String, Object> jsonObj = new LinkedHashMap<>(this.data);
- jsonObj.put("userProps", copy);
- return new ConfigOverlay(jsonObj, znodeVersion);
- }
-
- public ConfigOverlay unsetUserProperty(String key) {
- if (!userProps.containsKey(key)) return this;
- Map copy = new LinkedHashMap(userProps);
- copy.remove(key);
- Map<String, Object> jsonObj = new LinkedHashMap<>(this.data);
- jsonObj.put("userProps", copy);
- return new ConfigOverlay(jsonObj, znodeVersion);
- }
-
- public ConfigOverlay setProperty(String name, Object val) {
- List<String> hierarchy = checkEditable(name, false, true);
- Map deepCopy = (Map) Utils.fromJSON(Utils.toJSON(props));
- Map obj = deepCopy;
- for (int i = 0; i < hierarchy.size(); i++) {
- String s = hierarchy.get(i);
- if (i < hierarchy.size() - 1) {
- if (obj.get(s) == null || (!(obj.get(s) instanceof Map))) {
- obj.put(s, new LinkedHashMap<>());
- }
- obj = (Map) obj.get(s);
- } else {
- obj.put(s, val);
- }
- }
-
- Map<String, Object> jsonObj = new LinkedHashMap<>(this.data);
- jsonObj.put("props", deepCopy);
-
- return new ConfigOverlay(jsonObj, znodeVersion);
- }
-
-
- public static final String NOT_EDITABLE = "''{0}'' is not an editable property";
-
- private List<String> checkEditable(String propName, boolean isXPath, boolean failOnError) {
- LinkedList<String> hierarchy = new LinkedList<>();
- if (!isEditableProp(propName, isXPath, hierarchy)) {
- if (failOnError)
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, StrUtils.formatString(NOT_EDITABLE, propName));
- else return null;
- }
- return hierarchy;
-
- }
-
- public ConfigOverlay unsetProperty(String name) {
- List<String> hierarchy = checkEditable(name, false, true);
- Map deepCopy = (Map) Utils.fromJSON(Utils.toJSON(props));
- Map obj = deepCopy;
- for (int i = 0; i < hierarchy.size(); i++) {
- String s = hierarchy.get(i);
- if (i < hierarchy.size() - 1) {
- if (obj.get(s) == null || (!(obj.get(s) instanceof Map))) {
- return this;
- }
- obj = (Map) obj.get(s);
- } else {
- obj.remove(s);
- }
- }
-
- Map<String, Object> jsonObj = new LinkedHashMap<>(this.data);
- jsonObj.put("props", deepCopy);
-
- return new ConfigOverlay(jsonObj, znodeVersion);
- }
-
- public byte[] toByteArray() {
- return Utils.toJSON(data);
- }
-
-
- public int getZnodeVersion() {
- return znodeVersion;
- }
-
- @Override
- public String toString() {
- CharArr out = new CharArr();
- try {
- new JSONWriter(out, 2).write(data);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return out.toString();
- }
-
-
- public static final String RESOURCE_NAME = "configoverlay.json";
-
- /*private static final Long STR_ATTR = 0L;
- private static final Long STR_NODE = 1L;
- private static final Long BOOL_ATTR = 10L;
- private static final Long BOOL_NODE = 11L;
- private static final Long INT_ATTR = 20L;
- private static final Long INT_NODE = 21L;
- private static final Long FLOAT_ATTR = 30L;
- private static final Long FLOAT_NODE = 31L;*/
- //The path maps to the xml xpath and value of 1 means it is a tag with a string value and value
- // of 0 means it is an attribute with string value
-
- private static Map editable_prop_map = (Map) Utils.fromJSONResource("EditableSolrConfigAttributes.json");
-
- public static boolean isEditableProp(String path, boolean isXpath, List<String> hierarchy) {
- return !(checkEditable(path, isXpath, hierarchy) == null);
- }
-
-
- public static Class checkEditable(String path, boolean isXpath, List<String> hierarchy) {
- List<String> parts = StrUtils.splitSmart(path, isXpath ? '/' : '.');
- Object obj = editable_prop_map;
- for (int i = 0; i < parts.size(); i++) {
- String part = parts.get(i);
- boolean isAttr = isXpath && part.startsWith("@");
- if (isAttr) {
- part = part.substring(1);
- }
- if (hierarchy != null) hierarchy.add(part);
- if (obj == null) return null;
- if (i == parts.size() - 1) {
- if (obj instanceof Map) {
- Map map = (Map) obj;
- Object o = map.get(part);
- return checkType(o, isXpath, isAttr);
- }
- return null;
- }
- obj = ((Map) obj).get(part);
- }
- return null;
- }
-
- static Class[] types = new Class[]{String.class, Boolean.class, Integer.class, Float.class};
-
- private static Class checkType(Object o, boolean isXpath, boolean isAttr) {
- if (o instanceof Long) {
- Long aLong = (Long) o;
- int ten = aLong.intValue() / 10;
- int one = aLong.intValue() % 10;
- if (isXpath && isAttr && one != 0) return null;
- return types[ten];
- } else {
- return null;
- }
- }
-
- public Map<String, String> getEditableSubProperties(String xpath) {
- Object o = Utils.getObjectByPath(props, false, StrUtils.splitSmart(xpath, '/'));
- if (o instanceof Map) {
- return (Map) o;
- } else {
- return null;
- }
- }
-
- public Map<String, Object> getUserProps() {
- return userProps;
- }
-
- @Override
- public Map<String, Object> toMap(Map<String, Object> map) {
- map.put(ZNODEVER, znodeVersion);
- map.putAll(data);
- return map;
- }
-
- public Map<String, Map> getNamedPlugins(String typ) {
- Map<String, Map> reqHandlers = (Map<String, Map>) data.get(typ);
- if (reqHandlers == null) return Collections.EMPTY_MAP;
- return Collections.unmodifiableMap(reqHandlers);
- }
-
-
- public ConfigOverlay addNamedPlugin(Map<String, Object> info, String typ) {
- Map dataCopy = Utils.getDeepCopy(data, 4);
- Map reqHandler = (Map) dataCopy.get(typ);
- if (reqHandler == null) dataCopy.put(typ, reqHandler = new LinkedHashMap());
- reqHandler.put(info.get(CoreAdminParams.NAME), info);
- return new ConfigOverlay(dataCopy, this.znodeVersion);
- }
-
- public ConfigOverlay deleteNamedPlugin(String name, String typ) {
- Map dataCopy = Utils.getDeepCopy(data, 4);
- Map reqHandler = (Map) dataCopy.get(typ);
- if (reqHandler == null) return this;
- reqHandler.remove(name);
- return new ConfigOverlay(dataCopy, this.znodeVersion);
-
- }
-
- public static final String ZNODEVER = "znodeVersion";
- public static final String NAME = "overlay";
-
- public static void main(String[] args) {
- System.out.println(Utils.toJSONString(editable_prop_map));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/core/ConfigSet.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSet.java b/solr/core/src/java/org/apache/solr/core/ConfigSet.java
deleted file mode 100644
index e0c9fe4..0000000
--- a/solr/core/src/java/org/apache/solr/core/ConfigSet.java
+++ /dev/null
@@ -1,65 +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 org.apache.solr.common.util.NamedList;
-import org.apache.solr.schema.IndexSchema;
-
-/**
- * Stores a core's configuration in the form of a SolrConfig and IndexSchema
- */
-public class ConfigSet {
-
- private final String name;
-
- private final SolrConfig solrconfig;
-
- private final IndexSchema indexSchema;
-
- private final NamedList properties;
-
- private final boolean trusted;
-
- public ConfigSet(String name, SolrConfig solrConfig, IndexSchema indexSchema,
- NamedList properties, boolean trusted) {
- this.name = name;
- this.solrconfig = solrConfig;
- this.indexSchema = indexSchema;
- this.properties = properties;
- this.trusted = trusted;
- }
-
- public String getName() {
- return name;
- }
-
- public SolrConfig getSolrConfig() {
- return solrconfig;
- }
-
- public IndexSchema getIndexSchema() {
- return indexSchema;
- }
-
- public NamedList getProperties() {
- return properties;
- }
-
- public boolean isTrusted() {
- return trusted;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/core/ConfigSetProperties.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetProperties.java b/solr/core/src/java/org/apache/solr/core/ConfigSetProperties.java
deleted file mode 100644
index 77cd272..0000000
--- a/solr/core/src/java/org/apache/solr/core/ConfigSetProperties.java
+++ /dev/null
@@ -1,82 +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.io.InputStreamReader;
-import java.lang.invoke.MethodHandles;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.util.NamedList;
-
-import org.noggit.JSONParser;
-import org.noggit.ObjectBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class ConfigSetProperties {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- public static final String DEFAULT_FILENAME = "configsetprops.json";
- public static final String IMMUTABLE_CONFIGSET_ARG = "immutable";
-
- /**
- * Return the properties associated with the ConfigSet (e.g. immutable)
- *
- * @param loader the resource loader
- * @param name the name of the config set properties file
- * @return the properties in a NamedList
- */
- public static NamedList readFromResourceLoader(SolrResourceLoader loader, String name) {
- InputStreamReader reader;
- try {
- reader = new InputStreamReader(loader.openResource(name), StandardCharsets.UTF_8);
- } catch (SolrResourceNotFoundException ex) {
- log.debug("Did not find ConfigSet properties, assuming default properties: " + ex.getMessage());
- return null;
- } catch (Exception ex) {
- throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to load reader for ConfigSet properties: " + name, ex);
- }
-
- try {
- return readFromInputStream(reader);
- } finally {
- IOUtils.closeQuietly(reader);
- }
- }
-
- public static NamedList readFromInputStream(InputStreamReader reader) {
- try {
- JSONParser jsonParser = new JSONParser(reader);
- Object object = ObjectBuilder.getVal(jsonParser);
- if (!(object instanceof Map)) {
- final String objectClass = object == null ? "null" : object.getClass().getName();
- throw new SolrException(ErrorCode.SERVER_ERROR, "Invalid JSON type " + objectClass + ", expected Map");
- }
- return new NamedList((Map)object);
- } catch (Exception ex) {
- throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to load ConfigSet properties", ex);
- } finally {
- IOUtils.closeQuietly(reader);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
deleted file mode 100644
index 7ce1a52..0000000
--- a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
+++ /dev/null
@@ -1,243 +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.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.time.Instant;
-import java.util.Locale;
-import java.util.concurrent.ExecutionException;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import org.apache.solr.cloud.CloudConfigSetService;
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.cloud.ZkSolrResourceLoader;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.schema.IndexSchema;
-import org.apache.solr.schema.IndexSchemaFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Service class used by the CoreContainer to load ConfigSets for use in SolrCore
- * creation.
- */
-public abstract class ConfigSetService {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static ConfigSetService createConfigSetService(NodeConfig nodeConfig, SolrResourceLoader loader, ZkController zkController) {
- if (zkController != null)
- return new CloudConfigSetService(loader, zkController);
-
- if (nodeConfig.hasSchemaCache())
- return new SchemaCaching(loader, nodeConfig.getConfigSetBaseDirectory());
-
- return new Default(loader, nodeConfig.getConfigSetBaseDirectory());
- }
-
- protected final SolrResourceLoader parentLoader;
-
- /**
- * Create a new ConfigSetService
- * @param loader the CoreContainer's resource loader
- */
- public ConfigSetService(SolrResourceLoader loader) {
- this.parentLoader = loader;
- }
-
- /**
- * Load the ConfigSet for a core
- * @param dcore the core's CoreDescriptor
- * @return a ConfigSet
- */
- public final ConfigSet getConfig(CoreDescriptor dcore) {
-
- SolrResourceLoader coreLoader = createCoreResourceLoader(dcore);
-
- try {
-
- // ConfigSet properties are loaded from ConfigSetProperties.DEFAULT_FILENAME file.
- // ConfigSet flags are loaded from the metadata of the ZK node of the configset.
- NamedList properties = createConfigSetProperties(dcore, coreLoader);
- NamedList flags = getConfigSetFlags(dcore, coreLoader);
-
- boolean trusted =
- (coreLoader instanceof ZkSolrResourceLoader
- && flags != null
- && flags.get("trusted") != null
- && !flags.getBooleanArg("trusted")
- ) ? false: true;
-
- SolrConfig solrConfig = createSolrConfig(dcore, coreLoader);
- IndexSchema schema = createIndexSchema(dcore, solrConfig);
- return new ConfigSet(configName(dcore), solrConfig, schema, properties, trusted);
- } catch (Exception e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Could not load conf for core " + dcore.getName() +
- ": " + e.getMessage(), e);
- }
-
- }
-
- /**
- * Create a SolrConfig object for a core
- * @param cd the core's CoreDescriptor
- * @param loader the core's resource loader
- * @return a SolrConfig object
- */
- protected SolrConfig createSolrConfig(CoreDescriptor cd, SolrResourceLoader loader) {
- return SolrConfig.readFromResourceLoader(loader, cd.getConfigName());
- }
-
- /**
- * Create an IndexSchema object for a core
- * @param cd the core's CoreDescriptor
- * @param solrConfig the core's SolrConfig
- * @return an IndexSchema
- */
- protected IndexSchema createIndexSchema(CoreDescriptor cd, SolrConfig solrConfig) {
- return IndexSchemaFactory.buildIndexSchema(cd.getSchemaName(), solrConfig);
- }
-
- /**
- * Return the ConfigSet properties
- * @param cd the core's CoreDescriptor
- * @param loader the core's resource loader
- * @return the ConfigSet properties
- */
- protected NamedList createConfigSetProperties(CoreDescriptor cd, SolrResourceLoader loader) {
- return ConfigSetProperties.readFromResourceLoader(loader, cd.getConfigSetPropertiesName());
- }
-
- protected NamedList getConfigSetFlags(CoreDescriptor cd, SolrResourceLoader loader) {
- if (loader instanceof ZkSolrResourceLoader) {
- try {
- return ConfigSetProperties.readFromResourceLoader(loader, ".");
- } catch (Exception ex) {
- return null;
- }
- } else {
- return null;
- }
- }
-
- /**
- * Create a SolrResourceLoader for a core
- * @param cd the core's CoreDescriptor
- * @return a SolrResourceLoader
- */
- protected abstract SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd);
-
- /**
- * Return a name for the ConfigSet for a core
- * @param cd the core's CoreDescriptor
- * @return a name for the core's ConfigSet
- */
- public abstract String configName(CoreDescriptor cd);
-
- /**
- * The default ConfigSetService.
- *
- * Loads a ConfigSet defined by the core's configSet property,
- * looking for a directory named for the configSet property value underneath
- * a base directory. If no configSet property is set, loads the ConfigSet
- * instead from the core's instance directory.
- */
- public static class Default extends ConfigSetService {
-
- private final Path configSetBase;
-
- /**
- * Create a new ConfigSetService.Default
- * @param loader the CoreContainer's resource loader
- * @param configSetBase the base directory under which to look for config set directories
- */
- public Default(SolrResourceLoader loader, Path configSetBase) {
- super(loader);
- this.configSetBase = configSetBase;
- }
-
- @Override
- public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) {
- Path instanceDir = locateInstanceDir(cd);
- return new SolrResourceLoader(instanceDir, parentLoader.getClassLoader(), cd.getSubstitutableProperties());
- }
-
- @Override
- public String configName(CoreDescriptor cd) {
- return (cd.getConfigSet() == null ? "instancedir " : "configset ") + locateInstanceDir(cd);
- }
-
- protected Path locateInstanceDir(CoreDescriptor cd) {
- String configSet = cd.getConfigSet();
- if (configSet == null)
- return cd.getInstanceDir();
- Path configSetDirectory = configSetBase.resolve(configSet);
- if (!Files.isDirectory(configSetDirectory))
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Could not load configuration from directory " + configSetDirectory);
- return configSetDirectory;
- }
-
- }
-
- /**
- * A ConfigSetService that shares schema objects between cores
- */
- public static class SchemaCaching extends Default {
-
- private final Cache<String, IndexSchema> schemaCache = CacheBuilder.newBuilder().build();
-
- public SchemaCaching(SolrResourceLoader loader, Path configSetBase) {
- super(loader, configSetBase);
- }
-
- public static String cacheName(Path schemaFile) throws IOException {
- long lastModified = Files.getLastModifiedTime(schemaFile).toMillis();
- return String.format(Locale.ROOT, "%s:%s",
- schemaFile.toString(), Instant.ofEpochMilli(lastModified).toString());
- }
-
- @Override
- public IndexSchema createIndexSchema(final CoreDescriptor cd, final SolrConfig solrConfig) {
- final String resourceNameToBeUsed = IndexSchemaFactory.getResourceNameToBeUsed(cd.getSchemaName(), solrConfig);
- Path schemaFile = Paths.get(solrConfig.getResourceLoader().getConfigDir()).resolve(resourceNameToBeUsed);
- if (Files.exists(schemaFile)) {
- try {
- String cachedName = cacheName(schemaFile);
- return schemaCache.get(cachedName, () -> {
- log.info("Creating new index schema for core {}", cd.getName());
- return IndexSchemaFactory.buildIndexSchema(cd.getSchemaName(), solrConfig);
- });
- } catch (ExecutionException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Error creating index schema for core " + cd.getName(), e);
- } catch (IOException e) {
- log.warn("Couldn't get last modified time for schema file {}: {}", schemaFile, e.getMessage());
- log.warn("Will not use schema cache");
- }
- }
- return IndexSchemaFactory.buildIndexSchema(cd.getSchemaName(), solrConfig);
- }
- }
-
-}