nick-boss-tech commented on code in PR #5353:
URL: https://github.com/apache/solr/pull/5353#discussion_r4636781444
##########
solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java:
##########
@@ -98,20 +95,9 @@ void listSnapshots(SnapshotListParams params) throws
Exception {
}
public void listSnapshots(SolrClient solrClient, String collectionName) {
- CollectionAdminRequest.ListSnapshots listSnaps =
- new CollectionAdminRequest.ListSnapshots(collectionName);
- CollectionAdminResponse resp;
try {
- resp = listSnaps.process(solrClient);
- if (resp.getStatus() != 0) {
- throw new IllegalStateException(
- "The LISTSNAPSHOTS request failed. The status code is " +
resp.getStatus());
- }
-
- NamedList<?> apiResult =
- (NamedList<?>)
resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
- apiResult.forEach((name, value) -> echo(name));
-
+ var response = new
CollectionSnapshotsApi.ListSnapshots(collectionName).process(solrClient);
Review Comment:
🤖 *AI text below* 🤖
Could we cover a proxied base URL before moving all four CLI commands to v2?
With a base path like `/solr-tenant/solr`, [the v2 URL
builder](https://github.com/epugh/solr/blob/4de78d855ccc9d5054589347cc99de654308d985/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java#L75-L88)
replaces the first `/solr` substring, producing `/api-tenant/solr` instead of
`/solr-tenant/api`. That rewrite already exists, but the v1 snapshot CLI didn’t
use it. Can we preserve the configured prefix or keep these commands on v1
until the rewrite is fixed?
##########
solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc:
##########
@@ -2537,6 +2537,8 @@ This is particularly useful prior to reindexing or making
config changes to a co
Unlike backups, which copy collection data off-disk, snapshots themselves
don't provide disaster recovery in case of disk or hardware failure.
They provide less protection than backups, at a much cheaper cost.
+The v2 API requires a JSON request body (use `{}` for the defaults) and
returns HTTP 404 if the collection does not exist.
Review Comment:
🤖 *AI text below* 🤖
If the CLI migration stays in this PR, could the upgrade notes say that
`snapshot create` now requires a server with the v2 route fix? A new CLI
pointed at an unupgraded node through `--solr-url` can hit the same HTTP 405
this PR fixes. Operators with proxy allowlists or custom permissions scoped to
`/solr/admin/collections` should also check the new
`/api/collections/.../snapshots` paths.
##########
solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java:
##########
@@ -62,19 +62,32 @@ String run(Class<? extends ToolBase> tool, String name,
String... extra) throws
@Test
public void testSnapshotLifecycle() throws Exception {
- run(SnapshotCreateTool.class, "snapshot-create", "--snapshot-name",
"snap1");
+ assertTrue(
+ run(SnapshotCreateTool.class, "snapshot-create", "--snapshot-name",
"snap1")
+ .contains("Successfully created snapshot"));
assertTrue(run(SnapshotListTool.class, "snapshot-list").contains("snap1"));
String described =
run(SnapshotDescribeTool.class, "snapshot-describe",
"--snapshot-name", "snap1");
assertTrue(described, described.contains("Name: snap1"));
+ assertTrue(described, described.contains("Status: Successful"));
+ assertTrue(described, described.contains("Total number of cores with
snapshot: 1"));
+ assertTrue(described, described.contains("leader=true"));
run(SnapshotDeleteTool.class, "snapshot-delete", "--snapshot-name",
"snap1");
assertFalse(run(SnapshotListTool.class,
"snapshot-list").contains("snap1"));
}
+ @Test
+ public void testDeleteMissingSnapshot() throws Exception {
Review Comment:
🤖 *AI text below* 🤖
Should deleting a missing snapshot remain a no-op for the CLI? It succeeded
idempotently on v1. After this change the v2 404 prints “Failed,” but the
command still exits 0. This test explicitly enforces both because `run()`
requires exit 0. I’d preserve the CLI’s no-op for an already absent snapshot.
If we want to make it a CLI error instead, the test should require a nonzero
exit status.
##########
solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java:
##########
@@ -16,70 +16,236 @@
*/
package org.apache.solr.handler.admin.api;
-import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
-import static
org.apache.solr.common.params.CollectionAdminParams.FOLLOW_ALIASES;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
-
-import org.apache.solr.client.api.model.CreateCollectionSnapshotRequestBody;
-import org.apache.solr.common.params.CollectionParams;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.junit.Before;
+import java.io.ByteArrayInputStream;
+import java.util.List;
+import java.util.Map;
+import org.apache.solr.client.solrj.RemoteSolrException;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
+import org.apache.solr.client.solrj.response.JavaBinResponseParser;
+import org.apache.solr.client.solrj.response.XMLResponseParser;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.snapshots.CollectionSnapshotMetaData;
+import org.eclipse.jetty.client.StringRequestContent;
+import org.junit.After;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mockito;
-public class CreateCollectionSnapshotAPITest extends MockV2APITest {
+/** HTTP integration tests for creating collection snapshots through the
generated client. */
+public class CreateCollectionSnapshotAPITest extends SolrCloudTestCase {
+ private static final String COLLECTION = "snapshot_api_collection";
+ private static final String ALIAS = "snapshot_api_alias";
- private CreateCollectionSnapshot api;
+ @BeforeClass
+ public static void setupCluster() throws Exception {
+ configureCluster(1).addConfig("conf",
configset("cloud-minimal")).configure();
+ CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1)
+ .process(cluster.getSolrClient());
+ cluster.waitForActiveCollection(COLLECTION, 1, 1);
+ cluster.getSolrClient().add(COLLECTION, new SolrInputDocument("id", "1"));
+ cluster.getSolrClient().commit(COLLECTION);
+ CollectionAdminRequest.createAlias(ALIAS,
COLLECTION).process(cluster.getSolrClient());
+ }
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- when(mockCoreContainer.isZooKeeperAware()).thenReturn(true);
+ @After
+ public void clearSnapshots() throws Exception {
+ var response =
+ new
CollectionSnapshotsApi.ListSnapshots(COLLECTION).process(cluster.getSolrClient());
+ for (String snapshot : response.snapshots.keySet()) {
+ new CollectionSnapshotsApi.DeleteCollectionSnapshot(COLLECTION, snapshot)
+ .process(cluster.getSolrClient());
+ }
+ }
- api = new CreateCollectionSnapshot(mockCoreContainer, mockQueryRequest,
queryResponse);
+ @Test
+ public void testMissingCollections() throws Exception {
+ var client = cluster.getSolrClient();
+ assertEquals(
+ 404,
+ expectThrows(
+ RemoteSolrException.class,
+ () ->
+ new
CollectionSnapshotsApi.CreateCollectionSnapshot("missing", "snapshot")
+ .process(client))
+ .code());
+ assertEquals(
+ 404,
+ expectThrows(
+ RemoteSolrException.class,
+ () -> new
CollectionSnapshotsApi.ListSnapshots("missing").process(client))
+ .code());
+ assertEquals(
+ 404,
+ expectThrows(
+ RemoteSolrException.class,
+ () ->
+ new
CollectionSnapshotsApi.DeleteCollectionSnapshot("missing", "snapshot")
+ .process(client))
+ .code());
+ assertEquals(
+ 400,
+ expectThrows(
+ RemoteSolrException.class,
+ () ->
+ new CollectionAdminRequest.CreateSnapshot("missing",
"snapshot")
+ .process(client))
+ .code());
+ assertEquals(
+ 400,
+ expectThrows(
+ RemoteSolrException.class,
+ () -> new
CollectionAdminRequest.ListSnapshots("missing").process(client))
+ .code());
+ assertEquals(
+ 400,
+ expectThrows(
+ RemoteSolrException.class,
+ () ->
+ new CollectionAdminRequest.DeleteSnapshot("missing",
"snapshot")
+ .process(client))
+ .code());
}
@Test
- public void testConstructsValidOverseerMessage() throws Exception {
- when(mockClusterState.hasCollection("myCollName")).thenReturn(true);
- when(mockSolrZkClient.exists(anyString())).thenReturn(false);
+ public void testMissingSnapshot() throws Exception {
+ var request = new
CollectionSnapshotsApi.DeleteCollectionSnapshot(COLLECTION, "missing");
+ var error =
+ expectThrows(RemoteSolrException.class, () ->
request.process(cluster.getSolrClient()));
+ assertEquals(404, error.code());
+ assertTrue(error.getMessage(), error.getMessage().contains("missing"));
+ new CollectionAdminRequest.DeleteSnapshot(COLLECTION, "missing")
+ .process(cluster.getSolrClient());
+ }
- CreateCollectionSnapshotRequestBody body = new
CreateCollectionSnapshotRequestBody();
- body.followAliases = false;
+ @Test
+ public void testMissingRequestBody() throws Exception {
+ var jetty = cluster.getJettySolrRunner(0);
+ var response =
+ jetty
+ .getSolrClient()
+ .getHttpClient()
+ .newRequest(
+ jetty.getBaseURLV2() + "/collections/" + COLLECTION +
"/snapshots/missing_body")
+ .method("POST")
+ .send();
+ assertEquals(400, response.getStatus());
+ var error = (Map<?, ?>) ((Map<?, ?>)
Utils.fromJSON(response.getContent())).get("error");
+ assertEquals(400L, ((Number) error.get("code")).longValue());
+ assertTrue(error.toString(),
error.get("msg").toString().contains("request-body"));
+ }
- api.createCollectionSnapshot("myCollName", "mySnapshotName", body);
+ @Test
+ public void testCreateResponseFormats() throws Exception {
+ var jetty = cluster.getJettySolrRunner(0);
+ for (String format : List.of("xml", "javabin")) {
+ String snapshot = "snapshot_" + format;
+ var response =
+ jetty
+ .getSolrClient()
+ .getHttpClient()
+ .newRequest(
+ jetty.getBaseURLV2()
+ + "/collections/"
+ + ALIAS
+ + "/snapshots/"
+ + snapshot
+ + "?wt="
+ + format)
+ .method("POST")
+ .body(new StringRequestContent("application/json",
"{\"followAliases\":true}"))
+ .send();
+ assertEquals(200, response.getStatus());
+ var parser = format.equals("xml") ? new XMLResponseParser() : new
JavaBinResponseParser();
+ var body = parser.processResponse(new
ByteArrayInputStream(response.getContent()), "UTF-8");
+ assertEquals(ALIAS, body.get("collection"));
+ assertEquals(true, body.get("followAliases"));
+ assertEquals(snapshot, body.get("snapshot"));
+ var listing =
+ jetty
+ .getSolrClient()
+ .getHttpClient()
+ .newRequest(
+ jetty.getBaseURLV2() + "/collections/" + COLLECTION +
"/snapshots?wt=" + format)
+ .send();
+ assertEquals(200, listing.getStatus());
+ var listingBody =
+ parser.processResponse(new
ByteArrayInputStream(listing.getContent()), "UTF-8");
+ assertEquals(snapshot, listingBody._get("snapshots/" + snapshot +
"/name"));
+ assertEquals("Successful", listingBody._get("snapshots/" + snapshot +
"/status"));
+ }
+ }
+
+ @Test
+ public void testCreateListAndDeleteSnapshot() throws Exception {
Review Comment:
🤖 *AI text below* 🤖
Could we keep an async-create assertion in the new HTTP tests? The removed
unit test checked that the body’s `async` ID reached the collection command;
the replacement cases all submit synchronously. A generated-client test could
assert the returned request ID, wait for terminal success via REQUESTSTATUS,
and then check that the snapshot appears in the listing.
--
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]