dsmiley commented on code in PR #4073: URL: https://github.com/apache/solr/pull/4073#discussion_r2724461614
########## solr/core/src/java/org/apache/solr/response/BuiltInResponseWriters.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.response; + +import static org.apache.solr.handler.admin.MetricsHandler.OPEN_METRICS_WT; +import static org.apache.solr.handler.admin.MetricsHandler.PROMETHEUS_METRICS_WT; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.solr.common.params.CommonParams; + +/** + * Registry for built-in response writers in Solr. + * + * <p>Manages a minimal set of essential response writers that are always available, regardless of + * core configuration or ImplicitPlugins.json settings. These writers are primarily used by + * admin/container-level requests that have no associated SolrCore. + * + * <p>Built-in writers include essential formats needed by admin APIs and core functionality: + * javabin, json, xml, prometheus, and openmetrics. + * + * <p>For core-specific requests that need access to the full set of response writers (including + * csv, geojson, graphml, smile, etc.), use the SolrCore's response writer registry which is loaded + * from ImplicitPlugins.json and supports ConfigOverlay customizations. + */ +public class BuiltInResponseWriters { Review Comment: How about calling this `ResponseWriterRegistry`? Or `ResponseWriters` Presently, just "built-in" stuff but I could see one day increasing/changing to hold node level plugins that may be registered in advance via solr.xml or ServiceLoader. ########## solr/core/src/java/org/apache/solr/response/BuiltInResponseWriters.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.response; + +import static org.apache.solr.handler.admin.MetricsHandler.OPEN_METRICS_WT; +import static org.apache.solr.handler.admin.MetricsHandler.PROMETHEUS_METRICS_WT; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.solr.common.params.CommonParams; + +/** + * Registry for built-in response writers in Solr. + * + * <p>Manages a minimal set of essential response writers that are always available, regardless of + * core configuration or ImplicitPlugins.json settings. These writers are primarily used by + * admin/container-level requests that have no associated SolrCore. + * + * <p>Built-in writers include essential formats needed by admin APIs and core functionality: + * javabin, json, xml, prometheus, and openmetrics. + * + * <p>For core-specific requests that need access to the full set of response writers (including + * csv, geojson, graphml, smile, etc.), use the SolrCore's response writer registry which is loaded + * from ImplicitPlugins.json and supports ConfigOverlay customizations. + */ +public class BuiltInResponseWriters { + + private BuiltInResponseWriters() { + // Prevent instantiation + } + + /** + * Built-in response writers that are always available. + * + * <p>Contains only essential formats needed by admin APIs and core functionality: + * + * <ul> + * <li><b>javabin</b> - Binary format, efficient for SolrJ clients + * <li><b>json/standard</b> - JSON format, default for most requests + * <li><b>xml</b> - XML format, provides backward compatibility + * <li><b>prometheus/openmetrics</b> - Required by metrics endpoints + * </ul> + */ + private static final Map<String, QueryResponseWriter> BUILTIN_WRITERS; + + static { + // Initialize built-in writers that are always available + Map<String, QueryResponseWriter> builtinWriters = new HashMap<>(6, 1); Review Comment: Instead lets use `Map.of` which is more modern Java and is especially applicable to read-only write once read-many use-cases like here. ########## solr/core/src/java/org/apache/solr/response/BuiltInResponseWriters.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.response; + +import static org.apache.solr.handler.admin.MetricsHandler.OPEN_METRICS_WT; +import static org.apache.solr.handler.admin.MetricsHandler.PROMETHEUS_METRICS_WT; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.solr.common.params.CommonParams; + +/** + * Registry for built-in response writers in Solr. + * + * <p>Manages a minimal set of essential response writers that are always available, regardless of + * core configuration or ImplicitPlugins.json settings. These writers are primarily used by + * admin/container-level requests that have no associated SolrCore. + * + * <p>Built-in writers include essential formats needed by admin APIs and core functionality: + * javabin, json, xml, prometheus, and openmetrics. + * + * <p>For core-specific requests that need access to the full set of response writers (including + * csv, geojson, graphml, smile, etc.), use the SolrCore's response writer registry which is loaded + * from ImplicitPlugins.json and supports ConfigOverlay customizations. + */ +public class BuiltInResponseWriters { + + private BuiltInResponseWriters() { + // Prevent instantiation + } + + /** + * Built-in response writers that are always available. + * + * <p>Contains only essential formats needed by admin APIs and core functionality: + * + * <ul> + * <li><b>javabin</b> - Binary format, efficient for SolrJ clients + * <li><b>json/standard</b> - JSON format, default for most requests + * <li><b>xml</b> - XML format, provides backward compatibility + * <li><b>prometheus/openmetrics</b> - Required by metrics endpoints + * </ul> + */ + private static final Map<String, QueryResponseWriter> BUILTIN_WRITERS; + + static { + // Initialize built-in writers that are always available + Map<String, QueryResponseWriter> builtinWriters = new HashMap<>(6, 1); + builtinWriters.put(CommonParams.JAVABIN, new JavaBinResponseWriter()); + builtinWriters.put(CommonParams.JSON, new JacksonJsonWriter()); + builtinWriters.put("standard", builtinWriters.get(CommonParams.JSON)); // Alias for JSON Review Comment: A separate issue, but I propose we universally remove the alias "standard" from all plugin types. It's such a Solr old-school thing that I don't see anyone use. Solr 11 only, of course. ########## solr/core/src/java/org/apache/solr/response/BuiltInResponseWriters.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.response; + +import static org.apache.solr.handler.admin.MetricsHandler.OPEN_METRICS_WT; +import static org.apache.solr.handler.admin.MetricsHandler.PROMETHEUS_METRICS_WT; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.solr.common.params.CommonParams; + +/** + * Registry for built-in response writers in Solr. + * + * <p>Manages a minimal set of essential response writers that are always available, regardless of Review Comment: I think these javadocs are over specified. IMO it shouldn't speak of cores or ImplicitPlugins. But `@see` links to key methods (that might be in SolrCore) is very helpful. I've noticed LLMs haven't been good, by and large, on link-ifying documentation. It just puts text. ########## solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java: ########## @@ -195,16 +196,22 @@ default CloudDescriptor getCloudDescriptor() { return getCore().getCoreDescriptor().getCloudDescriptor(); } - /** The writer to use for this request, considering {@link CommonParams#WT}. Never null. */ + /** + * The writer to use for this request, considering {@link CommonParams#WT}. Never null. + * + * <p>If a core is available, uses the core's response writer registry (loaded from + * ImplicitPlugins.json with ConfigOverlay support). If no core is available (e.g., for + * admin/container requests), uses a minimal set of admin-appropriate writers. Review Comment: I don't believe in javadocs over-specifying implementation details (like added here). Let us be free to change the implementation details without maintaining these docs. ########## solr/core/src/java/org/apache/solr/core/SolrCore.java: ########## @@ -3148,11 +3116,49 @@ default String getContentType() { } /** - * Configure the query response writers. There will always be a default writer; additional writers - * may also be configured. + * Gets a response writer suitable for admin/container-level requests. + * + * @param writerName the writer name, or null for default + * @return the response writer, never null + * @deprecated Use {@link + * org.apache.solr.response.BuiltInResponseWriterRegistry#getWriter(String)} instead. + */ + @Deprecated + public static QueryResponseWriter getAdminResponseWriter(String writerName) { + return org.apache.solr.response.BuiltInResponseWriterRegistry.getWriter(writerName); + } + + /** + * Initializes query response writers. Response writers from {@code ImplicitPlugins.json} may also + * be configured. */ private void initWriters() { - responseWriters.init(DEFAULT_RESPONSE_WRITERS, this); + // Build default writers map from implicit plugins + Map<String, QueryResponseWriter> defaultWriters = new HashMap<>(); + + // Load writers from ImplicitPlugins.json + List<PluginInfo> implicitWriters = getImplicitResponseWriters(); + for (PluginInfo info : implicitWriters) { + try { + QueryResponseWriter writer = + createInstance( + info.className, + QueryResponseWriter.class, + "queryResponseWriter", + null, + getResourceLoader()); Review Comment: I suspect the VelocityResponseWriter needs a SolrResourceLoader (from a core). Any way, we need not concern ourselves with that. ########## solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java: ########## @@ -735,8 +736,9 @@ protected void logAndFlushAdminRequest(SolrQueryResponse solrResp) throws IOExce solrResp.getToLogAsString("[admin]")); } } + // Admin requests have no core, use built-in writers Review Comment: "node/container" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
