gerlowskija commented on code in PR #2912: URL: https://github.com/apache/solr/pull/2912#discussion_r1890632261
########## 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: That model works great anytime that the v1 and v2 responses are exactly the same (which is almost always the case). I made the v2 response for this API slightly different from v1 COLSTATUS, so it's hard to have CollectionsHandler call `V2ApiUtils.squashIntoNamedList(new CollectionStatus(..).getCollectionStatus(...))` the way we've been doing with most of our other v1-v2 pairs. That said, I did a bit of restructuring here so that v1 can *mostly* sit on top of v2: CollectionsHandler.COLSTATUS now calls a static method `populateColStatusData` that lives in this class. Hopefully that gets us most of the benefit. If we eventually tackle the TODO comment at L87, we should be able to close the gap and have CollectionsHandler.COLSTATUS consume the v2 API in the normal way. -- 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]
