Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/unreleased/SOLR-16396-config-get-components.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title:
Migrate GET config sections updateHandler, directoryFactory, indexConfig, and codecFactory to JAX-RS.
type: changed
authors:
- name: Jalaz Kumar
nick: jaykay12
links:
- name: SOLR-16396
url: https://issues.apache.org/jira/browse/SOLR-16396
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import org.apache.solr.client.api.model.ConfigInfoResponse;
import org.apache.solr.client.api.model.ConfigOverlayResponse;
Expand Down Expand Up @@ -68,5 +69,16 @@ ConfigZnodeVersionResponse getZnodeVersion(
@DefaultValue("-1")
@Parameter(description = "Expected request-params znode version")
int expectedParamsVersion);

// TODO: Keep this regex in sync with GetConfig.MIGRATED_CONFIG_COMPONENTS
@GET
@Path("/{component:updateHandler|directoryFactory|indexConfig|codecFactory}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting! I mean, why not...

@StoreApiParameters
@Operation(
summary = "Fetch a config section",
tags = {"config"})
ConfigInfoResponse getConfigComponent(
@PathParam("component") @Parameter(description = "Name of the config component")
String component);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ private void handleGET() {
.getZnodeVersion(
req.getParams().getInt(ConfigOverlay.NAME, -1),
req.getParams().getInt(RequestParams.NAME, -1)));
} else if (GetConfig.MIGRATED_CONFIG_COMPONENTS.contains(parts.get(1))) {
V2ApiUtils.squashIntoSolrResponseWithoutHeader(
resp, new GetConfig(req).getConfigComponent(parts.get(1)));
} else {
Map<String, Object> m = getConfigDetails(parts.get(1), req);
Map<String, Object> val = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.solr.api.JerseyResource;
import org.apache.solr.client.api.endpoint.ConfigApi;
import org.apache.solr.client.api.model.ConfigInfoResponse;
Expand All @@ -48,6 +49,11 @@

public class GetConfig extends JerseyResource implements ConfigApi.Get {

// TODO: Keep this in sync with @Path regex on ConfigApi.Get#getConfigComponent.
// TODO: Remove this set when remaining GET /config/{component} sections also migrate.
public static final Set<String> MIGRATED_CONFIG_COMPONENTS =
Set.of("updateHandler", "directoryFactory", "indexConfig", "codecFactory");

private final SolrQueryRequest solrQueryRequest;

@Inject
Expand Down Expand Up @@ -89,15 +95,36 @@ public ConfigZnodeVersionResponse getZnodeVersion(
return response;
}

@Override
@PermissionName(CONFIG_READ_PERM)
public ConfigInfoResponse getConfigComponent(String componentName) {
final var response = instantiateJerseyResponse(ConfigInfoResponse.class);
Map<String, Object> section = new LinkedHashMap<>();
section.put(componentName, solrConfigAsMap().get(componentName));
response.config = jsonSafeCopy(section);
return response;
}

private Map<String, Object> solrConfigAsMap() {
return Utils.convertToMap(solrQueryRequest.getCore().getSolrConfig(), new LinkedHashMap<>());
}

@SuppressWarnings("unchecked")
private NullKeyTolerantMap jsonSafeCopy(Map<String, Object> map) {
final var jsonSafeCopy = new NullKeyTolerantMap("children");
jsonSafeCopy.putAll((Map<String, Object>) Utils.getDeepCopy(map, 20, true));
return jsonSafeCopy;
}

@SuppressWarnings({"unchecked"})
private Map<String, Object> buildConfigMap(
SolrQueryRequest solrQueryRequest, boolean expandParams) {
Map<String, Object> map =
Utils.convertToMap(solrQueryRequest.getCore().getSolrConfig(), new LinkedHashMap<>());

Map<String, Object> configMap = solrConfigAsMap();

Map<String, Object> reqHandlers =
(Map<String, Object>)
map.computeIfAbsent(SolrRequestHandler.TYPE, k -> new LinkedHashMap<>());
configMap.computeIfAbsent(SolrRequestHandler.TYPE, k -> new LinkedHashMap<>());
List<PluginInfo> plugins = solrQueryRequest.getCore().getImplicitHandlers();
for (PluginInfo plugin : plugins) {
if (SolrRequestHandler.TYPE.equals(plugin.type) && !reqHandlers.containsKey(plugin.name)) {
Expand All @@ -111,9 +138,7 @@ private Map<String, Object> buildConfigMap(
}
}

final var jsonSafeCopy = new NullKeyTolerantMap("children");
jsonSafeCopy.putAll((Map<String, Object>) Utils.getDeepCopy(map, 20, true));
return jsonSafeCopy;
return jsonSafeCopy(configMap);
}

@SuppressWarnings({"unchecked", "rawtypes"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
/**
* V2 APIs for retrieving some or all configuration relevant to a particular collection (or core).
*
* <p>This class covers legacy AnnotatedApi paths under GET /config: /params, /params{paramset},
* /overlay, /znodeVersion, etc.
* <p>This class covers legacy AnnotatedApi paths under GET /config: /params, /params{paramset}, and
* remaining {@code /config/{component}} sections not yet migrated to {@link
* org.apache.solr.client.api.endpoint.ConfigApi.Get}
*/
public class GetConfigAPI {
private final SolrConfigHandler configHandler;
Expand Down Expand Up @@ -63,13 +64,9 @@ public void getSingleParamSet(SolrQueryRequest req, SolrQueryResponse rsp) {
"/config/query",
"/config/requestHandler",
"/config/searchComponent",
"/config/updateHandler",
"/config/queryResponseWriter",
"/config/initParams",
"/config/listener",
"/config/directoryFactory",
"/config/indexConfig",
"/config/codecFactory",
"/config/requestDispatcher",
"/config/jmx",
"/config/queryParser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,19 @@ public void testGetZnodeVersionFromCollection() throws Exception {
assertTrue(response.znodeVersion.overlay >= -1);
assertTrue(response.znodeVersion.params >= -1);
}

@Test
public void testGetConfigComponentFromCollection() throws Exception {
for (String component : GetConfig.MIGRATED_CONFIG_COMPONENTS) {
var request =
new ConfigApi.GetConfigComponent(IndexType.COLLECTION, COLLECTION_NAME, component);
var response = request.process(cluster.getSolrClient());

assertNotNull(component, response);
assertNull(component, response.error);
assertNotNull(component, response.config);
assertTrue(component, response.config.containsKey(component));
assertEquals(component, 1, response.config.size());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,18 @@ public void testGetZnodeVersionFromCore() throws Exception {
assertTrue(response.znodeVersion.overlay >= -1);
assertTrue(response.znodeVersion.params >= -1);
}

@Test
public void testGetConfigComponentFromCore() throws Exception {
for (String component : GetConfig.MIGRATED_CONFIG_COMPONENTS) {
var request = new ConfigApi.GetConfigComponent(IndexType.CORE, CORE_NAME, component);
var response = request.process(solrTestRule.getSolrClient(CORE_NAME));

assertNotNull(component, response);
assertNull(component, response.error);
assertNotNull(component, response.config);
assertTrue(component, response.config.containsKey(component));
assertEquals(component, 1, response.config.size());
}
}
}
Loading