dsmiley commented on code in PR #2599:
URL: https://github.com/apache/solr/pull/2599#discussion_r1704589925


##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -89,14 +93,61 @@ public static Health combine(Collection<Health> states) {
     }
   }
 
-  public ClusterStatus(ZkStateReader zkStateReader, ZkNodeProps props) {
+  public ClusterStatus(ZkStateReader zkStateReader, SolrParams params) {
     this.zkStateReader = zkStateReader;
-    this.message = props;
-    collection = props.getStr(ZkStateReader.COLLECTION_PROP);
+    this.solrParams = params;
+    collection = params.get(ZkStateReader.COLLECTION_PROP);
   }
 
   public void getClusterStatus(NamedList<Object> results)
       throws KeeperException, InterruptedException {
+    List<String> liveNodes = null;
+    NamedList<Object> clusterStatus = new SimpleOrderedMap<>();
+
+    boolean includeAll = this.solrParams.getBool(INCLUDE_ALL, true);
+    boolean withLiveNodes =
+        this.solrParams.getBool(LIVENODES_PROP, includeAll) || (collection != 
null);

Review Comment:
   why compare with collection here?



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -34,19 +34,23 @@
 import org.apache.solr.common.cloud.PerReplicaStates;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.ShardParams;
+import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.common.util.Utils;
 import org.apache.zookeeper.KeeperException;
 
 public class ClusterStatus {
   private final ZkStateReader zkStateReader;
-  private final ZkNodeProps message;
+  private SolrParams solrParams;

Review Comment:
   not final?



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -89,14 +93,61 @@ public static Health combine(Collection<Health> states) {
     }
   }
 
-  public ClusterStatus(ZkStateReader zkStateReader, ZkNodeProps props) {
+  public ClusterStatus(ZkStateReader zkStateReader, SolrParams params) {
     this.zkStateReader = zkStateReader;
-    this.message = props;
-    collection = props.getStr(ZkStateReader.COLLECTION_PROP);
+    this.solrParams = params;
+    collection = params.get(ZkStateReader.COLLECTION_PROP);
   }
 
   public void getClusterStatus(NamedList<Object> results)
       throws KeeperException, InterruptedException {
+    List<String> liveNodes = null;

Review Comment:
   why define this up top?



##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java:
##########
@@ -88,6 +88,9 @@ public class ZkStateReader implements SolrCloseable {
   public static final String CORE_NAME_PROP = "core";
 
   public static final String COLLECTION_PROP = "collection";
+  public static final String INCLUDE_ALL = "includeAll";
+  public static final String LIVENODES_PROP = "liveNodes";
+  public static final String CLUSTER_PROP = "clusterProperties";

Review Comment:
   they are still here.



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -191,43 +236,23 @@ public void getClusterStatus(NamedList<Object> results)
       }
       String configName = clusterStateCollection.getConfigName();
       collectionStatus.put("configName", configName);
-      if (message.getBool("prs", false) && 
clusterStateCollection.isPerReplicaState()) {
+      if (this.solrParams.getBool("prs", false) && 
clusterStateCollection.isPerReplicaState()) {

Review Comment:
   nitpick: I'd remove "this."



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -96,39 +96,43 @@ public static Health combine(Collection<Health> states) {
   public ClusterStatus(ZkStateReader zkStateReader, ZkNodeProps props) {
     this.zkStateReader = zkStateReader;
     this.message = props;
-    collectionParam = props.getStr(ZkStateReader.COLLECTION_PROP);
-    liveNodesParam = props.getBool(ZkStateReader.LIVENODES_PROP, false);
-    clusterPropertiesParam = props.getBool(ZkStateReader.CLUSTER_PROP, false);
-    rolesParam = props.getBool(ZkStateReader.ROLES_PROP, false);
-    includeAll = props.getBool(ZkStateReader.INCLUDE_ALL, true);
+    collection = props.getStr(ZkStateReader.COLLECTION_PROP);
   }
 
   public void getClusterStatus(NamedList<Object> results)
       throws KeeperException, InterruptedException {
-
     List<String> liveNodes = null;
     NamedList<Object> clusterStatus = new SimpleOrderedMap<>();
-    if (includeAll || collectionParam != null || liveNodesParam) {
+
+    boolean includeAll = this.message.getBool(INCLUDE_ALL, true);
+    boolean withLiveNodes =
+        this.message.getBool(LIVENODES_PROP, includeAll) || (collection != 
null);
+    boolean withClusterProperties = this.message.getBool(CLUSTER_PROP, 
includeAll);
+    boolean withRoles = this.message.getBool(ZkStateReader.ROLES_PROP, 
includeAll);
+    boolean withCollection = includeAll || (collection != null);
+
+    if (withLiveNodes) {
       liveNodes =
           
zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, 
true);
       // add live_nodes
       clusterStatus.add("live_nodes", liveNodes);
     }
-
-    if (includeAll || collectionParam != null)
+    if (withCollection) {
       fetchClusterStatusForCollOrAlias(clusterStatus, liveNodes);
+    }
 
-    if (includeAll || clusterPropertiesParam) {
+    Map<String, Object> clusterProps = Collections.emptyMap();
+    if (withClusterProperties) {
       // read cluster properties
-      Map<String, Object> clusterProps = zkStateReader.getClusterProperties();
-      if (clusterProps != null && !clusterProps.isEmpty()) {
-        clusterStatus.add("properties", clusterProps);
+      clusterProps = zkStateReader.getClusterProperties();
+      if (clusterProps == null || clusterProps.isEmpty()) {
+        clusterProps = Collections.emptyMap();
       }
     }
+    clusterStatus.add("properties", clusterProps);

Review Comment:
   (I don't see it)



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -89,14 +93,61 @@ public static Health combine(Collection<Health> states) {
     }
   }
 
-  public ClusterStatus(ZkStateReader zkStateReader, ZkNodeProps props) {
+  public ClusterStatus(ZkStateReader zkStateReader, SolrParams params) {
     this.zkStateReader = zkStateReader;
-    this.message = props;
-    collection = props.getStr(ZkStateReader.COLLECTION_PROP);
+    this.solrParams = params;
+    collection = params.get(ZkStateReader.COLLECTION_PROP);
   }
 
   public void getClusterStatus(NamedList<Object> results)
       throws KeeperException, InterruptedException {
+    List<String> liveNodes = null;
+    NamedList<Object> clusterStatus = new SimpleOrderedMap<>();
+
+    boolean includeAll = this.solrParams.getBool(INCLUDE_ALL, true);
+    boolean withLiveNodes =
+        this.solrParams.getBool(LIVENODES_PROP, includeAll) || (collection != 
null);
+    boolean withClusterProperties = this.solrParams.getBool(CLUSTER_PROP, 
includeAll);
+    boolean withRoles = this.solrParams.getBool(ZkStateReader.ROLES_PROP, 
includeAll);
+    boolean withCollection = includeAll || (collection != null);
+
+    if (withLiveNodes) {
+      liveNodes =
+          
zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, 
true);
+      // add live_nodes
+      clusterStatus.add("live_nodes", liveNodes);
+    }
+    if (withCollection) {
+      fetchClusterStatusForCollOrAlias(clusterStatus, liveNodes);
+    }
+
+    Map<String, Object> clusterProps = Collections.emptyMap();
+    if (withClusterProperties) {
+      // read cluster properties
+      clusterProps = zkStateReader.getClusterProperties();
+      if (clusterProps == null || clusterProps.isEmpty()) {
+        clusterProps = Collections.emptyMap();
+      }
+    }
+    clusterStatus.add("properties", clusterProps);
+
+    // add the roles map
+    Map<?, ?> roles = Collections.emptyMap();
+    if (withRoles) {
+      if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES, true)) {
+        roles =
+            (Map<?, ?>)
+                Utils.fromJSON(
+                    zkStateReader.getZkClient().getData(ZkStateReader.ROLES, 
null, null, true));
+      }
+    }
+    clusterStatus.add("roles", roles);

Review Comment:
   don't add unless `withRoles`



##########
solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java:
##########
@@ -97,20 +97,20 @@ public void testHttpClusterStateWithSSL() throws Exception {
             .build()) {
       ClusterStateProvider csp = http2BasedClient.getClusterStateProvider();
       assertTrue(csp instanceof Http2ClusterStateProvider);
-      verifyUrlSchemeInClusterState(csp.getClusterState(), collectionId, 
expectedReplicas);
+      verifyUrlSchemeInClusterState(
+          csp.getCollection(collectionId), collectionId, expectedReplicas);
     }
 
     // Zk cluster state now
     ClusterStateProvider csp = 
cluster.getSolrClient().getClusterStateProvider();
     assertTrue(csp instanceof ZkClientClusterStateProvider);
-    verifyUrlSchemeInClusterState(csp.getClusterState(), collectionId, 
expectedReplicas);
+    verifyUrlSchemeInClusterState(csp.getCollection(collectionId), 
collectionId, expectedReplicas);
   }
 
   private void verifyUrlSchemeInClusterState(
-      final ClusterState cs, final String collectionId, final int 
expectedReplicas) {
-    DocCollection dc = cs.getCollection(collectionId);
-    assertNotNull(dc);
-    List<Replica> replicas = dc.getReplicas();
+      final DocCollection collection, final String collectionId, final int 
expectedReplicas) {

Review Comment:
   why pass both DocCollection and it's name (collectionId)?



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseHttpClusterStateProvider.java:
##########
@@ -413,4 +412,11 @@ public String getQuorumHosts() {
     }
     return String.join(",", this.liveNodes);
   }
+
+  public enum ClusterStateRequestType {

Review Comment:
   (waiting)



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -147,6 +191,7 @@ public void getClusterStatus(NamedList<Object> results)
 
     NamedList<Object> collectionProps = new SimpleOrderedMap<>();
 
+    // loop will run only once

Review Comment:
   Why is that?



##########
solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java:
##########
@@ -139,6 +184,7 @@ public void getClusterStatus(NamedList<Object> results)
     if (didNotFindCollection && isAlias) {
       // In this case this.collection is an alias name not a collection
       // get all collections and filter out collections not in the alias
+      // clusterState.getCollectionsMap() should be replaced with an 
inexpensive call

Review Comment:
   (waiting)



##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/ClusterStateProvider.java:
##########
@@ -108,8 +112,7 @@ default DocCollection getCollection(String name) throws 
IOException {
   /** Obtain a cluster property, or the default value if it doesn't exist. */
   default <T> T getClusterProperty(String key, T defaultValue) {
     @SuppressWarnings({"unchecked"})
-    T value = (T) getClusterProperties().get(key);
-    if (value == null) return defaultValue;
+    T value = (T) getClusterProperties().getOrDefault(key, defaultValue);
     return value;

Review Comment:
   (waiting)



-- 
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]

Reply via email to