nick-boss-tech commented on code in PR #5284: URL: https://github.com/apache/solr/pull/5284#discussion_r4727729085
########## changelog/unreleased/SOLR-16398-rebalance-migrate.yml: ########## @@ -0,0 +1,7 @@ +title: Migrate the v2 rebalance-leaders and migrate-docs APIs to JAX-RS Review Comment: Done: the entry now reads 'Add generated SolrJ requests for the v2 rebalance-leaders and migrate-docs APIs', highlighting the SolrJ classes rather than the framework. ########## solr/api/src/java/org/apache/solr/client/api/endpoint/RebalanceLeadersApi.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.endpoint; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse; +import org.apache.solr.client.api.model.RebalanceLeadersRequestBody; + +@Path("/collections/{collectionName}/rebalance-leaders") +public interface RebalanceLeadersApi { + @POST + @Operation( + summary = "Rebalance shard leaders in a collection according to preferred leader settings.", + tags = {"collections"}) + FlexibleSolrJerseyResponse rebalanceLeaders( Review Comment: Done: the endpoint returns a dedicated RebalanceLeadersResponse model instead of FlexibleSolrJerseyResponse. ########## solr/core/src/java/org/apache/solr/handler/admin/api/RebalanceLeaders.java: ########## @@ -0,0 +1,82 @@ +/* + * 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 static org.apache.solr.common.cloud.ZkStateReader.MAX_AT_ONCE_PROP; +import static org.apache.solr.common.cloud.ZkStateReader.MAX_WAIT_SECONDS_PROP; +import static org.apache.solr.security.PermissionNameProvider.Name.COLL_EDIT_PERM; + +import jakarta.inject.Inject; +import java.util.Map; +import org.apache.solr.client.api.endpoint.RebalanceLeadersApi; +import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse; +import org.apache.solr.client.api.model.RebalanceLeadersRequestBody; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.core.CoreContainer; +import org.apache.solr.jersey.PermissionName; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; + +/** + * V2 API for rebalancing shard leaders in a collection. + * + * <p>This API (POST /v2/collections/collectionName/rebalance-leaders) is analogous to the v1 + * /admin/collections?action=REBALANCELEADERS command. + */ +public class RebalanceLeaders extends AdminAPIBase implements RebalanceLeadersApi { + + @Inject + public RebalanceLeaders( + CoreContainer coreContainer, + SolrQueryRequest solrQueryRequest, + SolrQueryResponse solrQueryResponse) { + super(coreContainer, solrQueryRequest, solrQueryResponse); + } + + @Override + @PermissionName(COLL_EDIT_PERM) + @SuppressWarnings("unchecked") + public FlexibleSolrJerseyResponse rebalanceLeaders( + String collectionName, RebalanceLeadersRequestBody requestBody) throws Exception { + final var response = instantiateJerseyResponse(FlexibleSolrJerseyResponse.class); + fetchAndValidateZooKeeperAwareCoreContainer(); + ensureRequiredParameterProvided(COLLECTION_PROP, collectionName); + recordCollectionForLogAndTracing(collectionName, solrQueryRequest); + if (requestBody == null) { + requestBody = new RebalanceLeadersRequestBody(); + } + + final var params = new ModifiableSolrParams(solrQueryRequest.getParams()); + params.set(COLLECTION_PROP, collectionName); + if (requestBody.maxAtOnce != null) { + params.set(MAX_AT_ONCE_PROP, requestBody.maxAtOnce); + } + if (requestBody.maxWaitSeconds != null) { + params.set(MAX_WAIT_SECONDS_PROP, requestBody.maxWaitSeconds); + } + solrQueryRequest.setParams(params); + + new org.apache.solr.handler.admin.RebalanceLeaders( Review Comment: Done: RebalanceLeaders now takes strongly typed parameters (collection, maxAtOnce, maxWaitSeconds, lock id), the v2 endpoint calls it directly, and the v1 CollectionsHandler path shares the same class. ########## solr/core/src/test/org/apache/solr/handler/admin/api/CollectionCommandsV2IntegrationTest.java: ########## @@ -0,0 +1,196 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.request.V2Request; +import org.apache.solr.client.solrj.response.RequestStatusState; +import org.apache.solr.client.solrj.response.V2Response; +import org.apache.solr.client.solrj.response.json.JsonMapResponseParser; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.cloud.RoutingRule; +import org.apache.solr.common.cloud.Slice; +import org.junit.BeforeClass; +import org.junit.Test; + +/** Drives the JAX-RS collection command APIs over HTTP against a running SolrCloud cluster. */ +public class CollectionCommandsV2IntegrationTest extends SolrCloudTestCase { Review Comment: Done: the standalone CollectionCommandsV2IntegrationTest class is gone; the coverage lives in RebalanceLeadersAPITest and TestRebalanceLeaders, and the API test drives the generated SolrJ request and response classes. -- 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]
