[
https://issues.apache.org/jira/browse/SOLR-17256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17932577#comment-17932577
]
Sanjay Dutt edited comment on SOLR-17256 at 3/5/25 10:18 AM:
-------------------------------------------------------------
Is there any easier way to get preferred nodes than this.
{code:java}
@EndPoint(method = GET, path = "/cluster/node-roles", permission =
COLL_READ_PERM)
public void roles(SolrQueryRequest req, SolrQueryResponse rsp) throws
Exception {
rsp.add(
"node-roles",
readRecursive(
ZkStateReader.NODE_ROLES,
collectionsHandler
.getCoreContainer()
.getZkController()
.getSolrCloudManager()
.getDistribStateManager(),
3));
} Object readRecursive(String path, DistribStateManager zk, int depth) {
if (depth == 0) return null;
Map<String, Object> result;
try {
List<String> children = zk.listData(path);
if (children != null && !children.isEmpty()) {
result = new HashMap<>();
} else {
return Collections.emptySet();
}
for (String child : children) {
Object c = readRecursive(path + "/" + child, zk, depth - 1);
result.put(child, c);
}
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
if (depth == 1) {
return result.keySet();
} else {
return result;
}
}{code}
was (Author: JIRAUSER305513):
Is there any easier way to get preferred nodes then this.
{code:java}
@EndPoint(method = GET, path = "/cluster/node-roles", permission =
COLL_READ_PERM)
public void roles(SolrQueryRequest req, SolrQueryResponse rsp) throws
Exception {
rsp.add(
"node-roles",
readRecursive(
ZkStateReader.NODE_ROLES,
collectionsHandler
.getCoreContainer()
.getZkController()
.getSolrCloudManager()
.getDistribStateManager(),
3));
} Object readRecursive(String path, DistribStateManager zk, int depth) {
if (depth == 0) return null;
Map<String, Object> result;
try {
List<String> children = zk.listData(path);
if (children != null && !children.isEmpty()) {
result = new HashMap<>();
} else {
return Collections.emptySet();
}
for (String child : children) {
Object c = readRecursive(path + "/" + child, zk, depth - 1);
result.put(child, c);
}
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
if (depth == 1) {
return result.keySet();
} else {
return result;
}
}{code}
> Remove SolrRequest.getBasePath setBasePath
> ------------------------------------------
>
> Key: SOLR-17256
> URL: https://issues.apache.org/jira/browse/SOLR-17256
> Project: Solr
> Issue Type: Improvement
> Components: SolrJ
> Reporter: David Smiley
> Assignee: Jason Gerlowski
> Priority: Minor
> Labels: newdev, pull-request-available
> Fix For: main (10.0), 9.7
>
> Time Spent: 5h 40m
> Remaining Estimate: 0h
>
> SolrRequest has a getBasePath & setBasePath. The naming is poor; it's the
> URL base to the Solr node like "http://localhost:8983/solr". It's only
> recognized by HttpSolrClient; LBSolrClient (used by CloudSolrClient) ignores
> it and will in fact mutate the passed in request to its liking, which is
> rather ugly because it means a request cannot be used concurrently if the
> user wants to. But moreover I think there's a conceptual discordance of
> placing this concept on SolrRequest given that some clients want to route
> requests to nodes *they* choose. I propose removing this from SolrRequest
> and instead adding a method specific to HttpSolrClient. Almost all existing
> usages of setBasePath immediately execute the request on an HttpSolrClient,
> so should be easy to change.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]