chatman commented on a change in pull request #403:
URL: https://github.com/apache/solr/pull/403#discussion_r779829825
##########
File path: solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
##########
@@ -57,92 +64,194 @@
import static
org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
import static
org.apache.solr.security.PermissionNameProvider.Name.CONFIG_READ_PERM;
-/** All V2 APIs that have a prefix of /api/cluster/
- *
+/**
+ * All V2 APIs that have a prefix of /api/cluster/
*/
public class ClusterAPI {
private final CollectionsHandler collectionsHandler;
private final ConfigSetsHandler configSetsHandler;
- public final Commands commands = new Commands();
- public final ConfigSetCommands configSetCommands = new ConfigSetCommands();
+ public final Commands commands = new Commands();
+ public final ConfigSetCommands configSetCommands = new ConfigSetCommands();
public ClusterAPI(CollectionsHandler ch, ConfigSetsHandler
configSetsHandler) {
this.collectionsHandler = ch;
this.configSetsHandler = configSetsHandler;
}
+ private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @EndPoint(method = GET,
+ path = "/cluster/node-roles",
+ permission = COLL_READ_PERM)
+ public void roles(SolrQueryRequest req, SolrQueryResponse rsp) throws
Exception {
+ Map<String, Object> result = new LinkedHashMap<>();
+
+ 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 = null;
+ try {
+ List<String> children = zk.listData(path);
+ if (children != null && !children.isEmpty()) {
+ result = new HashMap<>();
+ } else {
+ return depth >= 1 ? Collections.emptyList() : null;
+ }
+ 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;
+ }
+ }
+
+ @EndPoint(method = GET,
+ path = "/cluster/node-roles/role/{role}",
+ permission = COLL_READ_PERM)
+ public void nodesWithRole(SolrQueryRequest req, SolrQueryResponse rsp)
throws Exception {
+ String role = req.getPathTemplateValues().get("role");
+ rsp.add("node-roles", Map.of(role,
+ readRecursive(ZkStateReader.NODE_ROLES + "/"+ role,
+
collectionsHandler.getCoreContainer().getZkController().getSolrCloudManager().getDistribStateManager(),
2)));
+ }
+
+ @EndPoint(method = GET,
+ path = "/cluster/node-roles/node/{node}",
+ permission = COLL_READ_PERM)
+ @SuppressWarnings("unchecked")
+ public void rolesForNode(SolrQueryRequest req, SolrQueryResponse rsp) throws
Exception {
+ String node = req.getPathTemplateValues().get("node");
+ Map<String, String> ret = new HashMap<String, String>();
+ Map<String, Map<String, Set<String>>> roles = (Map<String, Map<String,
Set<String>>>) readRecursive(ZkStateReader.NODE_ROLES,
+
collectionsHandler.getCoreContainer().getZkController().getSolrCloudManager().getDistribStateManager(),
3);
+ for (String role: roles.keySet()) {
+ for (String mode : roles.get(role).keySet()) {
+ if (roles.get(role).get(mode) instanceof List && ((List)
roles.get(role).get(mode)).size() == 0) {
+ continue;
+ }
+ Set<String> nodes = roles.get(role).get(mode);
+ if (nodes.contains(node)) ret.put(role, mode);
+ }
+ }
+ for (String role: ret.keySet()) {
+ rsp.add(role, ret.get(role));
+ }
+ }
+
@EndPoint(method = GET,
- path = "/cluster/aliases",
- permission = COLL_READ_PERM)
+ path = "/cluster/node-roles/supported",
+ permission = COLL_READ_PERM)
+ public void supportedRoles(SolrQueryRequest req, SolrQueryResponse rsp)
throws Exception {
+ Map<String, Object> roleModesSupportedMap = new HashMap<>();
+ for (NodeRoles.Role role: NodeRoles.Role.values()) {
+ roleModesSupportedMap.put(role.toString(), Map.of("modes",
role.supportedModes(), "defaultIfAbsent", role.defaultIfAbsent()));
Review comment:
Removed this "defaultIfAbsent" from this API response. Renamed it to
"modeWhenRoleIsAbsent" internally. For the user, there is no role-specific
"default" to consider, everything is to be explicitly specified.
--
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]