Skip to content

SOLR-17625 NamedList.findRecursive-> _get #3355

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

Merged
merged 13 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/AssertTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
Expand Down Expand Up @@ -280,7 +281,7 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutMs, TimeUnit.MILLISECONDS);
try (SolrClient solrClient = CLIUtils.getSolrClient(url, credentials)) {
NamedList<Object> response = solrClient.request(new HealthCheckRequest());
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
Integer statusCode = (Integer) response._get(List.of("responseHeader", "status"), null);
CLIUtils.checkCodeForAuthError(statusCode);
} catch (IOException | SolrServerException e) {
log.debug("Opening connection to {} failed, Solr does not seem to be running", url, e);
Expand Down
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/ConfigTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.solr.cli;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.MissingArgumentException;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void runImpl(CommandLine cli) throws Exception {
try (SolrClient solrClient =
CLIUtils.getSolrClient(solrUrl, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) {
NamedList<Object> result = SolrCLI.postJsonToSolr(solrClient, updatePath, jsonBody);
Integer statusCode = (Integer) result.findRecursive("responseHeader", "status");
Integer statusCode = (Integer) result._get(List.of("responseHeader", "status"), null);
if (statusCode == 0) {
if (value != null) {
echo("Successfully " + action + " " + property + " to " + value);
Expand Down
7 changes: 4 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) th
solrClient.request(
new GenericSolrRequest(
SolrRequest.METHOD.GET, CommonParams.SYSTEM_INFO_PATH));
uptime = SolrCLI.uptime((Long) systemInfo.findRecursive("jvm", "jmx", "upTimeMS"));
String usedMemory = (String) systemInfo.findRecursive("jvm", "memory", "used");
String totalMemory = (String) systemInfo.findRecursive("jvm", "memory", "total");
uptime =
SolrCLI.uptime((Long) systemInfo._get(List.of("jvm", "jmx", "upTimeMS"), null));
String usedMemory = systemInfo._getStr(List.of("jvm", "memory", "used"), null);
String totalMemory = systemInfo._getStr(List.of("jvm", "memory", "total"), null);
memory = usedMemory + " of " + totalMemory;
}

Expand Down
14 changes: 7 additions & 7 deletions solr/core/src/java/org/apache/solr/cli/StatusTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ public static Map<String, Object> reportStatus(NamedList<Object> info, SolrClien

String solrHome = (String) info.get("solr_home");
status.put("solr_home", solrHome != null ? solrHome : "?");
status.put("version", info.findRecursive("lucene", "solr-impl-version"));
status.put("startTime", info.findRecursive("jvm", "jmx", "startTime").toString());
status.put("uptime", SolrCLI.uptime((Long) info.findRecursive("jvm", "jmx", "upTimeMS")));
status.put("version", info._getStr(List.of("lucene", "solr-impl-version"), null));
status.put("startTime", info._getStr(List.of("jvm", "jmx", "startTime"), null));
status.put("uptime", SolrCLI.uptime((Long) info._get(List.of("jvm", "jmx", "upTimeMS"), null)));

String usedMemory = (String) info.findRecursive("jvm", "memory", "used");
String totalMemory = (String) info.findRecursive("jvm", "memory", "total");
String usedMemory = info._getStr(List.of("jvm", "memory", "used"), null);
String totalMemory = info._getStr(List.of("jvm", "memory", "total"), null);
status.put("memory", usedMemory + " of " + totalMemory);

// if this is a Solr in solrcloud mode, gather some basic cluster info
Expand All @@ -344,11 +344,11 @@ private static Map<String, String> getCloudStatus(SolrClient solrClient, String
// TODO add booleans to request just what we want; not everything
NamedList<Object> json = solrClient.request(new CollectionAdminRequest.ClusterStatus());

List<String> liveNodes = (List<String>) json.findRecursive("cluster", "live_nodes");
List<String> liveNodes = (List<String>) json._get(List.of("cluster", "live_nodes"), null);
cloudStatus.put("liveNodes", String.valueOf(liveNodes.size()));

// TODO get this as a metric from the metrics API instead, or something else.
var collections = (Map<String, Object>) json.findRecursive("cluster", "collections");
var collections = (Map<String, Object>) json._get(List.of("cluster", "collections"), null);
cloudStatus.put("collections", String.valueOf(collections.size()));

return cloudStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,15 @@ public static void checkDiskSpace(
SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params)
.process(cloudManager.getSolrClient());

Number size = (Number) rsp.getResponse().findRecursive("metrics", indexSizeMetricName);
Number size = (Number) rsp.getResponse()._get(List.of("metrics", indexSizeMetricName), null);
if (size == null) {
log.warn("cannot verify information for parent shard leader");
return;
}
double indexSize = size.doubleValue();

Number freeSize = (Number) rsp.getResponse().findRecursive("metrics", freeDiskSpaceMetricName);
Number freeSize =
(Number) rsp.getResponse()._get(List.of("metrics", freeDiskSpaceMetricName), null);
if (freeSize == null) {
log.warn("missing node disk space information for parent shard leader");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,18 @@ private void processComponents(
if (resp == null) {
return false;
}
Object recursive = resp.findRecursive("responseHeader", "partialResults");
Object recursive =
resp._get(List.of("responseHeader", "partialResults"), null);
if (recursive != null) {
Object message =
"[Shard:"
+ response.getShardAddress()
+ "]"
+ resp.findRecursive(
"responseHeader",
RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY);
+ resp._get(
List.of(
"responseHeader",
RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY),
null);
detailMesg.compareAndSet(null, message); // first one, ingore rest
}
return recursive != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public Map<String, SolrPackageInstance> getPackagesDeployedAsClusterLevelPlugins
NamedList<Object> response =
solrClient.request(
new GenericV2SolrRequest(SolrRequest.METHOD.GET, PackageUtils.CLUSTERPROPS_PATH));
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
Integer statusCode = (Integer) response._get(List.of("responseHeader", "status"), null);
if (statusCode == null || statusCode == ErrorCode.NOT_FOUND.code) {
// Cluster props doesn't exist, that means there are no cluster level plugins installed.
result = Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException

cluster.waitForActiveCollection(collectionName, 2, 4);

String nodeName = (String) response._get("success[0]/key", null);
String corename = (String) response._get(asList("success", nodeName, "core"), null);
String nodeName = response._getStr("success[0]/key", null);
String corename = response._getStr(asList("success", nodeName, "core"), null);

try (SolrClient coreClient =
getHttpSolrClient(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
Expand Down Expand Up @@ -620,19 +620,23 @@ public void testColStatus() throws Exception {
CollectionAdminResponse rsp = req.process(cluster.getSolrClient());
assertEquals(0, rsp.getStatus());
assertNotNull(rsp.getResponse().get(collectionName));
assertNotNull(rsp.getResponse().findRecursive(collectionName, "properties"));
assertNotNull(rsp.getResponse()._get(List.of(collectionName, "properties"), null));
final var collPropMap =
(Map<String, Object>) rsp.getResponse().findRecursive(collectionName, "properties");
(Map<String, Object>) rsp.getResponse()._get(List.of(collectionName, "properties"), null);
assertEquals("conf2", collPropMap.get("configName"));
assertEquals(2L, collPropMap.get("nrtReplicas"));
assertEquals("0", collPropMap.get("tlogReplicas"));
assertEquals("0", collPropMap.get("pullReplicas"));
assertEquals(
2, ((NamedList<Object>) rsp.getResponse().findRecursive(collectionName, "shards")).size());
assertNotNull(rsp.getResponse().findRecursive(collectionName, "shards", "shard1", "leader"));
2,
((NamedList<Object>) rsp.getResponse()._get(List.of(collectionName, "shards"), null))
.size());
assertNotNull(
rsp.getResponse()._get(List.of(collectionName, "shards", "shard1", "leader"), null));
// Ensure more advanced info is not returned
assertNull(
rsp.getResponse().findRecursive(collectionName, "shards", "shard1", "leader", "segInfos"));
rsp.getResponse()
._get(List.of(collectionName, "shards", "shard1", "leader", "segInfos"), null));

// Returns segment metadata iff requested
req = CollectionAdminRequest.collectionStatus(collectionName);
Expand Down Expand Up @@ -689,7 +693,7 @@ public void testColStatus() throws Exception {
assertEquals(0, rsp.getStatus());
@SuppressWarnings({"unchecked"})
List<Object> nonCompliant =
(List<Object>) rsp.getResponse().findRecursive(collectionName, "schemaNonCompliant");
(List<Object>) rsp.getResponse()._get(List.of(collectionName, "schemaNonCompliant"), null);
assertEquals(nonCompliant.toString(), 1, nonCompliant.size());
assertTrue(nonCompliant.toString(), nonCompliant.contains("(NONE)"));
@SuppressWarnings({"unchecked"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void testAddDocs() throws Exception {
"Replicas shouldn't process the add document request: " + statsResponse,
((Map<String, Object>)
(statsResponse.getResponse())
.findRecursive("plugins", "UPDATE", "updateHandler", "stats"))
._get(List.of("plugins", "UPDATE", "updateHandler", "stats"), null))
.get("UPDATE.updateHandler.adds"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.util.SecurityJson;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -153,10 +154,9 @@ public void testPKIAuthWorksForPullReplication() throws Exception {

@SuppressWarnings("unchecked")
private Object getUpdateHandlerMetric(QueryResponse statsResponse, String metric) {
NamedList<Object> entries = statsResponse.getResponse();
return ((Map<String, Object>)
statsResponse
.getResponse()
.findRecursive("plugins", "UPDATE", "updateHandler", "stats"))
entries._get(List.of("plugins", "UPDATE", "updateHandler", "stats"), null))
.get(metric);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.common.cloud.LiveNodesPredicate;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.embedded.JettySolrRunner;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -237,15 +238,17 @@ public boolean matches(SortedSet<String> oldLiveNodes, SortedSet<String> newLive
* <p>The update happens in org.apache.solr.cloud.Overseer.ClusterStateUpdater.processQueueItem()
*/
private int getNumLeaderOperations(CollectionAdminResponse resp) {
return (int) resp.getResponse().findRecursive("overseer_operations", "leader", "requests");
NamedList<Object> entries = resp.getResponse();
return (int) entries._get(List.of("overseer_operations", "leader", "requests"), null);
}

/**
* "state" stats are when Overseer processes a {@link
* org.apache.solr.cloud.overseer.OverseerAction#STATE} message that sets replica properties
*/
private int getNumStateOperations(CollectionAdminResponse resp) {
return (int) resp.getResponse().findRecursive("overseer_operations", "state", "requests");
NamedList<Object> entries = resp.getResponse();
return (int) entries._get(List.of("overseer_operations", "state", "requests"), null);
}

private String getOverseerLeader() throws IOException, SolrServerException {
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ public void testAddDocs() throws Exception {
"qt", "/admin/plugins",
"stats", "true");
QueryResponse statsResponse = tlogReplicaClient.query(req);
NamedList<Object> entries = (statsResponse.getResponse());
assertEquals(
"Append replicas should recive all updates. Replica: "
+ r
+ ", response: "
+ statsResponse,
1L,
((Map<String, Object>)
(statsResponse.getResponse())
.findRecursive("plugins", "UPDATE", "updateHandler", "stats"))
entries._get(List.of("plugins", "UPDATE", "updateHandler", "stats"), null))
.get("UPDATE.updateHandler.cumulativeAdds.count"));
break;
} catch (AssertionError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.SolrClient;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void test() {
NamedList<Object> createResponse = null;
try {
createResponse = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
message = (String) createResponse.findRecursive("status", "msg");
message = createResponse._getStr(List.of("status", "msg"), null);
} catch (SolrServerException | IOException e) {
log.error("error sending request", e);
}
Expand Down Expand Up @@ -122,7 +123,7 @@ public void test() {
NamedList<Object> splitResponse = null;
try {
splitResponse = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
message = (String) splitResponse.findRecursive("status", "msg");
message = splitResponse._getStr(List.of("status", "msg"), null);
} catch (SolrServerException | IOException e) {
log.error("error sending request", e);
}
Expand Down Expand Up @@ -154,7 +155,7 @@ public void test() {

try {
NamedList<Object> response = sendStatusRequestWithRetry(params, MAX_WAIT_TIMEOUT_SECONDS);
message = (String) response.findRecursive("status", "msg");
message = response._getStr(List.of("status", "msg"), null);
} catch (SolrServerException | IOException e) {
log.error("error sending request", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public TokenStream create(TokenStream input) {
// just test that we see "900" in the flags attribute here
@SuppressWarnings({"unchecked", "rawtypes"})
List<NamedList> tokenInfoList =
(List<NamedList>) result.findRecursive("index", CustomTokenFilter.class.getName());
(List<NamedList>) result._get(List.of("index", CustomTokenFilter.class.getName()), null);
// '1' from CustomTokenFilter plus 900 from CustomFlagsAttributeImpl.
assertEquals(
901,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.MapWriter;
Expand Down Expand Up @@ -479,7 +480,7 @@ public void testKeyMetrics() throws Exception {
key1),
resp);
NamedList<?> values = resp.getValues();
Object val = values.findRecursive("metrics", key1);
Object val = values._get(List.of("metrics", key1), null);
assertNotNull(val);
assertTrue(val instanceof MapWriter);
assertTrue(((MapWriter) val)._size() >= 2);
Expand Down Expand Up @@ -573,8 +574,8 @@ public void testKeyMetrics() throws Exception {
values = resp.getValues();
NamedList<?> metrics = (NamedList<?>) values.get("metrics");
assertEquals(0, metrics.size());
assertNotNull(values.findRecursive("errors", "foo"));
assertNotNull(values.findRecursive("errors", "foo:bar:baz:xyz"));
assertNotNull(values._get(List.of("errors", "foo"), null));
assertNotNull(values._get(List.of("errors", "foo:bar:baz:xyz"), null));

// unknown registry
resp = new SolrQueryResponse();
Expand All @@ -590,7 +591,7 @@ public void testKeyMetrics() throws Exception {
values = resp.getValues();
metrics = (NamedList<?>) values.get("metrics");
assertEquals(0, metrics.size());
assertNotNull(values.findRecursive("errors", "foo:bar:baz"));
assertNotNull(values._get(List.of("errors", "foo:bar:baz"), null));

// unknown metric
resp = new SolrQueryResponse();
Expand All @@ -606,7 +607,7 @@ public void testKeyMetrics() throws Exception {
values = resp.getValues();
metrics = (NamedList<?>) values.get("metrics");
assertEquals(0, metrics.size());
assertNotNull(values.findRecursive("errors", "solr.jetty:unknown:baz"));
assertNotNull(values._get(List.of("errors", "solr.jetty:unknown:baz"), null));

handler.close();
}
Expand All @@ -628,9 +629,9 @@ public void testExprMetrics() throws Exception {
key1),
resp);
// response structure is like in the case of non-key params
Object val =
resp.getValues()
.findRecursive("metrics", "solr.core.collection1", "QUERY./select.requestTimes");
Object val =
resp.getValues()._get(
List.of("metrics", "solr.core.collection1", "QUERY./select.requestTimes"), null);
assertNotNull(val);
assertTrue(val instanceof MapWriter);
Map<String, Object> map = new HashMap<>();
Expand All @@ -655,7 +656,7 @@ public void testExprMetrics() throws Exception {
key2),
resp);
// response structure is like in the case of non-key params
val = resp.getValues().findRecursive("metrics", "solr.core.collection1");
val = resp.getValues()._get(List.of("metrics", "solr.core.collection1"), null);
assertNotNull(val);
Object v = ((SimpleOrderedMap<Object>) val).get("QUERY./select.requestTimes");
assertNotNull(v);
Expand Down Expand Up @@ -689,7 +690,7 @@ public void testExprMetrics() throws Exception {
MetricsHandler.EXPR_PARAM,
key3),
resp);
val = resp.getValues().findRecursive("metrics", "solr.core.collection1");
val = resp.getValues()._get(List.of("metrics", "solr.core.collection1"), null);
assertNotNull(val);
// for requestTimes only the full set of values from the first expr should be present
assertNotNull(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void validateControlData(QueryResponse control) {
NamedList<Object> nl = control.getResponse();

Object explicitNumSuggestExpected =
nl.findRecursive("responseHeader", "params", "test.expected.suggestions");
nl._get(List.of("responseHeader", "params", "test.expected.suggestions"), null);

@SuppressWarnings("unchecked")
NamedList<Object> sc = (NamedList<Object>) nl.get("spellcheck");
Expand Down
Loading
Loading