-
Notifications
You must be signed in to change notification settings - Fork 828
SOLR-17600 (Part 1/4): Migrate V2 API Payloads from MapSerializable #4463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ | |
| import org.apache.solr.client.solrj.response.SimpleSolrResponse; | ||
| import org.apache.solr.cloud.ZkController; | ||
| import org.apache.solr.cloud.ZkSolrResourceLoader; | ||
| import org.apache.solr.common.MapSerializable; | ||
| import org.apache.solr.common.MapWriter; | ||
| import org.apache.solr.common.SolrErrorWrappingException; | ||
| import org.apache.solr.common.SolrException; | ||
| import org.apache.solr.common.cloud.ClusterState; | ||
|
|
@@ -75,6 +75,7 @@ | |
| import org.apache.solr.common.util.EnvUtils; | ||
| import org.apache.solr.common.util.ExecutorUtil; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.common.util.SolrNamedThreadFactory; | ||
| import org.apache.solr.common.util.StrUtils; | ||
| import org.apache.solr.common.util.Utils; | ||
|
|
@@ -204,7 +205,7 @@ private void handleGET() { | |
| Map<String, Object> m = new LinkedHashMap<>(); | ||
| m.put(ZNODEVER, params.getZnodeVersion()); | ||
| if (p != null) { | ||
| m.put(RequestParams.NAME, Map.of(parts.get(2), p.toMap(new LinkedHashMap<>()))); | ||
| m.put(RequestParams.NAME, Map.of(parts.get(2), new SimpleOrderedMap<>(p))); | ||
| } | ||
| resp.add(SolrQueryResponse.NAME, m); | ||
| } else { | ||
|
|
@@ -283,16 +284,16 @@ private void handleGET() { | |
| Map pluginNameVsPluginInfo = (Map) val.get(parts.get(1)); | ||
| if (pluginNameVsPluginInfo != null) { | ||
| Object o = | ||
| pluginNameVsPluginInfo instanceof MapSerializable | ||
| pluginNameVsPluginInfo instanceof MapWriter | ||
| ? pluginNameVsPluginInfo | ||
| : pluginNameVsPluginInfo.get(componentName); | ||
| Map<String, Object> pluginInfo = | ||
| o instanceof MapSerializable | ||
| ? ((MapSerializable) o).toMap(new LinkedHashMap<>()) | ||
| o instanceof MapWriter | ||
| ? new SimpleOrderedMap<>((MapWriter) o) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SOM is okay for response |
||
| : (Map<String, Object>) o; | ||
| val.put( | ||
| parts.get(1), | ||
| pluginNameVsPluginInfo instanceof PluginInfo | ||
| pluginNameVsPluginInfo instanceof MapWriter | ||
| ? pluginInfo | ||
| : Map.of(componentName, pluginInfo)); | ||
| if (req.getParams().getBool("meta", false)) { | ||
|
|
@@ -306,8 +307,10 @@ private void handleGET() { | |
| if (infos == null || infos.isEmpty()) continue; | ||
| infos.forEach( | ||
| (s, mapWriter) -> { | ||
| if (s.equals(pluginInfo.get("class"))) { | ||
| (pluginInfo).put("_packageinfo_", mapWriter); | ||
| Map<String, Object> componentInfo = | ||
| getComponentInfo(pluginInfo, componentName); | ||
| if (s.equals(componentInfo.get("class"))) { | ||
| (componentInfo).put("_packageinfo_", mapWriter); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -320,10 +323,20 @@ private void handleGET() { | |
| } | ||
| } | ||
|
|
||
| @SuppressWarnings({"unchecked"}) | ||
| private Map<String, Object> getComponentInfo( | ||
| Map<String, Object> pluginInfo, String componentName) { | ||
| if (pluginInfo.containsKey("class")) { | ||
| return pluginInfo; | ||
| } | ||
| return (Map<String, Object>) | ||
| pluginInfo.computeIfAbsent(componentName, k -> new LinkedHashMap<>()); | ||
| } | ||
|
|
||
| private Map<String, Object> getConfigDetails(String componentType, SolrQueryRequest req) { | ||
| String componentName = componentType == null ? null : req.getParams().get("componentName"); | ||
| boolean showParams = req.getParams().getBool("expandParams", false); | ||
| Map<String, Object> map = this.req.getCore().getSolrConfig().toMap(new LinkedHashMap<>()); | ||
| Map<String, Object> map = new SimpleOrderedMap<>(this.req.getCore().getSolrConfig()); | ||
|
|
||
| if (componentType != null && !SolrRequestHandler.TYPE.equals(componentType)) return map; | ||
|
|
||
| @SuppressWarnings({"unchecked"}) | ||
|
|
@@ -356,7 +369,7 @@ private Map<String, Object> expandUseParams(SolrQueryRequest req, Object plugin) | |
| if (plugin instanceof Map) { | ||
| pluginInfo = (Map) plugin; | ||
| } else if (plugin instanceof PluginInfo) { | ||
| pluginInfo = ((PluginInfo) plugin).toMap(new LinkedHashMap<>()); | ||
| pluginInfo = new SimpleOrderedMap<>((PluginInfo) plugin); | ||
|
|
||
| } | ||
| String useParams = (String) pluginInfo.get(USEPARAM); | ||
| String useParamsInReq = req.getOriginalParams().get(USEPARAM); | ||
|
|
@@ -510,9 +523,7 @@ private void handleParams(ArrayList<CommandOperation> ops, RequestParams params) | |
| ZkController.touchConfDir(zkLoader); | ||
| } else { | ||
| if (log.isDebugEnabled()) { | ||
| log.debug( | ||
| "persisting params data : {}", | ||
| Utils.toJSONString(params.toMap(new LinkedHashMap<>()))); | ||
| log.debug("persisting params data : {}", Utils.toJSONString(params)); | ||
| } | ||
| int latestVersion = | ||
| ZkController.persistConfigResourceToZooKeeper( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST; | ||
| import static org.apache.solr.common.util.StrUtils.splitSmart; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
@@ -185,7 +186,7 @@ public Iterator<String> getParameterNamesIterator() { | |
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> toMap(Map<String, Object> suppliedMap) { | ||
| public void writeMap(EntryWriter ew) throws IOException { | ||
| for (Iterator<String> it = getParameterNamesIterator(); it.hasNext(); ) { | ||
| final String param = it.next(); | ||
| String key = cmd.meta().getParamSubstitute(param); | ||
|
|
@@ -195,26 +196,32 @@ public Map<String, Object> toMap(Map<String, Object> suppliedMap) { | |
| : map.get(key); | ||
| if (o == null) o = pathValues.get(key); | ||
| if (o == null && useRequestParams) o = origParams.getParams(key); | ||
| if (o == null) { | ||
| ew.put(param, null); | ||
| continue; | ||
| } | ||
|
Comment on lines
+199
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we skip putting 'null'? Curious, what test or issue brought this change about? |
||
| // make strings out of as many things as we can now to minimize differences from | ||
| // the standard impls that pass through a NamedList/SimpleOrderedMap... | ||
| Class<?> oClass = o.getClass(); | ||
| if (oClass.isPrimitive() | ||
| || Number.class.isAssignableFrom(oClass) | ||
| || Character.class.isAssignableFrom(oClass) | ||
| || Boolean.class.isAssignableFrom(oClass)) { | ||
| suppliedMap.put(param, String.valueOf(o)); | ||
| } else if (List.class.isAssignableFrom(oClass) | ||
| && ((List) o).get(0) instanceof String) { | ||
| ew.put(param, String.valueOf(o)); | ||
| } else if (List.class.isAssignableFrom(oClass)) { | ||
| @SuppressWarnings({"unchecked"}) | ||
| List<String> l = (List<String>) o; | ||
| suppliedMap.put(param, l.toArray(new String[0])); | ||
| List<?> l = (List<?>) o; | ||
| if (l.isEmpty() || l.get(0) instanceof String) { | ||
| ew.put(param, l.toArray(new String[0])); | ||
| } else { | ||
| ew.put(param, o); | ||
| } | ||
| } else { | ||
| // Lists pass through but will require special handling downstream | ||
| // if they contain non-string elements. | ||
| suppliedMap.put(param, o); | ||
| ew.put(param, o); | ||
| } | ||
| } | ||
| return suppliedMap; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ | |
| import org.apache.lucene.util.SuppressForbidden; | ||
| import org.apache.lucene.util.UnicodeUtil; | ||
| import org.apache.solr.common.MapWriter; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.common.util.Utils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -277,12 +278,10 @@ private void convert(Map<String, Object> result) { | |
| for (Map.Entry<String, Object> entry : result.entrySet()) { | ||
| Object value = entry.getValue(); | ||
| if (value instanceof ItemPriorityQueue queue) { | ||
| Map<String, Object> map = new LinkedHashMap<>(); | ||
| queue.toMap(map); | ||
| Map<String, Object> map = new SimpleOrderedMap<>(queue); | ||
| entry.setValue(map); | ||
| } else if (value instanceof MapWriterSummaryStatistics stats) { | ||
| Map<String, Object> map = new LinkedHashMap<>(); | ||
| stats.toMap(map); | ||
| Map<String, Object> map = new SimpleOrderedMap<>(stats); | ||
|
Comment on lines
+281
to
+284
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SOM is good here; this is a response-structure |
||
| entry.setValue(map); | ||
| } else if (value instanceof AtomicLong) { | ||
| entry.setValue(((AtomicLong) value).longValue()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,14 +22,14 @@ | |
| import static org.apache.solr.handler.ClusterAPI.wrapParams; | ||
| import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import org.apache.solr.api.Command; | ||
| import org.apache.solr.api.EndPoint; | ||
| import org.apache.solr.api.PayloadObj; | ||
| import org.apache.solr.client.solrj.request.beans.OverseerOperationPayload; | ||
| import org.apache.solr.common.params.CoreAdminParams; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.handler.admin.CoreAdminHandler; | ||
|
|
||
| /** | ||
|
|
@@ -59,7 +59,7 @@ public OverseerOperationAPI(CoreAdminHandler coreAdminHandler) { | |
| @Command(name = OVERSEER_OP_CMD) | ||
| public void joinOverseerLeaderElection(PayloadObj<OverseerOperationPayload> payload) | ||
| throws Exception { | ||
| final Map<String, Object> v1Params = payload.get().toMap(new HashMap<>()); | ||
| final Map<String, Object> v1Params = new SimpleOrderedMap<>(payload.get()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets standardize on use of |
||
| v1Params.put( | ||
| ACTION, CoreAdminParams.CoreAdminAction.OVERSEEROP.name().toLowerCase(Locale.ROOT)); | ||
| coreAdminHandler.handleRequestBody( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SOM makes sense as it's a response structure here