This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new e997ae88fdd SOLR-17731: Fix shadowed v2 alias and snapshot APIs (#5353)
e997ae88fdd is described below
commit e997ae88fddff0119709dda8af7e5ba94abe1123
Author: Eric Pugh <[email protected]>
AuthorDate: Sun Nov 22 11:27:29 2026 -0500
SOLR-17731: Fix shadowed v2 alias and snapshot APIs (#5353)
Align the class-level resource roots and move resource names to
method-level paths, preserving the public URLs.
Reuse GetAliasByNameResponse for each entry in the v2 alias listing.
Entries now contain name, a collections array, and properties, matching the
detail response. Update the Admin UI to consume this structure and preserve the
v1 LISTALIASES response format.
Introduce typed collection snapshot metadata, including replica details and
creation time in epoch milliseconds. Use the narrower synchronous listing
response base and include CREATE response fields consistently in JSON, XML, and
Javabin.
Return HTTP 404 for missing aliases, collections, and snapshots, and HTTP
400 for a missing snapshot creation body. Preserve the v1 snapshot collection
error codes, missing-snapshot deletion no-op, and listing format in the
adapters.
Migrate bin/solr snapshot create, delete, list, and describe to the
generated v2 clients. Use typed metadata directly when describing a snapshot,
removing the legacy response parsing.
Update the reference guide examples and API conventions documentation.
---
changelog/unreleased/SOLR-17731.yml | 14 +
dev-docs/apis-v2-conventions.adoc | 2 +-
.../api/endpoint/CollectionSnapshotApis.java | 3 +-
.../solr/client/api/endpoint/DeleteAliasApi.java | 3 +-
...sponse.java => CollectionSnapshotMetadata.java} | 24 +-
.../model/CreateCollectionSnapshotResponse.java | 2 +
.../solr/client/api/model/ListAliasesResponse.java | 6 +-
.../api/model/ListCollectionSnapshotsResponse.java | 6 +-
.../org/apache/solr/cli/SnapshotCreateTool.java | 14 +-
.../org/apache/solr/cli/SnapshotDeleteTool.java | 47 ++-
.../org/apache/solr/cli/SnapshotDescribeTool.java | 74 +---
.../java/org/apache/solr/cli/SnapshotListTool.java | 20 +-
.../cloud/api/collections/CreateSnapshotCmd.java | 2 +-
.../core/snapshots/CollectionSnapshotMetaData.java | 45 +++
.../solr/handler/admin/CollectionsHandler.java | 48 ++-
.../solr/handler/admin/api/AdminAPIBase.java | 2 +-
.../admin/api/CreateCollectionSnapshot.java | 1 +
.../admin/api/DeleteCollectionSnapshot.java | 20 +
.../apache/solr/handler/admin/api/ListAliases.java | 41 +-
.../handler/admin/api/ListCollectionSnapshots.java | 5 +-
.../org/apache/solr/cli/SnapshotToolsTest.java | 37 +-
.../admin/api/CreateCollectionSnapshotAPITest.java | 425 ++++++++++++++++++---
.../admin/api/DeleteCollectionSnapshotAPITest.java | 2 +-
.../solr/handler/admin/api/ListAliasesAPITest.java | 169 ++++----
.../deployment-guide/pages/alias-management.adoc | 55 ++-
.../pages/collection-management.adoc | 108 ++++--
.../pages/major-changes-in-solr-11.adoc | 13 +
.../solr/webapp/AdminUiCollectionsScreenTest.java | 48 +++
solr/webapp/web/js/angular/app.js | 9 +-
.../web/js/angular/controllers/collections.js | 9 +-
solr/webapp/web/partials/alias_overview.html | 2 +-
solr/webapp/web/partials/collections.html | 2 +-
32 files changed, 937 insertions(+), 321 deletions(-)
diff --git a/changelog/unreleased/SOLR-17731.yml
b/changelog/unreleased/SOLR-17731.yml
new file mode 100644
index 00000000000..84c6d3483b1
--- /dev/null
+++ b/changelog/unreleased/SOLR-17731.yml
@@ -0,0 +1,14 @@
+title: >-
+ Fix v2 alias detail and collection snapshot creation requests returning HTTP
405.
+ Alias listings now return the same per-alias structure as the detail view,
+ including a collections array and properties; the Admin UI supports this
format.
+ Align snapshot responses and error handling with v2 conventions, and migrate
+ the snapshot CLI to these APIs. The CLI explains when a snapshot is already
absent
+ and returns a nonzero exit status for other deletion errors.
+ Fix asynchronous collection snapshot creation while preserving v1 response
formats.
+type: fixed
+authors:
+ - name: Eric Pugh
+links:
+ - name: SOLR-17731
+ url: https://issues.apache.org/jira/browse/SOLR-17731
diff --git a/dev-docs/apis-v2-conventions.adoc
b/dev-docs/apis-v2-conventions.adoc
index 848f460cedc..2868a7a1662 100644
--- a/dev-docs/apis-v2-conventions.adoc
+++ b/dev-docs/apis-v2-conventions.adoc
@@ -160,7 +160,7 @@ Don't settle for a bare `SolrJerseyResponse` if the
underlying operation actuall
When an API exposes both a "list all" endpoint and a "get one by name"
endpoint for the same kind of resource, give each its own response type rather
than reusing the list's shape for a single item:
-* `List<Resource>Response` - the collection endpoint's response. Its data is a
map or list keyed/indexed across every matching resource (e.g.
`ListAliasesResponse.aliases: Map<String, String>`).
+* `List<Resource>Response` - the collection endpoint's response. Its data is a
map or list keyed/indexed across every matching resource (e.g.
`ListAliasesResponse.aliases: Map<String, GetAliasByNameResponse>`).
* `Get<Resource>Response` (or `Get<Resource>ByNameResponse`) - the
single-resource endpoint's response. Its data is a flat object describing just
that one resource, with no collection wrapper (e.g.
`GetAliasByNameResponse.collections`, `GetAliasByNameResponse.properties`).
Don't have the single-resource endpoint return the list type filtered down to
one entry (e.g. a `Map<String, ...>` with one key) - that forces callers to
re-extract by name something they already specified in the request, and conveys
no information once only one key is possible.
diff --git
a/solr/api/src/java/org/apache/solr/client/api/endpoint/CollectionSnapshotApis.java
b/solr/api/src/java/org/apache/solr/client/api/endpoint/CollectionSnapshotApis.java
index 21c1dc44224..04972ad5633 100644
---
a/solr/api/src/java/org/apache/solr/client/api/endpoint/CollectionSnapshotApis.java
+++
b/solr/api/src/java/org/apache/solr/client/api/endpoint/CollectionSnapshotApis.java
@@ -53,9 +53,10 @@ public interface CollectionSnapshotApis {
throws Exception;
}
- @Path("/collections/{collName}/snapshots/{snapshotName}")
+ @Path("/collections/{collName}/snapshots")
interface Delete {
@DELETE
+ @Path("/{snapshotName}")
@Operation(
summary = "Delete an existing collection-snapshot by name.",
tags = {"collection-snapshots"})
diff --git
a/solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java
b/solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java
index 082760f9f41..5b96bf0a48a 100644
--- a/solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java
+++ b/solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java
@@ -25,10 +25,11 @@ import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import org.apache.solr.client.api.model.AsyncJerseyResponse;
-@Path("/aliases/{aliasName}")
+@Path("/aliases")
public interface DeleteAliasApi {
@DELETE
+ @Path("/{aliasName}")
@Operation(
summary = "Deletes an alias by its name",
tags = {"aliases"})
diff --git
a/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
b/solr/api/src/java/org/apache/solr/client/api/model/CollectionSnapshotMetadata.java
similarity index 51%
copy from
solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
copy to
solr/api/src/java/org/apache/solr/client/api/model/CollectionSnapshotMetadata.java
index 3d9c93af85e..7ead7ae31d4 100644
---
a/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
+++
b/solr/api/src/java/org/apache/solr/client/api/model/CollectionSnapshotMetadata.java
@@ -17,12 +17,24 @@
package org.apache.solr.client.api.model;
import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Map;
+import java.util.List;
+import org.apache.solr.client.api.util.ReflectWritable;
-public class ListAliasesResponse extends SolrJerseyResponse {
- @JsonProperty("aliases")
- public Map<String, String> aliases;
+/** Metadata for a collection snapshot and its replica snapshots. */
+public class CollectionSnapshotMetadata implements ReflectWritable {
+ @JsonProperty public String name;
+ @JsonProperty public String status;
+ @JsonProperty public Long creationDate;
+ @JsonProperty public List<ReplicaSnapshotMetadata> replicaSnapshots;
+ @JsonProperty public List<String> shards;
- @JsonProperty("properties")
- public Map<String, Map<String, String>> properties;
+ /** The index commit captured on a replica. */
+ public static class ReplicaSnapshotMetadata implements ReflectWritable {
+ @JsonProperty public String coreName;
+ @JsonProperty public String indexDirPath;
+ @JsonProperty public long generationNumber;
+ @JsonProperty public boolean leader;
+ @JsonProperty public String shardId;
+ @JsonProperty public List<String> files;
+ }
}
diff --git
a/solr/api/src/java/org/apache/solr/client/api/model/CreateCollectionSnapshotResponse.java
b/solr/api/src/java/org/apache/solr/client/api/model/CreateCollectionSnapshotResponse.java
index 0392e0ed1ce..4ad4a13e119 100644
---
a/solr/api/src/java/org/apache/solr/client/api/model/CreateCollectionSnapshotResponse.java
+++
b/solr/api/src/java/org/apache/solr/client/api/model/CreateCollectionSnapshotResponse.java
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
public class CreateCollectionSnapshotResponse extends
SubResponseAccumulatingJerseyResponse {
@Schema(description = "The name of the collection.")
+ @JsonProperty("collection")
public String collection;
@Schema(description = "The name of the snapshot to be created.")
@@ -28,5 +29,6 @@ public class CreateCollectionSnapshotResponse extends
SubResponseAccumulatingJer
public String snapshotName;
@Schema(description = "A flag that treats the collName parameter as a
collection alias.")
+ @JsonProperty("followAliases")
public boolean followAliases;
}
diff --git
a/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
b/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
index 3d9c93af85e..b656f2f3865 100644
---
a/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
+++
b/solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java
@@ -19,10 +19,8 @@ package org.apache.solr.client.api.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
+/** Response listing details for all collection aliases. */
public class ListAliasesResponse extends SolrJerseyResponse {
@JsonProperty("aliases")
- public Map<String, String> aliases;
-
- @JsonProperty("properties")
- public Map<String, Map<String, String>> properties;
+ public Map<String, GetAliasByNameResponse> aliases;
}
diff --git
a/solr/api/src/java/org/apache/solr/client/api/model/ListCollectionSnapshotsResponse.java
b/solr/api/src/java/org/apache/solr/client/api/model/ListCollectionSnapshotsResponse.java
index 962cfda7014..51ff9668573 100644
---
a/solr/api/src/java/org/apache/solr/client/api/model/ListCollectionSnapshotsResponse.java
+++
b/solr/api/src/java/org/apache/solr/client/api/model/ListCollectionSnapshotsResponse.java
@@ -21,11 +21,9 @@ import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;
/** The Response for the v2 "list collection snapshots" API */
-public class ListCollectionSnapshotsResponse extends AsyncJerseyResponse {
+public class ListCollectionSnapshotsResponse extends SolrJerseyResponse {
- // TODO In practice, map values are of the CollectionSnapshotMetaData type,
but that cannot be
- // used here until the class is made into more of a POJO and can join the
'api' module here
@Schema(description = "The snapshots for the collection.")
@JsonProperty("snapshots")
- public Map<String, Object> snapshots;
+ public Map<String, CollectionSnapshotMetadata> snapshots;
}
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotCreateTool.java
b/solr/core/src/java/org/apache/solr/cli/SnapshotCreateTool.java
index 5066f75f3bb..f5724702924 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotCreateTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotCreateTool.java
@@ -20,8 +20,7 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
/** Supports snapshot-create command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -118,15 +117,10 @@ public class SnapshotCreateTool extends ToolBase {
}
public void createSnapshot(SolrClient solrClient, String collectionName,
String snapshotName) {
- CollectionAdminRequest.CreateSnapshot createSnapshot =
- new CollectionAdminRequest.CreateSnapshot(collectionName,
snapshotName);
- CollectionAdminResponse resp;
+ var createSnapshot =
+ new CollectionSnapshotsApi.CreateCollectionSnapshot(collectionName,
snapshotName);
try {
- resp = createSnapshot.process(solrClient);
- if (resp.getStatus() != 0) {
- throw new IllegalStateException(
- "The CREATESNAPSHOT request failed. The status code is " +
resp.getStatus());
- }
+ createSnapshot.process(solrClient);
echo(
"Successfully created snapshot with name "
+ snapshotName
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotDeleteTool.java
b/solr/core/src/java/org/apache/solr/cli/SnapshotDeleteTool.java
index 399796c9835..21e1d04ea4e 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotDeleteTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotDeleteTool.java
@@ -16,12 +16,14 @@
*/
package org.apache.solr.cli;
+import static org.apache.solr.common.SolrException.ErrorCode.NOT_FOUND;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
+import org.apache.solr.common.SolrException;
/** Supports snapshot-delete command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -118,15 +120,10 @@ public class SnapshotDeleteTool extends ToolBase {
}
public void deleteSnapshot(SolrClient solrClient, String collectionName,
String snapshotName) {
- CollectionAdminRequest.DeleteSnapshot deleteSnapshot =
- new CollectionAdminRequest.DeleteSnapshot(collectionName,
snapshotName);
- CollectionAdminResponse resp;
+ var deleteSnapshot =
+ new CollectionSnapshotsApi.DeleteCollectionSnapshot(collectionName,
snapshotName);
try {
- resp = deleteSnapshot.process(solrClient);
- if (resp.getStatus() != 0) {
- throw new IllegalStateException(
- "The DELETESNAPSHOT request failed. The status code is " +
resp.getStatus());
- }
+ deleteSnapshot.process(solrClient);
echo(
"Successfully deleted snapshot with name "
+ snapshotName
@@ -134,13 +131,39 @@ public class SnapshotDeleteTool extends ToolBase {
+ collectionName);
} catch (Exception e) {
- echo(
+ if (isMissingSnapshot(solrClient, collectionName, snapshotName, e)) {
+ echo(
+ "Snapshot with name "
+ + snapshotName
+ + " does not exist for collection "
+ + collectionName
+ + "; nothing to delete.");
+ return;
+ }
+ throw new IllegalStateException(
"Failed to delete a snapshot with name "
+ snapshotName
+ " for collection "
+ collectionName
+ " due to following error : "
- + e.getLocalizedMessage());
+ + e.getLocalizedMessage(),
+ e);
+ }
+ }
+
+ private static boolean isMissingSnapshot(
+ SolrClient solrClient, String collectionName, String snapshotName,
Exception failure) {
+ if (!(failure instanceof SolrException error) || error.code() !=
NOT_FOUND.code) {
+ return false;
+ }
+ try {
+ return !new CollectionSnapshotsApi.ListSnapshots(collectionName)
+ .process(solrClient)
+ .snapshots
+ .containsKey(snapshotName);
+ } catch (Exception lookupFailure) {
+ failure.addSuppressed(lookupFailure);
+ return false;
}
}
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotDescribeTool.java
b/solr/core/src/java/org/apache/solr/cli/SnapshotDescribeTool.java
index 9793903ccfc..bc4bb1bf392 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotDescribeTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotDescribeTool.java
@@ -16,22 +16,15 @@
*/
package org.apache.solr.cli;
-import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Date;
import java.util.Locale;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.response.CollectionAdminResponse;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.snapshots.CollectionSnapshotMetaData;
-import org.apache.solr.core.snapshots.SolrSnapshotManager;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
/** Supports snapshot-describe command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -132,28 +125,25 @@ public class SnapshotDescribeTool extends ToolBase {
public void describeSnapshot(SolrClient solrClient, String collectionName,
String snapshotName) {
try {
- Collection<CollectionSnapshotMetaData> snaps =
- listCollectionSnapshots(solrClient, collectionName);
- for (CollectionSnapshotMetaData m : snaps) {
- if (snapshotName.equals(m.getName())) {
- echo("Name: " + m.getName());
- echo("Status: " + m.getStatus());
- echo("Time of creation: " + dateFormat.format(m.getCreationDate()));
- echo("Total number of cores with snapshot: " +
m.getReplicaSnapshots().size());
- echo("-----------------------------------");
- for (CollectionSnapshotMetaData.CoreSnapshotMetaData n :
m.getReplicaSnapshots()) {
- String builder =
- "Core [name="
- + n.getCoreName()
- + ", leader="
- + n.isLeader()
- + ", generation="
- + n.getGenerationNumber()
- + ", indexDirPath="
- + n.getIndexDirPath()
- + "]\n";
- echo(builder);
- }
+ var response = new
CollectionSnapshotsApi.ListSnapshots(collectionName).process(solrClient);
+ var metadata = response.snapshots.get(snapshotName);
+ if (metadata != null) {
+ echo("Name: " + metadata.name);
+ echo("Status: " + metadata.status);
+ echo("Time of creation: " + dateFormat.format(new
Date(metadata.creationDate)));
+ echo("Total number of cores with snapshot: " +
metadata.replicaSnapshots.size());
+ echo("-----------------------------------");
+ for (var replica : metadata.replicaSnapshots) {
+ echo(
+ "Core [name="
+ + replica.coreName
+ + ", leader="
+ + replica.leader
+ + ", generation="
+ + replica.generationNumber
+ + ", indexDirPath="
+ + replica.indexDirPath
+ + "]\n");
}
}
} catch (Exception e) {
@@ -161,28 +151,6 @@ public class SnapshotDescribeTool extends ToolBase {
}
}
- private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(
- SolrClient solrClient, String collectionName) throws
SolrServerException, IOException {
- CollectionAdminRequest.ListSnapshots listSnapshots =
- new CollectionAdminRequest.ListSnapshots(collectionName);
- CollectionAdminResponse resp = listSnapshots.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);
-
- Collection<CollectionSnapshotMetaData> result = new ArrayList<>();
- for (int i = 0; i < apiResult.size(); i++) {
- result.add(new CollectionSnapshotMetaData((NamedList<?>)
apiResult.getVal(i)));
- }
-
- return result;
- }
-
@Override
public int callTool() throws Exception {
SnapshotDescribeParams params =
diff --git a/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
b/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
index 4649215b53e..56abb2a0018 100644
--- a/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/SnapshotListTool.java
@@ -20,10 +20,7 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.response.CollectionAdminResponse;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.snapshots.SolrSnapshotManager;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
/** Supports snapshot-list command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -98,20 +95,9 @@ public class SnapshotListTool extends ToolBase {
}
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);
+ response.snapshots.keySet().forEach(this::echo);
} catch (Exception e) {
echo(
"Failed to list snapshots for collection "
diff --git
a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateSnapshotCmd.java
b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateSnapshotCmd.java
index 2c901cea406..881d0305e21 100644
---
a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateSnapshotCmd.java
+++
b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateSnapshotCmd.java
@@ -98,7 +98,7 @@ public class CreateSnapshotCmd implements
CollApiCmds.CollectionApiCommand {
ShardHandler shardHandler = ccc.newShardHandler();
final ShardRequestTracker shardRequestTracker =
- CollectionHandlingUtils.asyncRequestTracker(adminCmdContext, ccc);
+ CollectionHandlingUtils.syncRequestTracker(adminCmdContext, ccc);
DocCollection collection =
ccc.getZkStateReader().getClusterState().getCollection(collectionName);
for (Slice slice : collection.getActiveSlices()) {
diff --git
a/solr/core/src/java/org/apache/solr/core/snapshots/CollectionSnapshotMetaData.java
b/solr/core/src/java/org/apache/solr/core/snapshots/CollectionSnapshotMetaData.java
index b3b3476ac3d..325a4c4b5b8 100644
---
a/solr/core/src/java/org/apache/solr/core/snapshots/CollectionSnapshotMetaData.java
+++
b/solr/core/src/java/org/apache/solr/core/snapshots/CollectionSnapshotMetaData.java
@@ -24,6 +24,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.solr.client.api.model.CollectionSnapshotMetadata;
+import
org.apache.solr.client.api.model.CollectionSnapshotMetadata.ReplicaSnapshotMetadata;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
@@ -183,6 +185,49 @@ public class CollectionSnapshotMetaData implements
JSONWriter.Writable {
}
}
+ /** Build internal metadata from the API representation. */
+ public CollectionSnapshotMetaData(CollectionSnapshotMetadata metadata) {
+ this(
+ metadata.name,
+ SnapshotStatus.valueOf(metadata.status),
+ new Date(metadata.creationDate),
+ metadata.replicaSnapshots.stream()
+ .map(
+ replica ->
+ new CoreSnapshotMetaData(
+ replica.coreName,
+ replica.indexDirPath,
+ replica.generationNumber,
+ replica.shardId,
+ replica.leader,
+ replica.files))
+ .toList());
+ }
+
+ /** Return the public API representation of this snapshot. */
+ public CollectionSnapshotMetadata toApiModel() {
+ var result = new CollectionSnapshotMetadata();
+ result.name = name;
+ result.status = status.toString();
+ result.creationDate = creationDate.getTime();
+ result.shards = List.copyOf(getShards());
+ result.replicaSnapshots =
+ replicaSnapshots.stream()
+ .map(
+ replica -> {
+ var entry = new ReplicaSnapshotMetadata();
+ entry.coreName = replica.getCoreName();
+ entry.indexDirPath = replica.getIndexDirPath();
+ entry.generationNumber = replica.getGenerationNumber();
+ entry.shardId = replica.getShardId();
+ entry.leader = replica.isLeader();
+ entry.files = List.copyOf(replica.getFiles());
+ return entry;
+ })
+ .toList();
+ return result;
+ }
+
public String getName() {
return name;
}
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 982bb85cb41..55c39574f81 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
@@ -100,6 +100,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.solr.api.AnnotatedApi;
@@ -469,6 +470,17 @@ public class CollectionsHandler extends RequestHandlerBase
implements Permission
return Category.ADMIN;
}
+ private static <T> T callSnapshotApi(Callable<T> operation) throws Exception
{
+ try {
+ return operation.call();
+ } catch (SolrException e) {
+ if (e.code() == SolrException.ErrorCode.NOT_FOUND.code) {
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
e.getMessage(), e);
+ }
+ throw e;
+ }
+ }
+
@SuppressWarnings("ImmutableEnumChecker")
public enum CollectionOperation implements CollectionOp {
CREATE_OP(
@@ -623,8 +635,17 @@ public class CollectionsHandler extends RequestHandlerBase
implements Permission
LISTALIASES,
(req, rsp, h) -> {
final ListAliases getAliasesAPI = new ListAliases(h.coreContainer,
req, rsp);
- final SolrJerseyResponse getAliasesResponse =
getAliasesAPI.getAliases();
- V2ApiUtils.squashIntoSolrResponseWithoutHeader(rsp,
getAliasesResponse);
+ final var getAliasesResponse = getAliasesAPI.getAliases();
+ Map<String, String> aliases = new LinkedHashMap<>();
+ Map<String, Map<String, String>> properties = new LinkedHashMap<>();
+ for (var alias : getAliasesResponse.aliases.values()) {
+ aliases.put(alias.alias, String.join(",", alias.collections));
+ if (!alias.properties.isEmpty()) {
+ properties.put(alias.alias, alias.properties);
+ }
+ }
+ rsp.add("aliases", aliases);
+ rsp.add("properties", properties);
return null;
}),
/**
@@ -923,10 +944,14 @@ public class CollectionsHandler extends
RequestHandlerBase implements Permission
requestBody.async = asyncId;
final CreateCollectionSnapshotResponse createSnapshotResponse =
- createCollectionSnapshotAPI.createCollectionSnapshot(
- extCollectionName, commitName, requestBody);
+ callSnapshotApi(
+ () ->
+ createCollectionSnapshotAPI.createCollectionSnapshot(
+ extCollectionName, commitName, requestBody));
V2ApiUtils.squashIntoSolrResponseWithoutHeader(rsp,
createSnapshotResponse);
+ rsp.getValues().remove("collection");
+ rsp.getValues().remove("followAliases");
return null;
}),
@@ -944,8 +969,10 @@ public class CollectionsHandler extends RequestHandlerBase
implements Permission
new DeleteCollectionSnapshot(h.coreContainer, req, rsp);
final var deleteSnapshotResponse =
- deleteCollectionSnapshotAPI.deleteCollectionSnapshot(
- extCollectionName, commitName, followAliases, asyncId);
+ callSnapshotApi(
+ () ->
+ deleteCollectionSnapshotAPI.deleteCollectionSnapshot(
+ extCollectionName, commitName, followAliases,
asyncId, false));
V2ApiUtils.squashIntoSolrResponseWithoutHeader(rsp,
deleteSnapshotResponse);
return null;
@@ -959,11 +986,14 @@ public class CollectionsHandler extends
RequestHandlerBase implements Permission
new ListCollectionSnapshots(h.coreContainer, req, rsp);
final ListCollectionSnapshotsResponse response =
-
listCollectionSnapshotsAPI.listSnapshots(req.getParams().get(COLLECTION_PROP));
+ callSnapshotApi(
+ () ->
+ listCollectionSnapshotsAPI.listSnapshots(
+ req.getParams().get(COLLECTION_PROP)));
NamedList<Object> snapshots = new NamedList<>();
- for (Object meta : response.snapshots.values()) {
- final var metaTyped = (CollectionSnapshotMetaData) meta;
+ for (var meta : response.snapshots.values()) {
+ final var metaTyped = new CollectionSnapshotMetaData(meta);
snapshots.add(metaTyped.getName(), metaTyped.toNamedList());
}
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/AdminAPIBase.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/AdminAPIBase.java
index 8cb671cffd5..d51197cdbcc 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/api/AdminAPIBase.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/AdminAPIBase.java
@@ -106,7 +106,7 @@ public abstract class AdminAPIBase extends JerseyResource {
final ClusterState clusterState =
coreContainer.getZkController().getClusterState();
if (!clusterState.hasCollection(collectionName)) {
throw new SolrException(
- SolrException.ErrorCode.BAD_REQUEST,
+ SolrException.ErrorCode.NOT_FOUND,
"Collection '" + collectionName + "' does not exist, no action
taken.");
}
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/CreateCollectionSnapshot.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/CreateCollectionSnapshot.java
index 2cfa244c74a..45346612590 100644
---
a/solr/core/src/java/org/apache/solr/handler/admin/api/CreateCollectionSnapshot.java
+++
b/solr/core/src/java/org/apache/solr/handler/admin/api/CreateCollectionSnapshot.java
@@ -59,6 +59,7 @@ public class CreateCollectionSnapshot extends AdminAPIBase
final CoreContainer coreContainer =
fetchAndValidateZooKeeperAwareCoreContainer();
recordCollectionForLogAndTracing(collName, solrQueryRequest);
+ ensureRequiredRequestBodyProvided(requestBody);
final String collectionName = resolveCollectionName(collName,
requestBody.followAliases);
final SolrZkClient client = coreContainer.getZkController().getZkClient();
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/DeleteCollectionSnapshot.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/DeleteCollectionSnapshot.java
index 086fde0cff0..b75c4dda83c 100644
---
a/solr/core/src/java/org/apache/solr/handler/admin/api/DeleteCollectionSnapshot.java
+++
b/solr/core/src/java/org/apache/solr/handler/admin/api/DeleteCollectionSnapshot.java
@@ -25,10 +25,12 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.solr.client.api.endpoint.CollectionSnapshotApis;
import org.apache.solr.client.api.model.DeleteCollectionSnapshotResponse;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.snapshots.SolrSnapshotManager;
import org.apache.solr.jersey.PermissionName;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
@@ -50,11 +52,29 @@ public class DeleteCollectionSnapshot extends AdminAPIBase
public DeleteCollectionSnapshotResponse deleteCollectionSnapshot(
String collName, String snapshotName, boolean followAliases, String
asyncId)
throws Exception {
+ return deleteCollectionSnapshot(collName, snapshotName, followAliases,
asyncId, true);
+ }
+
+ /** Shared implementation that can retain the legacy API's missing-snapshot
no-op. */
+ public DeleteCollectionSnapshotResponse deleteCollectionSnapshot(
+ String collName,
+ String snapshotName,
+ boolean followAliases,
+ String asyncId,
+ boolean failIfSnapshotMissing)
+ throws Exception {
final var response =
instantiateJerseyResponse(DeleteCollectionSnapshotResponse.class);
fetchAndValidateZooKeeperAwareCoreContainer();
recordCollectionForLogAndTracing(collName, solrQueryRequest);
final String collectionName = resolveCollectionName(collName,
followAliases);
+ if (failIfSnapshotMissing
+ && !SolrSnapshotManager.snapshotExists(
+ coreContainer.getZkController().getZkClient(), collectionName,
snapshotName)) {
+ throw new SolrException(
+ SolrException.ErrorCode.NOT_FOUND,
+ "Snapshot '" + snapshotName + "' does not exist for collection '" +
collectionName + "'");
+ }
submitRemoteMessageAndHandleResponse(
response,
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/ListAliases.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/ListAliases.java
index 69be9a59567..0460a3625a4 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/api/ListAliases.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/ListAliases.java
@@ -16,15 +16,16 @@
*/
package org.apache.solr.handler.admin.api;
+import static org.apache.solr.common.SolrException.ErrorCode.NOT_FOUND;
import static
org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PERM;
import jakarta.inject.Inject;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import org.apache.solr.client.api.endpoint.ListAliasesApi;
import org.apache.solr.client.api.model.GetAliasByNameResponse;
import org.apache.solr.client.api.model.ListAliasesResponse;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Aliases;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer;
@@ -43,12 +44,7 @@ public class ListAliases extends AdminAPIBase implements
ListAliasesApi {
super(coreContainer, solrQueryRequest, solrQueryResponse);
}
- /**
- * V2 API for listing all aliases known by Solr.
- *
- * <p>This API <code>GET /api/aliases</code> is analogous to the v1
<code>GET /api/cluster/aliases
- * </code> API.
- */
+ /** V2 API for listing all aliases known by Solr. */
@Override
@PermissionName(COLL_READ_PERM)
public ListAliasesResponse getAliases() throws Exception {
@@ -56,19 +52,15 @@ public class ListAliases extends AdminAPIBase implements
ListAliasesApi {
final ListAliasesResponse response =
instantiateJerseyResponse(ListAliasesResponse.class);
final Aliases aliases = readAliasesFromZk();
+ response.aliases = new LinkedHashMap<>();
if (aliases != null) {
- // the aliases themselves...
- response.aliases = aliases.getCollectionAliasMap();
- // Any properties for the above aliases.
- Map<String, Map<String, String>> meta = new LinkedHashMap<>();
- for (String alias : aliases.getCollectionAliasListMap().keySet()) {
- Map<String, String> collectionAliasProperties =
aliases.getCollectionAliasProperties(alias);
- if (!collectionAliasProperties.isEmpty()) {
- meta.put(alias, collectionAliasProperties);
- }
+ for (String aliasName : aliases.getCollectionAliasListMap().keySet()) {
+ final GetAliasByNameResponse entry = new GetAliasByNameResponse();
+ entry.responseHeader = null;
+ populateAlias(entry, aliases, aliasName);
+ response.aliases.put(aliasName, entry);
}
- response.properties = meta;
}
return response;
@@ -80,15 +72,22 @@ public class ListAliases extends AdminAPIBase implements
ListAliasesApi {
recordCollectionForLogAndTracing(null, solrQueryRequest);
final GetAliasByNameResponse response =
instantiateJerseyResponse(GetAliasByNameResponse.class);
- response.alias = aliasName;
-
final Aliases aliases = readAliasesFromZk();
+ if (aliases == null || !aliases.hasAlias(aliasName)) {
+ throw new SolrException(NOT_FOUND, "No such alias [" + aliasName + "]");
+ }
+ populateAlias(response, aliases, aliasName);
+
+ return response;
+ }
+
+ private static void populateAlias(
+ GetAliasByNameResponse response, Aliases aliases, String aliasName) {
+ response.alias = aliasName;
if (aliases != null) {
response.collections =
aliases.getCollectionAliasListMap().getOrDefault(aliasName, List.of());
response.properties = aliases.getCollectionAliasProperties(aliasName);
}
-
- return response;
}
private Aliases readAliasesFromZk() throws Exception {
diff --git
a/solr/core/src/java/org/apache/solr/handler/admin/api/ListCollectionSnapshots.java
b/solr/core/src/java/org/apache/solr/handler/admin/api/ListCollectionSnapshots.java
index 9bbc94f202b..a17c6c10053 100644
---
a/solr/core/src/java/org/apache/solr/handler/admin/api/ListCollectionSnapshots.java
+++
b/solr/core/src/java/org/apache/solr/handler/admin/api/ListCollectionSnapshots.java
@@ -22,6 +22,7 @@ import jakarta.inject.Inject;
import java.util.Collection;
import java.util.Map;
import org.apache.solr.client.api.endpoint.CollectionSnapshotApis;
+import org.apache.solr.client.api.model.CollectionSnapshotMetadata;
import org.apache.solr.client.api.model.ListCollectionSnapshotsResponse;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.util.CollectionUtil;
@@ -59,9 +60,9 @@ public class ListCollectionSnapshots extends AdminAPIBase
implements CollectionS
Collection<CollectionSnapshotMetaData> m =
SolrSnapshotManager.listSnapshots(client, collectionName);
- final Map<String, Object> snapshots = CollectionUtil.newHashMap(m.size());
+ final Map<String, CollectionSnapshotMetadata> snapshots =
CollectionUtil.newHashMap(m.size());
for (CollectionSnapshotMetaData metaData : m) {
- snapshots.put(metaData.getName(), metaData);
+ snapshots.put(metaData.getName(), metaData.toApiModel());
}
response.snapshots = snapshots;
diff --git a/solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java
b/solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java
index 5389dfe1573..4eb1e94301d 100644
--- a/solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/SnapshotToolsTest.java
@@ -62,19 +62,54 @@ public class SnapshotToolsTest extends SolrCloudTestCase {
@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 {
+ String output = run(SnapshotDeleteTool.class, "snapshot-delete",
"--snapshot-name", "missing");
+ assertTrue(output, output.contains("Snapshot with name missing"));
+ assertTrue(output, output.contains("does not exist"));
+ assertTrue(output, output.contains("nothing to delete"));
+ assertFalse(output, output.contains("Failed to delete"));
+ assertFalse(output, output.contains("Successfully deleted"));
+ }
+
+ @Test
+ public void testDeleteSnapshotFromMissingCollectionFails() throws Exception {
+ CLITestHelper.TestingRuntime runtime = new
CLITestHelper.TestingRuntime(true);
+ assertEquals(
+ 1,
+ runTool(
+ new String[] {
+ "snapshot-delete",
+ "-c",
+ "missing_collection",
+ "--snapshot-name",
+ "missing",
+ "--solr-url",
+ cluster.getJettySolrRunner(0).getBaseUrl().toString()
+ },
+ runtime,
+ SnapshotDeleteTool.class));
+ assertFalse(runtime.getOutput(), runtime.getOutput().contains("nothing to
delete"));
+ }
+
// snapshot-list reports a failed request in its output and still exits 0,
so check the output.
@Test
public void testConnectionFallsBackToTheZkHostProperty() throws Exception {
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java
b/solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java
index c0046f293cf..c11d2482245 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/api/CreateCollectionSnapshotAPITest.java
@@ -16,70 +16,381 @@
*/
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.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.solr.client.solrj.RemoteSolrException;
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.request.GenericSolrRequest;
+import org.apache.solr.client.solrj.response.JavaBinResponseParser;
+import org.apache.solr.client.solrj.response.RequestStatusState;
+import org.apache.solr.client.solrj.response.XMLResponseParser;
+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.util.NamedList;
+import org.apache.solr.common.util.TimeSource;
+import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.snapshots.CollectionSnapshotMetaData;
+import org.apache.solr.util.TimeOut;
+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 static final Duration ASYNC_SNAPSHOT_TIMEOUT =
Duration.ofSeconds(30);
- 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());
+ }
+
+ @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());
+ }
+ }
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- when(mockCoreContainer.isZooKeeperAware()).thenReturn(true);
+ @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());
+ }
- api = new CreateCollectionSnapshot(mockCoreContainer, mockQueryRequest,
queryResponse);
+ @Test
+ 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());
}
@Test
- public void testConstructsValidOverseerMessage() throws Exception {
- when(mockClusterState.hasCollection("myCollName")).thenReturn(true);
- when(mockSolrZkClient.exists(anyString())).thenReturn(false);
-
- CreateCollectionSnapshotRequestBody body = new
CreateCollectionSnapshotRequestBody();
- body.followAliases = false;
-
- api.createCollectionSnapshot("myCollName", "mySnapshotName", body);
-
- validateRunCommand(
- CollectionParams.CollectionAction.CREATESNAPSHOT,
- message -> {
- assertEquals(3, message.size());
- assertThat(
- message.keySet(),
- containsInAnyOrder(COLLECTION_PROP, CoreAdminParams.COMMIT_NAME,
FOLLOW_ALIASES));
- assertEquals("myCollName", message.get(COLLECTION_PROP));
- assertEquals("mySnapshotName",
message.get(CoreAdminParams.COMMIT_NAME));
- assertEquals(false, message.get(FOLLOW_ALIASES));
- });
-
- body.followAliases = true;
- body.async = "testId";
- Mockito.clearInvocations(mockCommandRunner);
- api.createCollectionSnapshot("myCollName", "mySnapshotName", body);
-
- validateRunCommand(
- CollectionParams.CollectionAction.CREATESNAPSHOT,
- body.async,
- message -> {
- assertEquals(3, message.size());
- assertThat(
- message.keySet(),
- containsInAnyOrder(COLLECTION_PROP, CoreAdminParams.COMMIT_NAME,
FOLLOW_ALIASES));
- assertEquals("myCollName", message.get(COLLECTION_PROP));
- assertEquals("mySnapshotName",
message.get(CoreAdminParams.COMMIT_NAME));
- assertEquals(true, message.get(FOLLOW_ALIASES));
- });
+ 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"));
+ }
+
+ @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 {
+ String snapshot = "snapshot_api_sync";
+ var response =
+ new CollectionSnapshotsApi.CreateCollectionSnapshot(COLLECTION,
snapshot)
+ .process(cluster.getSolrClient());
+ assertEquals(COLLECTION, response.collection);
+ assertEquals(snapshot, response.snapshotName);
+ assertFalse(response.followAliases);
+ var metadata =
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(cluster.getSolrClient())
+ .snapshots
+ .get(snapshot);
+ assertEquals(snapshot, metadata.name);
+ assertEquals("Successful", metadata.status);
+ assertNotNull(metadata.creationDate);
+ assertEquals(List.of("shard1"), metadata.shards);
+ assertEquals(1, metadata.replicaSnapshots.size());
+ var replica = metadata.replicaSnapshots.getFirst();
+ assertEquals("shard1", replica.shardId);
+ assertTrue(replica.leader);
+ assertFalse(replica.files.isEmpty());
+ var legacyResponse =
+ new
CollectionAdminRequest.ListSnapshots(COLLECTION).process(cluster.getSolrClient());
+ var legacySnapshots = (NamedList<?>)
legacyResponse.getResponse().get("snapshots");
+ var legacyMetadata =
+ new CollectionSnapshotMetaData((NamedList<?>)
legacySnapshots.get(snapshot));
+ assertEquals(snapshot, legacyMetadata.getName());
+ assertEquals(metadata.creationDate.longValue(),
legacyMetadata.getCreationDate().getTime());
+ assertEquals(replica.coreName,
legacyMetadata.getReplicaSnapshots().getFirst().getCoreName());
+ assertTrue(
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(cluster.getSolrClient())
+ .snapshots
+ .containsKey(snapshot));
+
+ new CollectionSnapshotsApi.DeleteCollectionSnapshot(COLLECTION, snapshot)
+ .process(cluster.getSolrClient());
+ assertTrue(
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(cluster.getSolrClient())
+ .snapshots
+ .isEmpty());
+ }
+
+ @Test
+ public void testV1SnapshotResponseFormats() throws Exception {
+ var client = cluster.getSolrClient();
+ for (var parser :
+ List.of(
+ new JsonMapResponseParser(), new XMLResponseParser(), new
JavaBinResponseParser())) {
+ String snapshot = "snapshot_v1_" + parser.getWriterType();
+ var create = new CollectionAdminRequest.CreateSnapshot(ALIAS, snapshot);
+ create.setFollowAliases(true);
+ create.setResponseParser(parser);
+ var created = create.process(client).getResponse();
+ assertEquals(Set.of("responseHeader", "snapshot"),
created.asMap(0).keySet());
+ assertEquals(snapshot, created.get("snapshot"));
+
+ var list = new CollectionAdminRequest.ListSnapshots(COLLECTION);
+ list.setResponseParser(parser);
+ var listed = list.process(client).getResponse();
+ assertEquals(Set.of("responseHeader", "snapshots"),
listed.asMap(0).keySet());
+ if (parser instanceof JsonMapResponseParser) {
+ var snapshots = (List<?>) listed.get("snapshots");
+ assertEquals(2, snapshots.size());
+ assertEquals(snapshot, snapshots.getFirst());
+ var metadata = (List<?>) snapshots.get(1);
+ assertEquals(snapshot, metadata.get(metadata.indexOf("name") + 1));
+ assertEquals("Successful", metadata.get(metadata.indexOf("status") +
1));
+ } else {
+ assertEquals(snapshot, listed._get("snapshots/" + snapshot + "/name"));
+ assertEquals("Successful", listed._get("snapshots/" + snapshot +
"/status"));
+ }
+
+ var delete = new CollectionAdminRequest.DeleteSnapshot(COLLECTION,
snapshot);
+ delete.setResponseParser(parser);
+ var deleted = delete.process(client).getResponse();
+ assertEquals(
+ Set.of("responseHeader", "collection", "snapshot", "followAliases"),
+ deleted.asMap(0).keySet());
+ assertEquals(COLLECTION, deleted.get("collection"));
+ assertEquals(snapshot, deleted.get("snapshot"));
+ assertEquals(false, deleted.get("followAliases"));
+ }
+ }
+
+ @Test
+ public void testV1CoreSnapshotAsyncStatusResponse() throws Exception {
+ var client = cluster.getJettySolrRunner(0).getSolrClient();
+ String core =
+ cluster
+ .getSolrClient()
+ .getClusterState()
+ .getCollection(COLLECTION)
+ .getLeader("shard1")
+ .getCoreName();
+ String snapshot = "snapshot_v1_core_async";
+ String asyncId = "snapshot_v1_core_request";
+ var create =
+ new GenericSolrRequest(
+ SolrRequest.METHOD.POST,
+ "/admin/cores",
+ SolrRequest.SolrRequestType.ADMIN,
+ params(
+ "action",
+ "CREATESNAPSHOT",
+ "core",
+ core,
+ "commitName",
+ snapshot,
+ "async",
+ asyncId));
+ create.process(client);
+ var requestStatus =
+ new GenericSolrRequest(
+ SolrRequest.METHOD.GET,
+ "/admin/cores",
+ SolrRequest.SolrRequestType.ADMIN,
+ params("action", "REQUESTSTATUS", "requestid", asyncId));
+ var status = new AtomicReference<NamedList<Object>>();
+ new TimeOut(ASYNC_SNAPSHOT_TIMEOUT, TimeSource.NANO_TIME)
+ .waitFor(
+ "Core snapshot task did not complete",
+ () -> {
+ try {
+ status.set(requestStatus.process(client).getResponse());
+ assertNotEquals(status.get().toString(), "failed",
status.get().get("STATUS"));
+ return "completed".equals(status.get().get("STATUS"));
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+ });
+ try {
+ for (var parser :
+ List.of(
+ new JsonMapResponseParser(), new XMLResponseParser(), new
JavaBinResponseParser())) {
+ requestStatus.setResponseParser(parser);
+ var response = requestStatus.process(client).getResponse();
+ assertEquals(Set.of("responseHeader", "STATUS"),
response.asMap(0).keySet());
+ assertEquals("completed", response.get("STATUS"));
+ }
+ } finally {
+ var delete = new CoreAdminRequest.DeleteSnapshot(snapshot);
+ delete.setCoreName(core);
+ delete.process(client);
+ }
+ }
+
+ @Test
+ public void testCreateSnapshotAsync() throws Exception {
+ String snapshot = "snapshot_api_async";
+ String asyncId = "create_snapshot_async";
+ var client = cluster.getSolrClient();
+ var request = new CollectionSnapshotsApi.CreateCollectionSnapshot(ALIAS,
snapshot);
+ request.setFollowAliases(true);
+ request.setAsync(asyncId);
+ var response = request.process(client);
+ assertEquals(asyncId, response.requestId);
+ assertEquals(ALIAS, response.collection);
+ assertEquals(snapshot, response.snapshotName);
+ assertTrue(response.followAliases);
+
+ var status = waitForAsyncClusterRequest(asyncId, ASYNC_SNAPSHOT_TIMEOUT);
+ assertEquals(status.toString(), RequestStatusState.COMPLETED,
status.getRequestStatus());
+ var metadata =
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(client)
+ .snapshots
+ .get(snapshot);
+ assertNotNull(metadata);
+ assertEquals(snapshot, metadata.name);
+ assertEquals("Successful", metadata.status);
+ assertEquals(List.of("shard1"), metadata.shards);
+ assertEquals(1, metadata.replicaSnapshots.size());
+ assertFalse(metadata.replicaSnapshots.getFirst().files.isEmpty());
+ CollectionAdminRequest.deleteAsyncId(asyncId).process(client);
+ }
+
+ @Test
+ public void testCreateSnapshotThroughAlias() throws Exception {
+ String snapshot = "snapshot_api_alias";
+ var request = new CollectionSnapshotsApi.CreateCollectionSnapshot(ALIAS,
snapshot);
+ request.setFollowAliases(true);
+ var response = request.process(cluster.getSolrClient());
+ assertEquals(ALIAS, response.collection);
+ assertEquals(snapshot, response.snapshotName);
+ assertTrue(response.followAliases);
+ assertTrue(
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(cluster.getSolrClient())
+ .snapshots
+ .containsKey(snapshot));
+
+ var delete = new CollectionSnapshotsApi.DeleteCollectionSnapshot(ALIAS,
snapshot);
+ delete.setFollowAliases(true);
+ delete.process(cluster.getSolrClient());
+ assertTrue(
+ new CollectionSnapshotsApi.ListSnapshots(COLLECTION)
+ .process(cluster.getSolrClient())
+ .snapshots
+ .isEmpty());
}
}
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/api/DeleteCollectionSnapshotAPITest.java
b/solr/core/src/test/org/apache/solr/handler/admin/api/DeleteCollectionSnapshotAPITest.java
index 13282e888bb..dd9db030c00 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/api/DeleteCollectionSnapshotAPITest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/api/DeleteCollectionSnapshotAPITest.java
@@ -44,7 +44,7 @@ public class DeleteCollectionSnapshotAPITest extends
MockV2APITest {
@Test
public void testConstructsValidOverseerMessage() throws Exception {
when(mockClusterState.hasCollection("myCollName")).thenReturn(true);
- when(mockSolrZkClient.exists(anyString())).thenReturn(false);
+ when(mockSolrZkClient.exists(anyString())).thenReturn(true);
api.deleteCollectionSnapshot("myCollName", "mySnapshotName", false, null);
diff --git
a/solr/core/src/test/org/apache/solr/handler/admin/api/ListAliasesAPITest.java
b/solr/core/src/test/org/apache/solr/handler/admin/api/ListAliasesAPITest.java
index 9939217b4b0..bbc6ea7e126 100644
---
a/solr/core/src/test/org/apache/solr/handler/admin/api/ListAliasesAPITest.java
+++
b/solr/core/src/test/org/apache/solr/handler/admin/api/ListAliasesAPITest.java
@@ -16,101 +16,126 @@
*/
package org.apache.solr.handler.admin.api;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.hamcrest.CoreMatchers.containsString;
-import io.opentelemetry.api.trace.Span;
import java.util.List;
import java.util.Map;
-import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.api.model.GetAliasByNameResponse;
import org.apache.solr.client.api.model.ListAliasesResponse;
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.common.cloud.Aliases;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.cloud.ZkStateReader.AliasesManager;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.junit.Before;
+import org.apache.solr.client.solrj.RemoteSolrException;
+import org.apache.solr.client.solrj.request.AliasesApi;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.util.Utils;
+import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;
-/** Unit tests for {@link ListAliases} */
-public class ListAliasesAPITest extends SolrTestCaseJ4 {
-
- private CoreContainer mockCoreContainer;
- private ZkStateReader zkStateReader;
- private SolrQueryRequest mockQueryRequest;
- private SolrQueryResponse queryResponse;
-
- private ListAliases getAliasesAPI;
+/** HTTP integration tests for {@link ListAliases} using the generated SolrJ
client. */
+public class ListAliasesAPITest extends SolrCloudTestCase {
+ private static final String COLLECTION_A = "listaliases_a";
+ private static final String COLLECTION_B = "listaliases_b";
@BeforeClass
- public static void ensureWorkingMockito() {
- assumeWorkingMockito();
+ public static void setupCluster() throws Exception {
+ configureCluster(1).addConfig("conf",
configset("cloud-minimal")).configure();
+ for (String collection : List.of(COLLECTION_A, COLLECTION_B)) {
+ CollectionAdminRequest.createCollection(collection, "conf", 1, 1)
+ .process(cluster.getSolrClient());
+ cluster.waitForActiveCollection(collection, 1, 1);
+ }
}
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
-
- AliasesManager aliasesManager = mock(AliasesManager.class);
- zkStateReader = mock(ZkStateReader.class);
- when(zkStateReader.getAliasesManager()).thenReturn(aliasesManager);
-
- ZkController zkController = mock(ZkController.class);
- when(zkController.getZkStateReader()).thenReturn(zkStateReader);
-
- mockCoreContainer = mock(CoreContainer.class);
- when(mockCoreContainer.getZkController()).thenReturn(zkController);
-
- mockQueryRequest = mock(SolrQueryRequest.class);
- when(mockQueryRequest.getSpan()).thenReturn(Span.getInvalid());
- queryResponse = new SolrQueryResponse();
-
- getAliasesAPI = new ListAliases(mockCoreContainer, mockQueryRequest,
queryResponse);
+ @After
+ public void clearAliases() throws Exception {
+ var response = new
AliasesApi.GetAliases().process(cluster.getSolrClient());
+ for (String alias : response.aliases.keySet()) {
+ new AliasesApi.DeleteAlias(alias).process(cluster.getSolrClient());
+ }
}
@Test
public void testGetAliases() throws Exception {
- when(mockCoreContainer.isZooKeeperAware()).thenReturn(true);
-
- Aliases aliases =
- Aliases.EMPTY
- .cloneWithCollectionAlias("alias0", "colA")
- .cloneWithCollectionAlias("alias1", "colB")
- .cloneWithCollectionAliasProperties("alias1", "pkey1", "pvalA");
- when(zkStateReader.getAliases()).thenReturn(aliases);
+ createAliases();
+ ListAliasesResponse response = new
AliasesApi.GetAliases().process(cluster.getSolrClient());
+ assertEquals(2, response.aliases.size());
+ assertNotNull(response.responseHeader);
+ assertEquals(List.of(COLLECTION_A),
response.aliases.get("alias0").collections);
+ assertEquals(List.of(COLLECTION_B, COLLECTION_A),
response.aliases.get("alias1").collections);
+ assertEquals(Map.of(), response.aliases.get("alias0").properties);
+ assertEquals(Map.of("pkey1", "pvalA"),
response.aliases.get("alias1").properties);
+ for (String name : List.of("alias0", "alias1")) {
+ GetAliasByNameResponse entry = response.aliases.get(name);
+ GetAliasByNameResponse detail =
+ new AliasesApi.GetAliasByName(name).process(cluster.getSolrClient());
+ assertEquals(name, entry.alias);
+ assertEquals(detail.collections, entry.collections);
+ assertEquals(detail.properties, entry.properties);
+ }
+ }
- ListAliasesResponse response = getAliasesAPI.getAliases();
- assertEquals(aliases.getCollectionAliasMap(), response.aliases);
- assertEquals(
- aliases.getCollectionAliasProperties("alias0"),
- response.properties.getOrDefault("alias0", Map.of()));
- assertEquals(
- aliases.getCollectionAliasProperties("alias1"),
- response.properties.getOrDefault("alias1", Map.of()));
- assertNull(response.error);
+ @Test
+ public void testGetEmptyAliases() throws Exception {
+ ListAliasesResponse response = new
AliasesApi.GetAliases().process(cluster.getSolrClient());
+ assertEquals(Map.of(), response.aliases);
+ assertNotNull(response.responseHeader);
}
@Test
public void testGetAliasByName() throws Exception {
- when(mockCoreContainer.isZooKeeperAware()).thenReturn(true);
-
- Aliases aliases =
- Aliases.EMPTY
- .cloneWithCollectionAlias("alias0", "colA")
- .cloneWithCollectionAlias("alias1", "colB")
- .cloneWithCollectionAliasProperties("alias1", "pkey1", "pvalA");
- when(zkStateReader.getAliases()).thenReturn(aliases);
-
- GetAliasByNameResponse response = getAliasesAPI.getAliasByName("alias1");
+ createAliases();
+ GetAliasByNameResponse response =
+ new
AliasesApi.GetAliasByName("alias1").process(cluster.getSolrClient());
assertEquals("alias1", response.alias);
- assertEquals(List.of("colB"), response.collections);
+ assertEquals(List.of(COLLECTION_B, COLLECTION_A), response.collections);
assertEquals(Map.of("pkey1", "pvalA"), response.properties);
+ assertNotNull(response.responseHeader);
+ }
+
+ @Test
+ public void testGetMissingAliasByName() throws Exception {
+ createAliases();
+ var request = new AliasesApi.GetAliasByName("missingAlias");
+ RemoteSolrException exception =
+ expectThrows(RemoteSolrException.class, () ->
request.process(cluster.getSolrClient()));
+ assertEquals(404, exception.code());
+ assertThat(exception.getMessage(), containsString("No such alias
[missingAlias]"));
+ }
+
+ @Test
+ public void testResponseFormatAndV1Compatibility() throws Exception {
+ createAliases();
+ var jetty = cluster.getJettySolrRunner(0);
+ var httpResponse =
+ jetty.getSolrClient().getHttpClient().newRequest(jetty.getBaseURLV2()
+ "/aliases").send();
+ assertEquals(200, httpResponse.getStatus());
+ Map<?, ?> listing = (Map<?, ?>) Utils.fromJSON(httpResponse.getContent());
+ assertTrue(listing.containsKey("responseHeader"));
+ assertFalse(listing.containsKey("properties"));
+ assertEquals(
+ Map.of(
+ "alias0",
+ Map.of("name", "alias0", "collections", List.of(COLLECTION_A),
"properties", Map.of()),
+ "alias1",
+ Map.of(
+ "name", "alias1",
+ "collections", List.of(COLLECTION_B, COLLECTION_A),
+ "properties", Map.of("pkey1", "pvalA"))),
+ listing.get("aliases"));
+
+ var legacyResponse = new
CollectionAdminRequest.ListAliases().process(cluster.getSolrClient());
+ assertEquals(
+ Map.of("alias0", COLLECTION_A, "alias1", COLLECTION_B + "," +
COLLECTION_A),
+ legacyResponse.getAliases());
+ assertEquals(Map.of("alias1", Map.of("pkey1", "pvalA")),
legacyResponse.getAliasProperties());
+ }
- assertNull(response.error);
+ private void createAliases() throws Exception {
+ CollectionAdminRequest.createAlias("alias0",
COLLECTION_A).process(cluster.getSolrClient());
+ CollectionAdminRequest.createAlias("alias1", COLLECTION_B + "," +
COLLECTION_A)
+ .process(cluster.getSolrClient());
+ CollectionAdminRequest.setAliasProperty("alias1")
+ .addProperty("pkey1", "pvalA")
+ .process(cluster.getSolrClient());
}
}
diff --git
a/solr/solr-ref-guide/modules/deployment-guide/pages/alias-management.adoc
b/solr/solr-ref-guide/modules/deployment-guide/pages/alias-management.adoc
index 1474a403c52..1c946594660 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/alias-management.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/alias-management.adoc
@@ -583,7 +583,9 @@ curl 'http://localhost:8983/api/aliases/testalias2'
=== LISTALIASES Response
-The output will contain a list of aliases with the corresponding collection
names.
+The v2 output maps each alias name to an object containing its `name`, a
`collections` array, and a `properties` map.
+Each object has the same fields as the detail response for a single alias,
without a nested `responseHeader`.
+The v1 `LISTALIASES` response retains its alias-to-comma-separated-collections
map and separate `properties` map.
=== Examples using LISTALIASES
@@ -591,13 +593,34 @@ The output will contain a list of aliases with the
corresponding collection name
*Input*
+[tabs#listaliases-example-request]
+======
+V1 API::
++
+====
+[source,bash]
+----
+curl 'http://localhost:8983/solr/admin/collections?action=LISTALIASES'
+----
+====
+
+V2 API::
++
+====
[source,bash]
----
curl 'http://localhost:8983/api/aliases'
----
+====
+======
*Output*
+[tabs#listaliases-example-response]
+======
+V1 API::
++
+====
[source,json]
----
{
@@ -616,6 +639,36 @@ curl 'http://localhost:8983/api/aliases'
}
}
----
+====
+
+V2 API::
++
+====
+[source,json]
+----
+{
+ "responseHeader": {
+ "status": 0,
+ "QTime": 1
+ },
+ "aliases": {
+ "testalias1": {
+ "name": "testalias1",
+ "collections": ["collection1"],
+ "properties": {}
+ },
+ "testalias2": {
+ "name": "testalias2",
+ "collections": ["collection2", "collection1"],
+ "properties": {
+ "someKey": "someValue"
+ }
+ }
+ }
+}
+----
+====
+======
==== Getting details for a single alias
diff --git
a/solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc
b/solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc
index dcfebbfa494..4067355f48d 100644
---
a/solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc
+++
b/solr/solr-ref-guide/modules/deployment-guide/pages/collection-management.adoc
@@ -2537,6 +2537,9 @@ 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.
+The v1 API returns HTTP 400 for a missing collection.
+
=== CREATESNAPSHOT Example
*Input*
@@ -2571,6 +2574,27 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots/snapshot0' -H
*Output*
+[tabs#createsnapshot-response]
+======
+V1 API::
++
+====
+[source,json]
+----
+{
+ "responseHeader": {
+ "status": 0,
+ "QTime": 214
+ },
+ "requestid": "someAsyncId",
+ "snapshot": "snapshot0"
+}
+----
+====
+
+V2 API::
++
+====
[source,json]
----
{
@@ -2584,6 +2608,8 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots/snapshot0' -H
"followAliases": true
}
----
+====
+======
=== CREATESNAPSHOT Parameters
@@ -2627,6 +2653,7 @@ Request ID to track this action which will be
xref:configuration-guide:collectio
== LISTSNAPSHOTS: List all snapshots for a collection
Lists all the snapshots taken of a collection.
+The v2 API returns HTTP 404 if the collection does not exist; the v1 API
returns HTTP 400.
=== LISTSNAPSHOTS Example
@@ -2641,7 +2668,7 @@ V1 API::
====
[source,bash]
----
-http://localhost:8983/solr/admin/collections?action=LISTSNAPSHOTS&collection=techproducts
+http://localhost:8983/solr/admin/collections?action=LISTSNAPSHOTS&collection=techproducts&json.nl=map
----
====
@@ -2657,6 +2684,15 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots'
*Output*
+The responses below show a snapshot containing one shard with one replica.
+The v1 request uses `json.nl=map` to render named lists as JSON objects.
+The v1 metadata contains a `replicas` map keyed by core name; v2 uses a
`replicaSnapshots` array and a `shards` list.
+
+[tabs#listsnapshots-response]
+======
+V1 API::
++
+====
[source,json]
----
{
@@ -2669,13 +2705,13 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots'
"name": "snapshot0",
"status": "Successful",
"creationDate": 1677985318116,
- "replicaSnapshots": [
- {
- "coreName": "techproducts_shard1_replica_n6",
+ "replicas": {
+ "techproducts_shard1_replica_n6": {
+ "core": "techproducts_shard1_replica_n6",
"indexDirPath":
"/path/to/solr/dir/node1/solr/techproducts_shard1_replica_n6/data/index/",
- "generationNumber": 2,
+ "generation": 2,
+ "shard_id": "shard1",
"leader": true,
- "shardId": "shard1",
"files": [
"_0.si",
"_0.fdm",
@@ -2690,12 +2726,35 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots'
"_0_Lucene90_0.tmd",
"_0.fnm"
]
- },
+ }
+ }
+ }
+ }
+}
+----
+====
+
+V2 API::
++
+====
+[source,json]
+----
+{
+ "responseHeader": {
+ "status": 0,
+ "QTime": 2
+ },
+ "snapshots": {
+ "snapshot0": {
+ "name": "snapshot0",
+ "status": "Successful",
+ "creationDate": 1677985318116,
+ "replicaSnapshots": [
{
- "coreName": "techproducts_shard1_replica_n2",
- "indexDirPath":
"/path/to/solr/dir/node2/solr/techproducts_shard1_replica_n2/data/index/",
+ "coreName": "techproducts_shard1_replica_n6",
+ "indexDirPath":
"/path/to/solr/dir/node1/solr/techproducts_shard1_replica_n6/data/index/",
"generationNumber": 2,
- "leader": false,
+ "leader": true,
"shardId": "shard1",
"files": [
"_0.si",
@@ -2711,37 +2770,17 @@ curl
'http://localhost:8983/api/collections/techproducts/snapshots'
"_0_Lucene90_0.tmd",
"_0.fnm"
]
- },
- {
- "coreName": "techproducts_shard2_replica_n4",
- "indexDirPath":
"/path/to/solr/dir/node1/solr/techproducts_shard2_replica_n4/data/index/",
- "generationNumber": 6,
- "leader": true,
- "shardId": "shard2",
- "files": [
- "segments_6"
- ]
- },
- {
- "coreName": "techproducts_shard2_replica_n1",
- "indexDirPath":
"/path/to/solr/dir/node2/solr/techproducts_shard2_replica_n1/data/index/",
- "generationNumber": 6,
- "leader": false,
- "shardId": "shard2",
- "files": [
- "segments_6"
- ]
}
],
"shards": [
- "shard2",
"shard1"
]
}
}
}
-
----
+====
+======
=== LISTSNAPSHOTS Parameters
@@ -2759,6 +2798,9 @@ The name of the collection to create a snapshot for.
Deletes a snapshot taken of a specified collection.
+The v2 API returns HTTP 404 if the collection or snapshot does not exist.
+The v1 API returns HTTP 400 for a missing collection and treats deletion of a
missing snapshot as a successful no-op.
+
=== DELETESNAPSHOT Example
*Input*
@@ -2788,6 +2830,8 @@ curl -X DELETE
'http://localhost:8983/api/collections/techproducts/snapshots/sna
*Output*
+The response fields are the same for v1 and v2.
+
[source,json]
----
{
diff --git
a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc
b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc
index 184aee18521..a1229fd6429 100644
---
a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc
+++
b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-11.adoc
@@ -25,6 +25,19 @@ This page highlights the most important changes including
new features and chang
Before starting an upgrade to this version of Solr, please be sure to review
all information about changes from the version you are currently on up to this
one, to include the minor version number changes as well.
For example, if you are currently using Solr 10.1, you should review changes
made in all subsequent 10.x releases in addition to the 11.0-specific changes
on this page.
+== API Changes
+
+=== V2 alias and collection snapshot responses
+
+`GET /api/aliases` now returns an object for each alias, containing its
`name`, a `collections` array, and a `properties` map.
+The separate top-level `properties` map has been removed from this v2 response.
+See xref:deployment-guide:alias-management.adoc#listaliases[LISTALIASES] for
examples of both API versions.
+
+V2 collection snapshot creation responses now include `collection` and
`followAliases` consistently in JSON, XML, and Javabin.
+The v2 snapshot APIs return HTTP 404 for missing collections, and v2 snapshot
deletion also returns HTTP 404 for a missing snapshot.
+The v1 response formats and error codes are unchanged.
+See xref:deployment-guide:collection-management.adoc#createsnapshot[collection
snapshots] for examples.
+
== Removed Features
=== Overseer Roles API
diff --git
a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCollectionsScreenTest.java
b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCollectionsScreenTest.java
index 83316587a81..0609a5ec905 100644
---
a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCollectionsScreenTest.java
+++
b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCollectionsScreenTest.java
@@ -32,10 +32,12 @@ import org.openqa.selenium.WebElement;
public class AdminUiCollectionsScreenTest extends AdminUiTestBase {
private static final String COLLECTION = "collscreen";
+ private static final String ALIAS_COLLECTION = "collscreen_alias_target";
@BeforeClass
public static void setupCollection() throws Exception {
createFixtureCollection(COLLECTION, 1, 1);
+ createFixtureCollection(ALIAS_COLLECTION, 1, 1);
}
@Test
@@ -129,6 +131,52 @@ public class AdminUiCollectionsScreenTest extends
AdminUiTestBase {
assertNoSevereConsoleErrors();
}
+ @Test
+ public void testAliasCollectionsAndPropertiesDisplay() throws Exception {
+ String alias = "uimulticollectionalias";
+ CollectionAdminRequest.createAlias(alias, COLLECTION + "," +
ALIAS_COLLECTION)
+ .process(cluster.getSolrClient());
+ try {
+ CollectionAdminRequest.setAliasProperty(alias)
+ .addProperty("description", "Multiple collection alias")
+ .process(cluster.getSolrClient());
+ CollectionAdminResponse response =
+ new
CollectionAdminRequest.ListAliases().process(cluster.getSolrClient());
+ List<String> collections =
List.of(response.getAliases().get(alias).split(","));
+ String description =
response.getAliasProperties().get(alias).get("description");
+
+ openPage(alias + "/alias-overview", By.id("dashboard"));
+ waitFor(By.cssSelector("#collection-menu .query a[href='#/" + alias +
"/query']"));
+ for (String page : List.of("analysis", "documents", "paramsets",
"files", "schema")) {
+ assertFalse(
+ page + " should be hidden for an alias with multiple collections",
+ driver.findElement(By.cssSelector("#collection-menu ." +
page)).isDisplayed());
+ }
+
+ openPage("~collections/alias_" + alias, By.id("collections"));
+ waitForTextContains(By.cssSelector("#alias-data h2"), alias);
+ By collectionLinks = By.cssSelector("#alias-data dd a");
+ waitUntil(
+ "each aliased collection should have its own link",
+ () -> driver.findElements(collectionLinks).size() ==
collections.size());
+ List<WebElement> links = driver.findElements(collectionLinks);
+ for (int i = 0; i < collections.size(); i++) {
+ assertEquals(collections.get(i), links.get(i).getText());
+ assertTrue(
+ links.get(i).getAttribute("href").endsWith("#~collections/" +
collections.get(i)));
+ }
+ waitForTextContains(
+
By.xpath("//div[@id='alias-data']//dt[span='description']/following-sibling::dd[1]"),
+ description);
+
+ click(collectionLinks);
+ waitForTextContains(By.cssSelector("#collection-data h2"),
collections.getFirst());
+ assertNoSevereConsoleErrors();
+ } finally {
+
CollectionAdminRequest.deleteAlias(alias).process(cluster.getSolrClient());
+ }
+ }
+
@Test
public void testAddAndDeleteReplicaViaUi() throws Exception {
openPage("~collections/" + COLLECTION, By.id("collections"));
diff --git a/solr/webapp/web/js/angular/app.js
b/solr/webapp/web/js/angular/app.js
index aabe50a0c8e..cda12fc932f 100644
--- a/solr/webapp/web/js/angular/app.js
+++ b/solr/webapp/web/js/angular/app.js
@@ -643,11 +643,8 @@ solrAdminApp.controller('MainController', function($scope,
$route, $rootScope, $
if (error) { ApiErrorHandler.handle(response); return; }
$scope.aliases = [];
for (var key in adata.aliases) {
- var props = {};
- if (key in adata.properties) {
- props = adata.properties[key];
- }
- var alias = {name: key, collections: adata.aliases[key],
type: 'alias', properties: props};
+ var details = adata.aliases[key];
+ var alias = {name: details.name, collections:
details.collections, type: 'alias', properties: details.properties};
$scope.aliases.push(alias);
if (pageType == Constants.IS_COLLECTION_PAGE && alias.name
== currentCollectionName) {
$scope.currentCollection = alias;
@@ -790,7 +787,7 @@ solrAdminApp.controller('MainController', function($scope,
$route, $rootScope, $
};
$scope.isMultiDestAlias = function(selectedColl) {
- return selectedColl && selectedColl.type === 'alias' &&
selectedColl.collections.includes(',');
+ return selectedColl && selectedColl.type === 'alias' &&
selectedColl.collections.length > 1;
};
$scope.ping = function() {
diff --git a/solr/webapp/web/js/angular/controllers/collections.js
b/solr/webapp/web/js/angular/controllers/collections.js
index 76c08a792d9..57ce3158921 100644
--- a/solr/webapp/web/js/angular/controllers/collections.js
+++ b/solr/webapp/web/js/angular/controllers/collections.js
@@ -56,13 +56,10 @@ solrAdminApp.controller('CollectionsController',
// TODO: Population of aliases array duplicated in app.js
$scope.aliases = [];
for (var key in adata.aliases) {
- var props = {};
- if (key in adata.properties) {
- props = adata.properties[key];
- }
- var alias = {name: key, collections: adata.aliases[key],
type: 'alias', properties: props};
+ var details = adata.aliases[key];
+ var alias = {name: details.name, collections:
details.collections, type: 'alias', properties: details.properties};
$scope.aliases.push(alias);
- if ($routeParams.collection == 'alias_' + key) {
+ if ($routeParams.collection == 'alias_' + alias.name) {
$scope.collection = alias;
}
}
diff --git a/solr/webapp/web/partials/alias_overview.html
b/solr/webapp/web/partials/alias_overview.html
index 0cf8124b531..b5dc4878d66 100644
--- a/solr/webapp/web/partials/alias_overview.html
+++ b/solr/webapp/web/partials/alias_overview.html
@@ -28,7 +28,7 @@ limitations under the License.
<dt><span>Collections:</span></dt>
<dd>
- <span ng-repeat="coll in (selectedCollection.collections |
splitByComma)">
+ <span ng-repeat="coll in selectedCollection.collections">
<a href="#~collections/{{coll}}">{{coll}}</a>{{$last ? '' : ',
'}}
</span>
</dd>
diff --git a/solr/webapp/web/partials/collections.html
b/solr/webapp/web/partials/collections.html
index 0ab8ce6b8fa..16032cd207c 100644
--- a/solr/webapp/web/partials/collections.html
+++ b/solr/webapp/web/partials/collections.html
@@ -189,7 +189,7 @@ limitations under the License.
<dl class="clearfix">
<dt><span>Collections:</span></dt>
<dd>
- <span ng-repeat="coll in (collection.collections |
splitByComma)">
+ <span ng-repeat="coll in collection.collections">
<a href="#~collections/{{coll}}">{{coll}}</a>{{$last ? ''
: ', '}}
</span>
</dd>