SOLR-6533: logging added and formatting fixed

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1658916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2015-02-11 10:40:03 +00:00
parent 78e1153dcb
commit 648eebbe92
3 changed files with 194 additions and 167 deletions

View File

@ -2148,6 +2148,7 @@ public final class ZkController {
try { try {
try { try {
zkClient.setData(resourceLocation, content, znodeVersion, true); zkClient.setData(resourceLocation, content, znodeVersion, true);
log.info("Persisted config data to node {} ", resourceLocation);
touchConfDir(zkLoader); touchConfDir(zkLoader);
} catch (NoNodeException e) { } catch (NoNodeException e) {
if (createIfNotExists) { if (createIfNotExists) {

View File

@ -91,7 +91,8 @@ public class SolrConfigHandler extends RequestHandlerBase {
String httpMethod = (String) req.getContext().get("httpMethod"); String httpMethod = (String) req.getContext().get("httpMethod");
Command command = new Command(req, rsp, httpMethod); Command command = new Command(req, rsp, httpMethod);
if ("POST".equals(httpMethod)) { if ("POST".equals(httpMethod)) {
if(configEditing_disabled) throw new SolrException(SolrException.ErrorCode.FORBIDDEN," solrconfig editing is not enabled"); if (configEditing_disabled)
throw new SolrException(SolrException.ErrorCode.FORBIDDEN, " solrconfig editing is not enabled");
command.handlePOST(); command.handlePOST();
} else { } else {
command.handleGET(); command.handleGET();
@ -204,7 +205,6 @@ public class SolrConfigHandler extends RequestHandlerBase {
} }
private void handleParams(ArrayList<CommandOperation> ops, RequestParams params) { private void handleParams(ArrayList<CommandOperation> ops, RequestParams params) {
for (CommandOperation op : ops) { for (CommandOperation op : ops) {
switch (op.name) { switch (op.name) {
@ -327,6 +327,7 @@ public class SolrConfigHandler extends RequestHandlerBase {
} }
List errs = CommandOperation.captureErrors(ops); List errs = CommandOperation.captureErrors(ops);
if (!errs.isEmpty()) { if (!errs.isEmpty()) {
log.info("Failed to run commands errors are {}", StrUtils.join(errs, ','));
resp.add(CommandOperation.ERR_MSGS, errs); resp.add(CommandOperation.ERR_MSGS, errs);
return; return;
} }
@ -336,12 +337,15 @@ public class SolrConfigHandler extends RequestHandlerBase {
ZkController.persistConfigResourceToZooKeeper((ZkSolrResourceLoader) loader, overlay.getZnodeVersion(), ZkController.persistConfigResourceToZooKeeper((ZkSolrResourceLoader) loader, overlay.getZnodeVersion(),
ConfigOverlay.RESOURCE_NAME, overlay.toByteArray(), true); ConfigOverlay.RESOURCE_NAME, overlay.toByteArray(), true);
log.info("Executed config commands successfully and persited to ZK {}", ops);
} else { } else {
SolrResourceLoader.persistConfLocally(loader, ConfigOverlay.RESOURCE_NAME, overlay.toByteArray()); SolrResourceLoader.persistConfLocally(loader, ConfigOverlay.RESOURCE_NAME, overlay.toByteArray());
req.getCore().getCoreDescriptor().getCoreContainer().reload(req.getCore().getName()); req.getCore().getCoreDescriptor().getCoreContainer().reload(req.getCore().getName());
log.info("Executed config commands successfully and persited to File System {}", ops);
} }
} }
private ConfigOverlay deleteNamedComponent(CommandOperation op, ConfigOverlay overlay, String typ) { private ConfigOverlay deleteNamedComponent(CommandOperation op, ConfigOverlay overlay, String typ) {
String name = op.getStr(CommandOperation.ROOT_OBJ); String name = op.getStr(CommandOperation.ROOT_OBJ);
if (op.hasError()) return overlay; if (op.hasError()) return overlay;
@ -417,7 +421,6 @@ public class SolrConfigHandler extends RequestHandlerBase {
} }
private ConfigOverlay applyUnset(CommandOperation op, ConfigOverlay overlay) { private ConfigOverlay applyUnset(CommandOperation op, ConfigOverlay overlay) {
List<String> name = op.getStrs(CommandOperation.ROOT_OBJ); List<String> name = op.getStrs(CommandOperation.ROOT_OBJ);
if (op.hasError()) return overlay; if (op.hasError()) return overlay;
@ -485,8 +488,10 @@ public class SolrConfigHandler extends RequestHandlerBase {
private static Set<String> subPaths = new HashSet<>(Arrays.asList("/overlay", "/params", private static Set<String> subPaths = new HashSet<>(Arrays.asList("/overlay", "/params",
"/query", "/jmx", "/requestDispatcher")); "/query", "/jmx", "/requestDispatcher"));
static { static {
for (SolrConfig.SolrPluginInfo solrPluginInfo : SolrConfig.plugins) subPaths.add("/"+solrPluginInfo.tag.replaceAll("/","")); for (SolrConfig.SolrPluginInfo solrPluginInfo : SolrConfig.plugins)
subPaths.add("/" + solrPluginInfo.tag.replaceAll("/", ""));
} }
@ -510,7 +515,6 @@ public class SolrConfigHandler extends RequestHandlerBase {
} }
public static final String SET_PROPERTY = "set-property"; public static final String SET_PROPERTY = "set-property";
public static final String UNSET_PROPERTY = "unset-property"; public static final String UNSET_PROPERTY = "unset-property";
public static final String SET_USER_PROPERTY = "set-user-property"; public static final String SET_USER_PROPERTY = "set-user-property";

View File

@ -19,6 +19,7 @@ package org.apache.solr.util;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -26,11 +27,14 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.cloud.ZkStateReader;
import org.noggit.JSONParser; import org.noggit.JSONParser;
import org.noggit.ObjectBuilder; import org.noggit.ObjectBuilder;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.apache.solr.common.cloud.ZkNodeProps.makeMap; import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
public class CommandOperation { public class CommandOperation {
@ -92,10 +96,12 @@ public class CommandOperation {
return val; return val;
} }
static final String REQD = "''{0}'' is a required field"; static final String REQD = "''{0}'' is a required field";
/**Get collection of values for a key. If only one val is present a /**
* Get collection of values for a key. If only one val is present a
* single value collection is returned * single value collection is returned
*/ */
public List<String> getStrs(String key, List<String> def) { public List<String> getStrs(String key, List<String> def) {
@ -122,7 +128,8 @@ public class CommandOperation {
} }
/**Get a required field. If missing it adds to the errors /**
* Get a required field. If missing it adds to the errors
*/ */
public String getStr(String key) { public String getStr(String key) {
if (ROOT_OBJ.equals(key)) { if (ROOT_OBJ.equals(key)) {
@ -151,7 +158,8 @@ public class CommandOperation {
errors.add(s); errors.add(s);
} }
/**Get all the values from the metadata for the command /**
* Get all the values from the metadata for the command
* without the specified keys * without the specified keys
*/ */
public Map getValuesExcluding(String... keys) { public Map getValuesExcluding(String... keys) {
@ -169,8 +177,10 @@ public class CommandOperation {
public List<String> getErrors() { public List<String> getErrors() {
return errors; return errors;
} }
public static final String ERR_MSGS = "errorMessages"; public static final String ERR_MSGS = "errorMessages";
public static final String ROOT_OBJ = ""; public static final String ROOT_OBJ = "";
public static List<Map> captureErrors(List<CommandOperation> ops) { public static List<Map> captureErrors(List<CommandOperation> ops) {
List<Map> errors = new ArrayList<>(); List<Map> errors = new ArrayList<>();
for (CommandOperation op : ops) { for (CommandOperation op : ops) {
@ -182,7 +192,8 @@ public class CommandOperation {
} }
/**Parse the command operations into command objects /**
* Parse the command operations into command objects
*/ */
public static List<CommandOperation> parse(Reader rdr) throws IOException { public static List<CommandOperation> parse(Reader rdr) throws IOException {
JSONParser parser = new JSONParser(rdr); JSONParser parser = new JSONParser(rdr);
@ -210,6 +221,7 @@ public class CommandOperation {
} }
} }
public CommandOperation getCopy() { public CommandOperation getCopy() {
return new CommandOperation(name, commandData); return new CommandOperation(name, commandData);
} }
@ -225,4 +237,14 @@ public class CommandOperation {
} }
} }
@Override
public String toString() {
try {
return new String(ZkStateReader.toJSON(singletonMap(name, commandData)), IOUtils.UTF_8);
} catch (UnsupportedEncodingException e) {
//should not happen
return "";
}
}
} }