Skip to content

Commit e997ae8

Browse files
authored
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.
1 parent c44af90 commit e997ae8

32 files changed

Lines changed: 959 additions & 315 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
title: >-
2+
Fix v2 alias detail and collection snapshot creation requests returning HTTP 405.
3+
Alias listings now return the same per-alias structure as the detail view,
4+
including a collections array and properties; the Admin UI supports this format.
5+
Align snapshot responses and error handling with v2 conventions, and migrate
6+
the snapshot CLI to these APIs. The CLI explains when a snapshot is already absent
7+
and returns a nonzero exit status for other deletion errors.
8+
Fix asynchronous collection snapshot creation while preserving v1 response formats.
9+
type: fixed
10+
authors:
11+
- name: Eric Pugh
12+
links:
13+
- name: SOLR-17731
14+
url: https://issues.apache.org/jira/browse/SOLR-17731

‎dev-docs/apis-v2-conventions.adoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Don't settle for a bare `SolrJerseyResponse` if the underlying operation actuall
160160

161161
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:
162162

163-
* `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>`).
163+
* `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>`).
164164
* `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`).
165165

166166
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.

‎solr/api/src/java/org/apache/solr/client/api/endpoint/CollectionSnapshotApis.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ CreateCollectionSnapshotResponse createCollectionSnapshot(
5353
throws Exception;
5454
}
5555

