iprithv commented on code in PR #4952: URL: https://github.com/apache/solr/pull/4952#discussion_r4139194766
########## solr/core/src/test/org/apache/solr/handler/admin/api/GetClusterStatusTest.java: ########## @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.admin.api; + +import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.solr.client.api.model.GetClusterStatusResponse; +import org.apache.solr.client.api.model.GetClusterStatusResponse.CollectionState; +import org.apache.solr.client.api.model.GetClusterStatusResponse.ReplicaState; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; +import org.apache.solr.client.solrj.request.ClusterApi; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.Utils; +import org.eclipse.jetty.client.ContentResponse; +import org.eclipse.jetty.client.HttpClient; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * HTTP tests for {@code GET /api/cluster}. + * + * <p>The response is the collections, shards, and replicas tree. Live nodes, the alias map, and + * cluster properties stay on their own endpoints. v1 {@code CLUSTERSTATUS} still returns them. + */ +public class GetClusterStatusTest extends SolrCloudTestCase { + + private static final String COLLECTION = "clusterstatuscoll"; + private static final String ALIAS = "clusterstatusalias"; + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(1).addConfig("conf", configset("cloud-minimal")).configure(); + CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1) + .process(cluster.getSolrClient()); + CollectionAdminRequest.createAlias(ALIAS, COLLECTION).process(cluster.getSolrClient()); + } + + @Test + public void testReturnsCollectionTreeWithoutClusterLevelExtras() throws Exception { + Map<String, Object> clusterState = clusterObject(getCluster("")); + assertNull(clusterState.get("live_nodes")); + assertNull(clusterState.get("aliases")); + assertNull(clusterState.get("properties")); + + Map<String, Object> collection = collection(clusterState, COLLECTION); + assertNotNull(collection.get("health")); + assertEquals("conf", collection.get("configName")); + assertNotNull(collection.get("router")); + assertEquals(Set.of("shard1"), shards(collection).keySet()); + assertNotNull(replica(collection).get("node_name")); + assertNotNull(replica(collection).get("state")); + assertTrue(aliasesOf(collection).contains(ALIAS)); + } + + @Test + @SuppressWarnings("unchecked") + public void testGeneratedClientReadsTheTree() throws Exception { + GetClusterStatusResponse response = + new ClusterApi.GetClusterStatus().process(cluster.getSolrClient()); + assertNull(response.error); + CollectionState collection = response.cluster.collections.get(COLLECTION); + assertNotNull(collection); + assertEquals("conf", collection.configName); + assertNotNull(collection.health); + assertTrue(collection.aliases.contains(ALIAS)); + Map<String, Object> router = (Map<String, Object>) collection.unknownProperties().get("router"); + assertEquals("compositeId", router.get("name")); + + ReplicaState replica = collection.shards.get("shard1").replicas.values().iterator().next(); + assertNotNull(replica.nodeName); + assertNotNull(replica.state); + assertEquals("true", replica.leader); + } + + @Test + public void testV1SelectionParamsAreIgnored() throws Exception { + Map<String, Object> clusterState = + clusterObject( + getCluster("?liveNodes=true&aliases=true&clusterProperties=true&includeAll=true")); + assertNull(clusterState.get("live_nodes")); Review Comment: yes, we ignore... undeclared query params don’t bind on the jax-rs method, and we don’t read them from the raw request either. jersey’s usual default is to ignore unknown query params; blowing up would need an explicit policy (bean validation / filter) across v2. -- 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]
