dsmiley commented on code in PR #2912: URL: https://github.com/apache/solr/pull/2912#discussion_r1888865754
########## solr/api/src/java/org/apache/solr/client/api/model/CollectionStatusResponse.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.client.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Map; + +/** Response of the CollectionStatusApi.getCollectionStatus() API */ +public class CollectionStatusResponse extends SolrJerseyResponse { + + @JsonProperty public String name; + @JsonProperty public Integer znodeVersion; + @JsonProperty public Long creationTimeMillis; + @JsonProperty public CollectionMetadata properties; + @JsonProperty public Integer activeShards; + @JsonProperty public Integer inactiveShards; + @JsonProperty public List<String> schemaNonCompliant; + + @JsonProperty public Map<String, ShardMetadata> shards; + + // Always present in response + public static class CollectionMetadata { + @JsonProperty public String configName; + @JsonProperty public Integer nrtReplicas; + @JsonProperty public Integer pullReplicas; + @JsonProperty public Integer tlogReplicas; + @JsonProperty public Map<String, String> router; + @JsonProperty public Integer replicationFactor; + } + + // Always present in response + public static class ShardMetadata { + @JsonProperty public String state; // TODO Make this an enum? + @JsonProperty public String range; + @JsonProperty public ReplicaSummary replicas; + @JsonProperty public LeaderSummary leader; + } + + // ALways present in response + public static class ReplicaSummary { + @JsonProperty public Integer total; + @JsonProperty public Integer active; + @JsonProperty public Integer down; + @JsonProperty public Integer recovering; + + @JsonProperty("recovery_failed") + public Integer recoveryFailed; + } + + // Always present in response unless otherwise specified + public static class LeaderSummary { + @JsonProperty public String coreNode; + @JsonProperty public String core; + @JsonProperty public Boolean leader; + + @JsonProperty("node_name") + public String nodeName; + + @JsonProperty("base_url") + public String baseUrl; + + @JsonProperty public String state; // TODO Make this an enum? + @JsonProperty public String type; // TODO Make this an enum? + + @JsonProperty("force_set_state") + public Boolean forceSetState; + + // Present with coreInfo=true || sizeInfo=true unless otherwise specified + @JsonProperty public SegmentInfo segInfos; + } + + // Present with coreInfo=true || sizeInfo=true unless otherwise specified + public static class SegmentInfo { + // Present with coreInfo=true || sizeInfo=true unless otherwise specified + @JsonProperty public SegmentSummary info; + + // Present with rawSize=true + @JsonProperty public RawSize rawSize; + + // Present with fieldInfo=true....this seems pretty useless in isolation? Is it maybe a bad + // param name? + @JsonProperty public List<String> fieldInfoLegend; + } + + // Present with rawSize=true unless otherwise specified + public static class RawSize { + @JsonProperty public Map<String, String> fieldsBySize; + @JsonProperty public Map<String, String> typesBySize; + + // Present with rawSizeDetails=true + @JsonProperty public Object details; + + // Present with rawSizeSummary=true + @JsonProperty public Map<String, Object> summary; + } + + // Present with coreInfo=true || sizeInfo=true unless otherwise specified + public static class SegmentSummary { + @JsonProperty public String minSegmentLuceneVersion; + @JsonProperty public String commitLuceneVersion; + @JsonProperty public Integer numSegments; + @JsonProperty public String segmentsFileName; + @JsonProperty public Integer totalMaxDoc; + + @JsonProperty + public Map<String, String> + userData; // Typically keys are 'commitCommandVer' and 'commitTimeMSec' Review Comment: nit: comment at EOL is awkward for the line wrap; maybe just put before instead. Or leave as-is of course :-) ########## solr/api/src/java/org/apache/solr/client/api/model/CollectionStatusResponse.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.client.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Map; + +/** Response of the CollectionStatusApi.getCollectionStatus() API */ +public class CollectionStatusResponse extends SolrJerseyResponse { + + @JsonProperty public String name; + @JsonProperty public Integer znodeVersion; + @JsonProperty public Long creationTimeMillis; + @JsonProperty public CollectionMetadata properties; + @JsonProperty public Integer activeShards; + @JsonProperty public Integer inactiveShards; + @JsonProperty public List<String> schemaNonCompliant; + + @JsonProperty public Map<String, ShardMetadata> shards; + + // Always present in response + public static class CollectionMetadata { + @JsonProperty public String configName; + @JsonProperty public Integer nrtReplicas; + @JsonProperty public Integer pullReplicas; + @JsonProperty public Integer tlogReplicas; + @JsonProperty public Map<String, String> router; + @JsonProperty public Integer replicationFactor; + } + + // Always present in response + public static class ShardMetadata { + @JsonProperty public String state; // TODO Make this an enum? + @JsonProperty public String range; + @JsonProperty public ReplicaSummary replicas; + @JsonProperty public LeaderSummary leader; + } + + // ALways present in response + public static class ReplicaSummary { + @JsonProperty public Integer total; + @JsonProperty public Integer active; + @JsonProperty public Integer down; + @JsonProperty public Integer recovering; + + @JsonProperty("recovery_failed") + public Integer recoveryFailed; + } + + // Always present in response unless otherwise specified + public static class LeaderSummary { + @JsonProperty public String coreNode; + @JsonProperty public String core; + @JsonProperty public Boolean leader; + + @JsonProperty("node_name") + public String nodeName; + + @JsonProperty("base_url") + public String baseUrl; + + @JsonProperty public String state; // TODO Make this an enum? + @JsonProperty public String type; // TODO Make this an enum? + + @JsonProperty("force_set_state") + public Boolean forceSetState; Review Comment: My understanding of this boolean is that it was meant to be a verb as part of some cluster state manipulations and was *not* meant to be a characteristic of the data; *not* meant to be in any state.json. But it snuck in there accidentally. It should not be exposed in this API. CC @markrmiller ########## solr/core/src/java/org/apache/solr/handler/admin/api/CollectionStatus.java: ########## @@ -0,0 +1,89 @@ +/* + * 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.common.cloud.ZkStateReader.COLLECTION_PROP; + +import jakarta.inject.Inject; +import org.apache.solr.client.api.endpoint.CollectionStatusApi; +import org.apache.solr.client.api.model.CollectionStatusResponse; +import org.apache.solr.common.cloud.ZkNodeProps; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.core.CoreContainer; +import org.apache.solr.handler.admin.ColStatus; +import org.apache.solr.jersey.PermissionName; +import org.apache.solr.jersey.SolrJacksonMapper; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.security.PermissionNameProvider; + +/** V2 API implementation for {@link CollectionStatusApi}. */ +public class CollectionStatus extends AdminAPIBase implements CollectionStatusApi { + + @Inject + public CollectionStatus( + CoreContainer coreContainer, + SolrQueryRequest solrQueryRequest, + SolrQueryResponse solrQueryResponse) { + super(coreContainer, solrQueryRequest, solrQueryResponse); + } + + @Override + @PermissionName(PermissionNameProvider.Name.COLL_READ_PERM) + public CollectionStatusResponse getCollectionStatus( + String collectionName, + Boolean coreInfo, + Boolean segments, + Boolean fieldInfo, + Boolean rawSize, + Boolean rawSizeSummary, + Boolean rawSizeDetails, + Float rawSizeSamplingPercent, + Boolean sizeInfo) + throws Exception { + recordCollectionForLogAndTracing(collectionName, solrQueryRequest); + + final var params = new ModifiableSolrParams(); + params.add(COLLECTION_PROP, collectionName); + params.setNonNull(ColStatus.CORE_INFO_PROP, coreInfo); + params.setNonNull(ColStatus.SEGMENTS_PROP, segments); + params.setNonNull(ColStatus.FIELD_INFO_PROP, fieldInfo); + params.setNonNull(ColStatus.RAW_SIZE_PROP, rawSize); + params.setNonNull(ColStatus.RAW_SIZE_SUMMARY_PROP, rawSizeSummary); + params.setNonNull(ColStatus.RAW_SIZE_DETAILS_PROP, rawSizeDetails); + params.setNonNull(ColStatus.RAW_SIZE_SAMPLING_PERCENT_PROP, rawSizeSamplingPercent); + params.setNonNull(ColStatus.SIZE_INFO_PROP, sizeInfo); + + // TODO Push CollectionStatusResponse down into ColStatus and avoid the intermediate NL, if all + // usages can be switched over. + final var nlResponse = new NamedList<>(); + new ColStatus( + coreContainer.getSolrClientCache(), + coreContainer.getZkController().getZkStateReader().getClusterState(), + new ZkNodeProps(params)) + .getColStatus(nlResponse); + // collName is prop/key for a nested NL returned by ColStatus - extract the inner NL and + // manually add name to resp Review Comment: so much for v1 moving to be on top of v2; ehh? ########## solr/api/src/java/org/apache/solr/client/api/model/CollectionStatusResponse.java: ########## @@ -0,0 +1,164 @@ +/* + * 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.client.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.Map; + +/** Response of the CollectionStatusApi.getCollectionStatus() API */ +public class CollectionStatusResponse extends SolrJerseyResponse { Review Comment: I love how structured / clear this is. Previously (v1) was all untyped/magic. ########## solr/core/src/java/org/apache/solr/api/V2HttpCall.java: ########## @@ -188,6 +188,8 @@ public void call(SolrQueryRequest req, SolrQueryResponse rsp) { Thread.currentThread().setContextClassLoader(core.getResourceLoader().getClassLoader()); this.path = path = path.substring(prefix.length() + pathSegments.get(1).length() + 2); + parts.put( + COLLECTION_PROP, origCorename); // Core-level API, so populate "collection" template val Review Comment: (same) -- 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]