56-
@Path("/collections/{collName}/snapshots/{snapshotName}")
56+
@Path("/collections/{collName}/snapshots")
5757
interface Delete {
5858
@DELETE
59+
@Path("/{snapshotName}")
5960
@Operation(
6061
summary = "Delete an existing collection-snapshot by name.",
6162
tags = {"collection-snapshots"})

‎solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
import jakarta.ws.rs.QueryParam;
2626
import org.apache.solr.client.api.model.AsyncJerseyResponse;
2727

28-
@Path("/aliases/{aliasName}")
28+
@Path("/aliases")
2929
public interface DeleteAliasApi {
3030

3131
@DELETE
32+
@Path("/{aliasName}")
3233
@Operation(
3334
summary = "Deletes an alias by its name",
3435
tags = {"aliases"})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.solr.client.api.model;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import java.util.List;
21+
import org.apache.solr.client.api.util.ReflectWritable;
22+
23+
/** Metadata for a collection snapshot and its replica snapshots. */
24+
public class CollectionSnapshotMetadata implements ReflectWritable {
25+
@JsonProperty public String name;
26+
@JsonProperty public String status;
27+
@JsonProperty public Long creationDate;
28+
@JsonProperty public List<ReplicaSnapshotMetadata> replicaSnapshots;
29+
@JsonProperty public List<String> shards;
30+
31+
/** The index commit captured on a replica. */
32+
public static class ReplicaSnapshotMetadata implements ReflectWritable {
33+
@JsonProperty public String coreName;
34+
@JsonProperty public String indexDirPath;
35+
@JsonProperty public long generationNumber;
36+
@JsonProperty public boolean leader;
37+
@JsonProperty public String shardId;
38+
@JsonProperty public List<String> files;
39+
}
40+
}

‎solr/api/src/java/org/apache/solr/client/api/model/CreateCollectionSnapshotResponse.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
public class CreateCollectionSnapshotResponse extends SubResponseAccumulatingJerseyResponse {
2323
@Schema(description = "The name of the collection.")
24+
@JsonProperty("collection")
2425
public String collection;
2526

2627
@Schema(description = "The name of the snapshot to be created.")
2728
@JsonProperty("snapshot")
2829
public String snapshotName;
2930

3031
@Schema(description = "A flag that treats the collName parameter as a collection alias.")
32+
@JsonProperty("followAliases")
3133
public boolean followAliases;
3234
}

‎solr/api/src/java/org/apache/solr/client/api/model/ListAliasesResponse.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import java.util.Map;
2121

22+
/** Response listing details for all collection aliases. */
2223
public class ListAliasesResponse extends SolrJerseyResponse {
2324
@JsonProperty("aliases")
24-
public Map<String, String> aliases;
25-
26-
@JsonProperty("properties")
27-
public Map<String, Map<String, String>> properties;
25+
public Map<String, GetAliasByNameResponse> aliases;
2826
}

‎solr/api/src/java/org/apache/solr/client/api/model/ListCollectionSnapshotsResponse.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
import java.util.Map;
2222

2323
/** The Response for the v2 "list collection snapshots" API */
24-
public class ListCollectionSnapshotsResponse extends AsyncJerseyResponse {
24+
public class ListCollectionSnapshotsResponse extends SolrJerseyResponse {
2525

26-
// TODO In practice, map values are of the CollectionSnapshotMetaData type, but that cannot be
27-
// used here until the class is made into more of a POJO and can join the 'api' module here
2826
@Schema(description = "The snapshots for the collection.")
2927
@JsonProperty("snapshots")
30-
public Map<String, Object> snapshots;
28+
public Map<String, CollectionSnapshotMetadata> snapshots;
3129
}

‎solr/core/src/java/org/apache/solr/cli/SnapshotCreateTool.java‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import org.apache.commons.cli.Option;
2121
import org.apache.commons.cli.Options;
2222
import org.apache.solr.client.solrj.SolrClient;
23-
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
24-
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
23+
import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
2524

2625
/** Supports snapshot-create command in the bin/solr script. */
2726
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -118,15 +117,10 @@ void createSnapshot(SnapshotCreateParams params) throws Exception {
118117
}
119118

120119
public void createSnapshot(SolrClient solrClient, String collectionName, String snapshotName) {
121-
CollectionAdminRequest.CreateSnapshot createSnapshot =
122-
new CollectionAdminRequest.CreateSnapshot(collectionName, snapshotName);
123-
CollectionAdminResponse resp;
120+
var createSnapshot =
121+
new CollectionSnapshotsApi.CreateCollectionSnapshot(collectionName, snapshotName);
124122
try {
125-
resp = createSnapshot.process(solrClient);
126-
if (resp.getStatus() != 0) {
127-
throw new IllegalStateException(
128-
"The CREATESNAPSHOT request failed. The status code is " + resp.getStatus());
129-
}
123+
createSnapshot.process(solrClient);
130124
echo(
131125
"Successfully created snapshot with name "
132126
+ snapshotName

‎solr/core/src/java/org/apache/solr/cli/SnapshotDeleteTool.java‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
*/
1717
package org.apache.solr.cli;
1818

19+
import static org.apache.solr.common.SolrException.ErrorCode.NOT_FOUND;
20+
1921
import org.apache.commons.cli.CommandLine;
2022
import org.apache.commons.cli.Option;
2123
import org.apache.commons.cli.Options;
2224
import org.apache.solr.client.solrj.SolrClient;
23-
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
24-
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
25+
import org.apache.solr.client.solrj.request.CollectionSnapshotsApi;
26+
import org.apache.solr.common.SolrException;
2527

2628
/** Supports snapshot-delete command in the bin/solr script. */
2729
@SuppressWarnings("UnnecessarilyFullyQualified")
@@ -118,29 +120,50 @@ void deleteSnapshot(SnapshotDeleteParams params) throws Exception {
118120
}
119121

120122
public void deleteSnapshot(SolrClient solrClient, String collectionName, String snapshotName) {
121-
CollectionAdminRequest.DeleteSnapshot deleteSnapshot =
122-
new CollectionAdminRequest.DeleteSnapshot(collectionName, snapshotName);
123-
CollectionAdminResponse resp;
123+
var deleteSnapshot =
124+
new CollectionSnapshotsApi.DeleteCollectionSnapshot(collectionName, snapshotName);
124125
try {
125-
resp = deleteSnapshot.process(solrClient);
126-
if (resp.getStatus() != 0) {
127-
throw new IllegalStateException(
128-
"The DELETESNAPSHOT request failed. The status code is " + resp.getStatus());
129-
}
126+
deleteSnapshot.process(solrClient);
130127
echo(
131128
"Successfully deleted snapshot with name "
132129
+ snapshotName
133130
+ " for collection "
134131
+ collectionName);
135132

136133
} catch (Exception e) {
137-
echo(
134+
if (isMissingSnapshot(solrClient, collectionName, snapshotName, e)) {
135+
echo(
136+
"Snapshot with name "
137+
+ snapshotName
138+
+ " does not exist for collection "
139+
+ collectionName
140+
+ "; nothing to delete.");
141+
return;
142+
}
143+
throw new IllegalStateException(
138144
"Failed to delete a snapshot with name "
139145
+ snapshotName
140146
+ " for collection "
141147
+ collectionName
142148
+ " due to following error : "
143-
+ e.getLocalizedMessage());
149+
+ e.getLocalizedMessage(),
150+
e);
151+
}
152+
}
153+
154+
private static boolean isMissingSnapshot(
155+
SolrClient solrClient, String collectionName, String snapshotName, Exception failure) {
156+
if (!(failure instanceof SolrException error) || error.code() != NOT_FOUND.code) {
157+
return false;
158+
}
159+
try {
160+
return !new CollectionSnapshotsApi.ListSnapshots(collectionName)
161+
.process(solrClient)
162+
.snapshots
163+
.containsKey(snapshotName);
164+
} catch (Exception lookupFailure) {
165+
failure.addSuppressed(lookupFailure);
166+
return false;
144167
}
145168
}
146169

0 commit comments

Comments
 (0)