This is an automated email from the ASF dual-hosted git repository. gerlowskija pushed a commit to branch SOLR-16825-migrate-definitions-to-api-module-pt4 in repository https://gitbox.apache.org/repos/asf/solr.git
commit bbce1a0609d729863b39a1fe7e18d7585738cda8 Author: Jason Gerlowski <[email protected]> AuthorDate: Wed Sep 27 10:08:09 2023 -0400 Migrade install-shard-data to 'api' module --- .../client/api/endpoint/InstallShardDataApi.java | 38 +++++++++++++++++++ .../api/model/InstallShardDataRequestBody.java | 28 ++++++++++++++ .../solr/handler/admin/CollectionsHandler.java | 12 +++--- ...tallShardDataAPI.java => InstallShardData.java} | 44 ++++------------------ .../org/apache/solr/gcs/GCSInstallShardTest.java | 3 +- .../org/apache/solr/s3/S3InstallShardTest.java | 3 +- .../api/collections/AbstractInstallShardTest.java | 3 +- 7 files changed, 86 insertions(+), 45 deletions(-) diff --git a/solr/api/src/java/org/apache/solr/client/api/endpoint/InstallShardDataApi.java b/solr/api/src/java/org/apache/solr/client/api/endpoint/InstallShardDataApi.java new file mode 100644 index 00000000000..65648ad9117 --- /dev/null +++ b/solr/api/src/java/org/apache/solr/client/api/endpoint/InstallShardDataApi.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 javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import org.apache.solr.client.api.model.InstallShardDataRequestBody; +import org.apache.solr.client.api.model.SolrJerseyResponse; + +/** V2 API definition allowing users to import offline-constructed index into a shard. */ +@Path("/collections/{collName}/shards/{shardName}/install") +public interface InstallShardDataApi { + @POST + @Operation( + summary = "Install offline index into an existing shard", + tags = {"shards"}) + SolrJerseyResponse installShardData( + @PathParam("collName") String collName, + @PathParam("shardName") String shardName, + InstallShardDataRequestBody requestBody) + throws Exception; +} diff --git a/solr/api/src/java/org/apache/solr/client/api/model/InstallShardDataRequestBody.java b/solr/api/src/java/org/apache/solr/client/api/model/InstallShardDataRequestBody.java new file mode 100644 index 00000000000..31bec8eb434 --- /dev/null +++ b/solr/api/src/java/org/apache/solr/client/api/model/InstallShardDataRequestBody.java @@ -0,0 +1,28 @@ +/* + * 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; + +public class InstallShardDataRequestBody { + @JsonProperty(value = "location", required = true) + public String location; + + @JsonProperty public String repository; + + @JsonProperty public String async; +} diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java index 5b0b97f7f07..808fb8491e7 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java @@ -123,6 +123,7 @@ import org.apache.solr.api.AnnotatedApi; import org.apache.solr.api.Api; import org.apache.solr.api.JerseyResource; import org.apache.solr.client.api.model.AddReplicaPropertyRequestBody; +import org.apache.solr.client.api.model.InstallShardDataRequestBody; import org.apache.solr.client.api.model.ReplaceNodeRequestBody; import org.apache.solr.client.api.model.SolrJerseyResponse; import org.apache.solr.client.api.model.UpdateAliasPropertiesRequestBody; @@ -186,7 +187,7 @@ import org.apache.solr.handler.admin.api.DeleteReplica; import org.apache.solr.handler.admin.api.DeleteReplicaProperty; import org.apache.solr.handler.admin.api.DeleteShardAPI; import org.apache.solr.handler.admin.api.ForceLeader; -import org.apache.solr.handler.admin.api.InstallShardDataAPI; +import org.apache.solr.handler.admin.api.InstallShardData; import org.apache.solr.handler.admin.api.ListAliases; import org.apache.solr.handler.admin.api.ListCollectionBackups; import org.apache.solr.handler.admin.api.ListCollectionSnapshotsAPI; @@ -1080,13 +1081,12 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission req.getParams().required().check(COLLECTION, SHARD); final String collectionName = req.getParams().get(COLLECTION); final String shardName = req.getParams().get(SHARD); - final InstallShardDataAPI.InstallShardRequestBody reqBody = - new InstallShardDataAPI.InstallShardRequestBody(); - reqBody.asyncId = req.getParams().get(ASYNC); + final InstallShardDataRequestBody reqBody = new InstallShardDataRequestBody(); + reqBody.async = req.getParams().get(ASYNC); reqBody.repository = req.getParams().get(BACKUP_REPOSITORY); reqBody.location = req.getParams().get(BACKUP_LOCATION); - final InstallShardDataAPI installApi = new InstallShardDataAPI(h.coreContainer, req, rsp); + final InstallShardData installApi = new InstallShardData(h.coreContainer, req, rsp); final SolrJerseyResponse installResponse = installApi.installShardData(collectionName, shardName, reqBody); V2ApiUtils.squashIntoSolrResponseWithoutHeader(rsp, installResponse); @@ -1375,7 +1375,7 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission DeleteReplicaProperty.class, DeleteShardAPI.class, ForceLeader.class, - InstallShardDataAPI.class, + InstallShardData.class, ListCollections.class, ListCollectionBackups.class, ReloadCollectionAPI.class, diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardDataAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardData.java similarity index 78% rename from solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardDataAPI.java rename to solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardData.java index fa400835a4f..cd72071fc05 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardDataAPI.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/api/InstallShardData.java @@ -17,18 +17,13 @@ package org.apache.solr.handler.admin.api; -import static org.apache.solr.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2; import static org.apache.solr.handler.admin.CollectionsHandler.DEFAULT_COLLECTION_OP_TIMEOUT; import static org.apache.solr.security.PermissionNameProvider.Name.COLL_EDIT_PERM; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.lang.invoke.MethodHandles; import java.util.HashMap; import javax.inject.Inject; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import org.apache.solr.client.api.endpoint.InstallShardDataApi; +import org.apache.solr.client.api.model.InstallShardDataRequestBody; import org.apache.solr.client.api.model.SolrJerseyResponse; import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.cloud.api.collections.InstallShardDataCmd; @@ -41,42 +36,30 @@ import org.apache.solr.common.params.CollectionParams; import org.apache.solr.common.util.StrUtils; import org.apache.solr.core.CoreContainer; import org.apache.solr.handler.admin.CollectionsHandler; -import org.apache.solr.jersey.JacksonReflectMapWriter; import org.apache.solr.jersey.PermissionName; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** - * A V2 API that allows users to import an index constructed offline into a shard of their - * collection + * V2 API implementation allowing users to import offline-constructed index into a shard. * * <p>Particularly useful for installing (per-shard) indices constructed offline into a SolrCloud * deployment. Callers are required to put the collection into read-only mode prior to installing * data into any shards of that collection, and should exit read only mode when completed. */ -@Path("/collections/{collName}/shards/{shardName}/install") -public class InstallShardDataAPI extends AdminAPIBase { - - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); +public class InstallShardData extends AdminAPIBase implements InstallShardDataApi { @Inject - public InstallShardDataAPI( + public InstallShardData( CoreContainer coreContainer, SolrQueryRequest solrQueryRequest, SolrQueryResponse solrQueryResponse) { super(coreContainer, solrQueryRequest, solrQueryResponse); } - @POST - @Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2}) @PermissionName(COLL_EDIT_PERM) public SolrJerseyResponse installShardData( - @PathParam("collName") String collName, - @PathParam("shardName") String shardName, - InstallShardRequestBody requestBody) - throws Exception { + String collName, String shardName, InstallShardDataRequestBody requestBody) throws Exception { final SolrJerseyResponse response = instantiateJerseyResponse(SolrJerseyResponse.class); final CoreContainer coreContainer = fetchAndValidateZooKeeperAwareCoreContainer(); recordCollectionForLogAndTracing(collName, solrQueryRequest); @@ -130,28 +113,17 @@ public class InstallShardDataAPI extends AdminAPIBase { } public static ZkNodeProps createRemoteMessage( - String collectionName, String shardName, InstallShardRequestBody requestBody) { + String collectionName, String shardName, InstallShardDataRequestBody requestBody) { final InstallShardDataCmd.RemoteMessage messageTyped = new InstallShardDataCmd.RemoteMessage(); messageTyped.collection = collectionName; messageTyped.shard = shardName; if (requestBody != null) { messageTyped.location = requestBody.location; messageTyped.repository = requestBody.repository; - messageTyped.asyncId = requestBody.asyncId; + messageTyped.asyncId = requestBody.async; } messageTyped.validate(); return new ZkNodeProps(messageTyped.toMap(new HashMap<>())); } - - public static class InstallShardRequestBody implements JacksonReflectMapWriter { - @JsonProperty(defaultValue = "location", required = true) - public String location; - - @JsonProperty("repository") - public String repository; - - @JsonProperty("async") - public String asyncId; - } } diff --git a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java index 51dc59d2ea0..3d0d30262ed 100644 --- a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java +++ b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java @@ -20,6 +20,7 @@ package org.apache.solr.gcs; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.cloud.api.collections.AbstractInstallShardTest; +import org.apache.solr.handler.admin.api.InstallShardData; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -27,7 +28,7 @@ import org.junit.BeforeClass; * Tests validating that the 'Install Shard API' works when used with {@link GCSBackupRepository} * * @see org.apache.solr.cloud.api.collections.AbstractInstallShardTest - * @see org.apache.solr.handler.admin.api.InstallShardDataAPI + * @see InstallShardData */ // Backups do checksum validation against a footer value not present in 'SimpleText' @LuceneTestCase.SuppressCodecs({"SimpleText"}) diff --git a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java index 189928f3dbb..ea21cb58877 100644 --- a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java +++ b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java @@ -21,6 +21,7 @@ import com.adobe.testing.s3mock.junit4.S3MockRule; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.cloud.api.collections.AbstractInstallShardTest; +import org.apache.solr.handler.admin.api.InstallShardData; import org.junit.BeforeClass; import org.junit.ClassRule; import software.amazon.awssdk.regions.Region; @@ -29,7 +30,7 @@ import software.amazon.awssdk.regions.Region; * Tests validating that the 'Install Shard API' works when used with {@link S3BackupRepository} * * @see org.apache.solr.cloud.api.collections.AbstractInstallShardTest - * @see org.apache.solr.handler.admin.api.InstallShardDataAPI + * @see InstallShardData */ // Backups do checksum validation against a footer value not present in 'SimpleText' @LuceneTestCase.SuppressCodecs({"SimpleText"}) diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractInstallShardTest.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractInstallShardTest.java index 70f1a38e18e..cc9d655f04c 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractInstallShardTest.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractInstallShardTest.java @@ -48,6 +48,7 @@ import org.apache.solr.core.CoreDescriptor; import org.apache.solr.core.DirectoryFactory; import org.apache.solr.core.SolrCore; import org.apache.solr.core.backup.repository.BackupRepository; +import org.apache.solr.handler.admin.api.InstallShardData; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -62,7 +63,7 @@ import org.slf4j.LoggerFactory; * repository. This base-class will populate that backup repository all data necessary for these * tests. * - * @see org.apache.solr.handler.admin.api.InstallShardDataAPI + * @see InstallShardData */ public abstract class AbstractInstallShardTest extends SolrCloudTestCase {
