Skip to content

Commit 51841d7

Browse files
authored
SOLR-17625: NamedList.findRecursive -> _get (#3355)
Replaced NamedList.findRecursive usages with _get, which can do Map traversal, and thus makes it easier to transition intermediate NamedLists to Maps.
1 parent e714925 commit 51841d7

25 files changed

+98
-75
lines changed

solr/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ Other Changes
342342

343343
* SOLR-17651: Add System.exit() in forbidden APIs, and make sure CLI unit tests never call it. (Pierre Salagnac)
344344

345+
* SOLR-17625: Replaced NamedList.findRecursive usages with _get, which can do Map traversal, and
346+
thus makes it easier to transition intermediate NamedLists to Maps. (Gaurav Tuli)
347+
345348
================== 9.8.1 ==================
346349
Bug Fixes
347350
---------------------

solr/core/src/java/org/apache/solr/cli/AssertTool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.file.Files;
2222
import java.nio.file.Path;
2323
import java.nio.file.attribute.FileOwnerAttributeView;
24+
import java.util.List;
2425
import java.util.concurrent.TimeUnit;
2526
import org.apache.commons.cli.CommandLine;
2627
import org.apache.commons.cli.Option;
@@ -280,7 +281,7 @@ public int assertSolrNotRunning(String url, String credentials) throws Exception
280281
System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutMs, TimeUnit.MILLISECONDS);
281282
try (SolrClient solrClient = CLIUtils.getSolrClient(url, credentials)) {
282283
NamedList<Object> response = solrClient.request(new HealthCheckRequest());
283-
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
284+
Integer statusCode = (Integer) response._get(List.of("responseHeader", "status"), null);
284285
CLIUtils.checkCodeForAuthError(statusCode);
285286
} catch (IOException | SolrServerException e) {
286287
log.debug("Opening connection to {} failed, Solr does not seem to be running", url, e);

solr/core/src/java/org/apache/solr/cli/ConfigTool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.solr.cli;
1919

2020
import java.util.HashMap;
21+
import java.util.List;
2122
import java.util.Map;
2223
import org.apache.commons.cli.CommandLine;
2324
import org.apache.commons.cli.MissingArgumentException;
@@ -124,7 +125,7 @@ public void runImpl(CommandLine cli) throws Exception {
124125
try (SolrClient solrClient =
125126
CLIUtils.getSolrClient(solrUrl, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) {
126127
NamedList<Object> result = SolrCLI.postJsonToSolr(solrClient, updatePath, jsonBody);
127-
Integer statusCode = (Integer) result.findRecursive("responseHeader", "status");
128+
Integer statusCode = (Integer) result._get(List.of("responseHeader", "status"), null);
128129
if (statusCode == 0) {
129130
if (value != null) {
130131
echo("Successfully " + action + " " + property + " to " + value);

solr/core/src/java/org/apache/solr/cli/HealthcheckTool.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) th
173173
solrClient.request(
174174
new GenericSolrRequest(
175175
SolrRequest.METHOD.GET, CommonParams.SYSTEM_INFO_PATH));
176-
uptime = SolrCLI.uptime((Long) systemInfo.findRecursive("jvm", "jmx", "upTimeMS"));
177-
String usedMemory = (String) systemInfo.findRecursive("jvm", "memory", "used");
178-
String totalMemory = (String) systemInfo.findRecursive("jvm", "memory", "total");
176+
uptime =
177+
SolrCLI.uptime((Long) systemInfo._get(List.of("jvm", "jmx", "upTimeMS"), null));
178+
String usedMemory = systemInfo._getStr(List.of("jvm", "memory", "used"), null);
179+
String totalMemory = systemInfo._getStr(List.of("jvm", "memory", "total"), null);
179180
memory = usedMemory + " of " + totalMemory;
180181
}
181182

solr/core/src/java/org/apache/solr/cli/StatusTool.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,12 @@ public static Map<String, Object> reportStatus(NamedList<Object> info, SolrClien
314314

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

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

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

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

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

354354
return cloudStatus;

solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,14 +862,15 @@ public static void checkDiskSpace(
862862
SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params)
863863
.process(cloudManager.getSolrClient());
864864

865-
Number size = (Number) rsp.getResponse().findRecursive("metrics", indexSizeMetricName);
865+
Number size = (Number) rsp.getResponse()._get(List.of("metrics", indexSizeMetricName), null);
866866
if (size == null) {
867867
log.warn("cannot verify information for parent shard leader");
868868
return;
869869
}
870870
double indexSize = size.doubleValue();
871871

872-
Number freeSize = (Number) rsp.getResponse().findRecursive("metrics", freeDiskSpaceMetricName);
872+
Number freeSize =
873+
(Number) rsp.getResponse()._get(List.of("metrics", freeDiskSpaceMetricName), null);
873874
if (freeSize == null) {
874875
log.warn("missing node disk space information for parent shard leader");
875876
return;

solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,18 @@ private void processComponents(
609609
if (resp == null) {
610610
return false;
611611
}
612-
Object recursive = resp.findRecursive("responseHeader", "partialResults");
612+
Object recursive =
613+
resp._get(List.of("responseHeader", "partialResults"), null);
613614
if (recursive != null) {
614615
Object message =
615616
"[Shard:"
616617
+ response.getShardAddress()
617618
+ "]"
618-
+ resp.findRecursive(
619-
"responseHeader",
620-
RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY);
619+
+ resp._get(
620+
List.of(
621+
"responseHeader",
622+
RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY),
623+
null);
621624
detailMesg.compareAndSet(null, message); // first one, ingore rest
622625
}
623626
return recursive != null;

solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public Map<String, SolrPackageInstance> getPackagesDeployedAsClusterLevelPlugins
284284
NamedList<Object> response =
285285
solrClient.request(
286286
new GenericV2SolrRequest(SolrRequest.METHOD.GET, PackageUtils.CLUSTERPROPS_PATH));
287-
Integer statusCode = (Integer) response.findRecursive("responseHeader", "status");
287+
Integer statusCode = (Integer) response._get(List.of("responseHeader", "status"), null);
288288
if (statusCode == null || statusCode == ErrorCode.NOT_FOUND.code) {
289289
// Cluster props doesn't exist, that means there are no cluster level plugins installed.
290290
result = Collections.emptyMap();

solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException
287287

288288
cluster.waitForActiveCollection(collectionName, 2, 4);
289289

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

293293
try (SolrClient coreClient =
294294
getHttpSolrClient(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
@@ -620,19 +620,23 @@ public void testColStatus() throws Exception {
620620
CollectionAdminResponse rsp = req.process(cluster.getSolrClient());
621621
assertEquals(0, rsp.getStatus());
622622
assertNotNull(rsp.getResponse().get(collectionName));
623-
assertNotNull(rsp.getResponse().findRecursive(collectionName, "properties"));
623+
assertNotNull(rsp.getResponse()._get(List.of(collectionName, "properties"), null));
624624
final var collPropMap =
625-
(Map<String, Object>) rsp.getResponse().findRecursive(collectionName, "properties");
625+
(Map<String, Object>) rsp.getResponse()._get(List.of(collectionName, "properties"), null);
626626
assertEquals("conf2", collPropMap.get("configName"));
627627
assertEquals(2L, collPropMap.get("nrtReplicas"));
628628
assertEquals("0", collPropMap.get("tlogReplicas"));
629629
assertEquals("0", collPropMap.get("pullReplicas"));
630630
assertEquals(
631-
2, ((NamedList<Object>) rsp.getResponse().findRecursive(collectionName, "shards")).size());
632-
assertNotNull(rsp.getResponse().findRecursive(collectionName, "shards", "shard1", "leader"));
631+
2,
632+
((NamedList<Object>) rsp.getResponse()._get(List.of(collectionName, "shards"), null))
633+
.size());
634+
assertNotNull(
635+
rsp.getResponse()._get(List.of(collectionName, "shards", "shard1", "leader"), null));
633636
// Ensure more advanced info is not returned
634637
assertNull(
635-
rsp.getResponse().findRecursive(collectionName, "shards", "shard1", "leader", "segInfos"));
638+
rsp.getResponse()
639+
._get(List.of(collectionName, "shards", "shard1", "leader", "segInfos"), null));
636640

637641
// Returns segment metadata iff requested
638642
req = CollectionAdminRequest.collectionStatus(collectionName);
@@ -689,7 +693,7 @@ public void testColStatus() throws Exception {
689693
assertEquals(0, rsp.getStatus());
690694
@SuppressWarnings({"unchecked"})
691695
List<Object> nonCompliant =
692-
(List<Object>) rsp.getResponse().findRecursive(collectionName, "schemaNonCompliant");
696+
(List<Object>) rsp.getResponse()._get(List.of(collectionName, "schemaNonCompliant"), null);
693697
assertEquals(nonCompliant.toString(), 1, nonCompliant.size());
694698
assertTrue(nonCompliant.toString(), nonCompliant.contains("(NONE)"));
695699
@SuppressWarnings({"unchecked"})

solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void testAddDocs() throws Exception {
319319
"Replicas shouldn't process the add document request: " + statsResponse,
320320
((Map<String, Object>)
321321
(statsResponse.getResponse())
322-
.findRecursive("plugins", "UPDATE", "updateHandler", "stats"))
322+
._get(List.of("plugins", "UPDATE", "updateHandler", "stats"), null))
323323
.get("UPDATE.updateHandler.adds"));
324324
}
325325
}

0 commit comments

Comments
 (0)