gerlowskija commented on code in PR #4179: URL: https://github.com/apache/solr/pull/4179#discussion_r3046271909
########## solr/api/src/java/org/apache/solr/client/api/endpoint/SplitShardApi.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.Parameter; +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.SolrJerseyResponse; +import org.apache.solr.client.api.model.SplitShardRequestBody; + +/** + * V2 API definition for splitting an existing shard into multiple pieces. + * + * <p>The new API (POST /api/collections/{collectionName}/shards/split) is equivalent to the v1 + * /admin/collections?action=SPLITSHARD command. + */ +@Path("/collections/{collectionName}/shards/split") +public interface SplitShardApi { + @POST + @Operation( + summary = "Splits a shard in an existing collection into two or more shards.", + tags = {"shards"}) + SolrJerseyResponse splitShard( Review Comment: [-1] SolrJerseyResponse is a very minimal POJO that pretty much just includes the responseHeader section. If you look at our actual split-shard implementation it can include a good bit more than that. Today's split-shard response can optionally include timing information about stages of the split, etc. So we probably need a split-shard specific response POJO ########## solr/solr-ref-guide/modules/configuration-guide/pages/coreadmin-api.adoc: ########## @@ -672,6 +672,31 @@ The `SPLIT` action splits an index into two or more indexes. The index being split can continue to handle requests. The split pieces can be placed into a specified directory on the server's filesystem or it can be merged into running Solr cores. +[tabs#coreadmin-split-request] Review Comment: [0] It's a bit weird to have this one example here, and then detailed info on the parameters, and then 2 or 3 more examples. Could the examples be combined in some way? ########## solr/core/src/java/org/apache/solr/handler/admin/api/SplitCoreAPI.java: ########## @@ -14,84 +14,86 @@ * 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.POST; import static org.apache.solr.common.params.CommonAdminParams.SPLIT_KEY; +import static org.apache.solr.common.params.CommonAdminParams.SPLIT_METHOD; import static org.apache.solr.common.params.CommonParams.PATH; import static org.apache.solr.common.params.CoreAdminParams.TARGET_CORE; import static org.apache.solr.handler.ClusterAPI.wrapParams; import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM; +import jakarta.inject.Inject; import java.util.HashMap; -import java.util.List; import java.util.Locale; import java.util.Map; -import org.apache.solr.api.Command; -import org.apache.solr.api.EndPoint; -import org.apache.solr.api.PayloadObj; -import org.apache.solr.common.annotation.JsonProperty; +import org.apache.solr.client.api.endpoint.SplitCoreApi; +import org.apache.solr.client.api.model.SolrJerseyResponse; +import org.apache.solr.client.api.model.SplitCoreRequestBody; +import org.apache.solr.common.params.CommonAdminParams; import org.apache.solr.common.params.CoreAdminParams; -import org.apache.solr.common.util.ReflectMapWriter; +import org.apache.solr.core.CoreContainer; import org.apache.solr.handler.admin.CoreAdminHandler; +import org.apache.solr.jersey.PermissionName; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; /** - * V2 API for splitting a single core into multiple pieces + * V2 API for splitting a single core into multiple pieces. * - * <p>The new API (POST /v2/cores/coreName {'split': {...}}) is equivalent to the v1 - * /admin/cores?action=split command. + * <p>The new API (POST /v2/cores/{coreName}/split) is equivalent to the v1 + * /admin/cores?action=split command. The logic remains in the V1 {@link CoreAdminHandler}. */ -@EndPoint( - path = {"/cores/{core}"}, - method = POST, - permission = CORE_EDIT_PERM) -public class SplitCoreAPI { - private static final String V2_SPLIT_CORE_CMD = "split"; - - private final CoreAdminHandler coreHandler; - - public SplitCoreAPI(CoreAdminHandler coreHandler) { - this.coreHandler = coreHandler; +public class SplitCoreAPI extends CoreAdminAPIBase implements SplitCoreApi { + + @Inject + public SplitCoreAPI( + CoreContainer coreContainer, + CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, + SolrQueryRequest req, + SolrQueryResponse rsp) { + super(coreContainer, coreAdminAsyncTracker, req, rsp); } - @Command(name = V2_SPLIT_CORE_CMD) - public void splitCore(PayloadObj<SplitCorePayload> obj) throws Exception { - final SplitCorePayload v2Body = obj.get(); - final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>()); + @Override + @PermissionName(CORE_EDIT_PERM) + public SolrJerseyResponse splitCore(String coreName, SplitCoreRequestBody requestBody) + throws Exception { + ensureRequiredParameterProvided("coreName", coreName); + SolrJerseyResponse response = instantiateJerseyResponse(SolrJerseyResponse.class); + + final Map<String, Object> v1Params = new HashMap<>(); v1Params.put( CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.SPLIT.name().toLowerCase(Locale.ROOT)); - v1Params.put( - CoreAdminParams.CORE, obj.getRequest().getPathTemplateValues().get(CoreAdminParams.CORE)); - - if (v2Body.path != null && !v2Body.path.isEmpty()) { - v1Params.put(PATH, v2Body.path.toArray(new String[0])); - } - if (v2Body.targetCore != null && !v2Body.targetCore.isEmpty()) { - v1Params.put(TARGET_CORE, v2Body.targetCore.toArray(new String[0])); - } - - if (v2Body.splitKey != null) { - v1Params.put(SPLIT_KEY, v1Params.remove("splitKey")); + v1Params.put(CoreAdminParams.CORE, coreName); + + if (requestBody != null) { + if (requestBody.path != null && !requestBody.path.isEmpty()) { + v1Params.put(PATH, requestBody.path.toArray(new String[0])); + } + if (requestBody.targetCore != null && !requestBody.targetCore.isEmpty()) { + v1Params.put(TARGET_CORE, requestBody.targetCore.toArray(new String[0])); + } + if (requestBody.splitKey != null) { + v1Params.put(SPLIT_KEY, requestBody.splitKey); + } + if (requestBody.splitMethod != null) { + v1Params.put(SPLIT_METHOD, requestBody.splitMethod); + } + if (requestBody.getRanges != null) { + v1Params.put(CoreAdminParams.GET_RANGES, requestBody.getRanges); + } + if (requestBody.ranges != null) { + v1Params.put(CoreAdminParams.RANGES, requestBody.ranges); + } + if (requestBody.async != null) { + v1Params.put(CommonAdminParams.ASYNC, requestBody.async); + } } - coreHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse()); - } - - public static class SplitCorePayload implements ReflectMapWriter { - @JsonProperty public List<String> path; - - @JsonProperty public List<String> targetCore; - - @JsonProperty public String splitKey; - - @JsonProperty public String splitMethod; - - @JsonProperty public Boolean getRanges; - - @JsonProperty public String ranges; - - @JsonProperty public String async; + CoreAdminHandler coreHandler = coreContainer.getMultiCoreHandler(); + coreHandler.handleRequestBody(wrapParams(req, v1Params), rsp); Review Comment: [-1] The way we've been handling the v1/v2 split is to have the actual logic/functionality live in v2, and have the v1 code (i.e. CoreAdminHandler) call into those methods. This serves a few purposes: 1. Makes it easier to delete the v1 code down the road. 2. Prevents v2 code from "falling behind" or being forgotten when query-params or API functionality changes 3. Ensures better test coverage - Most of our test code is for v1 APIs, so having the v1 code call v2 gives us at least some confidence that the v2 endpoints work despite their lack of test coverage. That's all to say - the actual logic in CorAdminHandler needs moved over here in order to get all those benefits. ########## solr/core/src/test/org/apache/solr/handler/admin/api/SplitShardAPITest.java: ########## @@ -0,0 +1,66 @@ +/* + * 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.core.CoreContainer.ALLOW_PATHS_SYSPROP; + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.api.model.SolrJerseyResponse; +import org.apache.solr.client.solrj.request.ShardsApi; +import org.apache.solr.common.util.EnvUtils; +import org.apache.solr.util.ExternalPaths; +import org.apache.solr.util.SolrJettyTestRule; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +/** Tests for the split shard V2 endpoint via the generated SolrJ client. */ +public class SplitShardAPITest extends SolrTestCaseJ4 { Review Comment: [-0] Any reason you created a new test class as opposed to adding the error-case test to SplitShardTest or a similar existing test class? That'd be my slight preference IMO. ########## changelog/unreleased/migrate-splitcoreapi-to-jaxrs.yml: ########## @@ -0,0 +1,7 @@ +title: Migrate SplitCore and SplitShard to JAX-RS. SplitCore and SplitShard now have OpenAPI and SolrJ support. Review Comment: [0] Drop the JAX-RS bit - users don't care about that IMO. What I'd focus on is the new auto-generated SolrJ classes that client users will have access to. -- 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]
