From e1d4ec798732b30a3bd87f72beb98465a8735376 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Fri, 16 Jun 2017 16:09:27 +0930 Subject: [PATCH] SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic' --- solr/CHANGES.txt | 3 ++ .../AtomicUpdateProcessorFactory.java | 3 +- .../SimpleUpdateProcessorFactory.java | 18 +++++++--- .../TemplateUpdateProcessorFactory.java | 5 +++ .../UpdateRequestProcessorChain.java | 20 +++++++---- .../AtomicUpdateProcessorFactoryTest.java | 36 +++++++++---------- .../TemplateUpdateProcessorTest.java | 12 +++---- .../src/update-request-processors.adoc | 10 +++--- 8 files changed, 66 insertions(+), 41 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 7c8f013be33..c2e07059385 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -94,6 +94,9 @@ Upgrading from Solr 6.x * TemplateUpdateRequestProcessorFactory uses {} instead of ${} for template +* SOLR-9565: The name of TemplateUpdateRequestProcessorFactory' is changed to 'template' from 'Template' and the + name of 'AtomicUpdateProcessorFactory' is changed to 'atomic' from 'Atomic' + New Features ---------------------- * SOLR-9857, SOLR-9858: Collect aggregated metrics from nodes and shard leaders in overseer. (ab) diff --git a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java index 2292dc8441b..2135fb76c5b 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/AtomicUpdateProcessorFactory.java @@ -61,7 +61,8 @@ public class AtomicUpdateProcessorFactory extends UpdateRequestProcessorFactory private final static Set VALID_OPS = new HashSet<>(Arrays.asList(ADD, INC, REMOVE, SET, REMOVEREGEX)); private final static String VERSION = "_version_"; - private final static String ATOMIC_FIELD_PREFIX = "Atomic."; + public static final String NAME = "atomic"; + public final static String ATOMIC_FIELD_PREFIX = "atomic."; private final static int MAX_ATTEMPTS = 5; private VersionInfo vinfo; diff --git a/solr/core/src/java/org/apache/solr/update/processor/SimpleUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/SimpleUpdateProcessorFactory.java index b1edea039d0..e78e3fb4d96 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/SimpleUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/SimpleUpdateProcessorFactory.java @@ -29,14 +29,12 @@ import org.apache.solr.update.AddUpdateCommand; * This is deliberately made to support only the add operation */ public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcessorFactory { - protected final String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz + private String myName; // if classname==XyzUpdateProcessorFactory myName=Xyz protected NamedList initArgs = new NamedList(); private static ThreadLocal REQ = new ThreadLocal<>(); protected SimpleUpdateProcessorFactory() { - String simpleName = this.getClass().getSimpleName(); - int idx = simpleName.indexOf("UpdateProcessorFactory"); - this.myName = idx == -1 ? simpleName : simpleName.substring(0, idx); + } @Override @@ -80,7 +78,17 @@ public abstract class SimpleUpdateProcessorFactory extends UpdateRequestProcesso } private String _param(String name) { - return myName + "." + name; + return getMyName() + "." + name; + } + + protected String getMyName() { + String myName = this.myName; + if (myName == null) { + String simpleName = this.getClass().getSimpleName(); + int idx = simpleName.indexOf("UpdateProcessorFactory"); + this.myName = myName = idx == -1 ? simpleName : simpleName.substring(0, idx); + } + return myName; } diff --git a/solr/core/src/java/org/apache/solr/update/processor/TemplateUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/TemplateUpdateProcessorFactory.java index 19c331f073d..b6e2c8b493e 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/TemplateUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/TemplateUpdateProcessorFactory.java @@ -41,6 +41,7 @@ import org.apache.solr.util.ConcurrentLRUCache; */ public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory { private Cache templateCache = new ConcurrentLRUCache<>(1000, 800, 900, 10, false, false, null); + public static final String NAME = "template"; @Override protected void process(AddUpdateCommand cmd, SolrQueryRequest req, SolrQueryResponse rsp) { String[] vals = getParams("field"); @@ -63,6 +64,10 @@ public class TemplateUpdateProcessorFactory extends SimpleUpdateProcessorFactory } + @Override + protected String getMyName() { + return NAME; + } public static Resolved getResolved(String template, Cache cache, Pattern pattern) { Resolved r = cache == null ? null : cache.get(template); diff --git a/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java b/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java index 3db42aa8837..6bb212cbc46 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java +++ b/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessorChain.java @@ -21,8 +21,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Objects; +import com.google.common.collect.ImmutableMap; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.SolrParams; @@ -271,12 +273,13 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized if (s.isEmpty()) continue; UpdateRequestProcessorFactory p = core.getUpdateProcessors().get(s); if (p == null) { - PluginInfo pluginInfo = new PluginInfo("updateProcessor", - Utils.makeMap("name", s, - "class", s + "UpdateProcessorFactory", - "runtimeLib", "true")); - - core.getUpdateProcessors().put(s, p = core.getUpdateProcessors().createPlugin(pluginInfo).get()); + Class factoryClass = implicits.get(s); + if(factoryClass != null) { + PluginInfo pluginInfo = new PluginInfo("updateProcessor", + Utils.makeMap("name", s, + "class", factoryClass.getName())); + core.getUpdateProcessors().put(s, p = core.getUpdateProcessors().createPlugin(pluginInfo).get()); + } if (p == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s); } @@ -315,4 +318,9 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized } } + public static final Map implicits = new ImmutableMap.Builder() + .put(TemplateUpdateProcessorFactory.NAME, TemplateUpdateProcessorFactory.class) + .put(AtomicUpdateProcessorFactory.NAME, AtomicUpdateProcessorFactory.class) + .build(); + } diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java index f3f833d90c0..45349373f87 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdateProcessorFactoryTest.java @@ -45,7 +45,7 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 { AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams() .add("processor", "Atomic") - .add("Atomic.cat", "delete") + .add("atomic.cat", "delete") .add("commit","true") )); @@ -63,8 +63,8 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 { public void testNoUniqueIdPassed() throws Exception { //TODO AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams() - .add("processor", "Atomic") - .add("Atomic.cat", "add") + .add("processor", "atomic") + .add("atomic.cat", "add") .add("commit","true") )); @@ -85,12 +85,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 { AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams() - .add("processor", "Atomic") - .add("Atomic.cat", "add") - .add("Atomic.title", "set") - .add("Atomic.count_i", "set") - .add("Atomic.name_s", "set") - .add("Atomic.multiDefault", "set") + .add("processor", "atomic") + .add("atomic.cat", "add") + .add("atomic.title", "set") + .add("atomic.count_i", "set") + .add("atomic.name_s", "set") + .add("atomic.multiDefault", "set") .add("commit","true") )); @@ -136,12 +136,12 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 { cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams() - .add("processor", "Atomic") - .add("Atomic.cat", "add") - .add("Atomic.title", "set") - .add("Atomic.count_i", "inc") - .add("Atomic.name_s", "remove") - .add("Atomic.multiDefault", "removeregex") + .add("processor", "atomic") + .add("atomic.cat", "add") + .add("atomic.title", "set") + .add("atomic.count_i", "inc") + .add("atomic.name_s", "remove") + .add("atomic.multiDefault", "removeregex") .add("commit","true") )); @@ -216,9 +216,9 @@ public class AtomicUpdateProcessorFactoryTest extends SolrTestCaseJ4 { public void run() { AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams() - .add("processor", "Atomic") - .add("Atomic.cat", "add") - .add("Atomic.int_i", "inc") + .add("processor", "atomic") + .add("atomic.cat", "add") + .add("atomic.int_i", "inc") .add("commit","true") )); diff --git a/solr/core/src/test/org/apache/solr/update/processor/TemplateUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/TemplateUpdateProcessorTest.java index e14521903d6..6eb122a3f48 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/TemplateUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/TemplateUpdateProcessorTest.java @@ -61,10 +61,10 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase { public void testSimple() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams() - .add("processor", "Template") - .add("Template.field", "id:{firstName}_{lastName}") - .add("Template.field", "another:{lastName}_{firstName}") - .add("Template.field", "missing:{lastName}_{unKnown}"); + .add("processor", "template") + .add("template.field", "id:{firstName}_{lastName}") + .add("template.field", "another:{lastName}_{firstName}") + .add("template.field", "missing:{lastName}_{unKnown}"); AddUpdateCommand cmd = new AddUpdateCommand(new LocalSolrQueryRequest(null, params @@ -82,9 +82,9 @@ public class TemplateUpdateProcessorTest extends SolrCloudTestCase { solrDoc.addField("id", "1"); params = new ModifiableSolrParams() - .add("processor", "Template") + .add("processor", "template") .add("commit", "true") - .add("Template.field", "x_s:key_{id}"); + .add("template.field", "x_s:key_{id}"); params.add("commit", "true"); UpdateRequest add = new UpdateRequest().add(solrDoc); add.setParams(params); diff --git a/solr/solr-ref-guide/src/update-request-processors.adoc b/solr/solr-ref-guide/src/update-request-processors.adoc index 7942028f792..37cdebbb9bf 100644 --- a/solr/solr-ref-guide/src/update-request-processors.adoc +++ b/solr/solr-ref-guide/src/update-request-processors.adoc @@ -386,27 +386,27 @@ These Update processors do not need any configuration is your `solrconfig.xml` . The `TemplateUpdateProcessorFactory` can be used to add new fields to documents based on a template pattern. -Use the parameter `processor=Template` to use it. The template parameter `Template.field` (multivalued) defines the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request. +Use the parameter `processor=template` to use it. The template parameter `template.field` (multivalued) define the field to add and the pattern. Templates may contain placeholders which refer to other fields in the document. You can have multiple `Template.field` parameters in a single request. For example: [source,bash] ---- -processor=Template&Template.field=fullName:Mr. {firstName} {lastName} +processor=template&template.field=fullName:Mr. {firstName} {lastName} ---- -The above example would add a new field to the document called `fullName`. The fields `firstName` and `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used. +The above example would add a new field to the document called `fullName`. The fields `firstName and` `lastName` are supplied from the document fields. If either of them is missing, that part is replaced with an empty string. If those fields are multi-valued, only the first value is used. ==== AtomicUpdateProcessorFactory -Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations. +Name of the processor is `atomic` . Use it to convert your normal `update` operations to atomic update operations. This is particularly useful when you use endpoints such as `/update/csv` or `/update/json/docs` which does not support syntax for atomic operations. example: [source,bash] ---- -processor=Atomic&Atomic.field1=add&Atomic.field2=set&Atomic.field3=inc&Atomic.field4=remove&Atomic.field4=remove +processor=atomic&atomic.field1=add&atomic.field2=set&atomic.field3=inc&atomic.field4=remove&atomic.field4=remove ---- The above parameters convert a normal `update` operation on