Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
540ff1d
bck
original-brownbear Nov 28, 2019
e8bfdaa
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Nov 28, 2019
32fb757
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 2, 2019
3067bc5
works
original-brownbear Dec 2, 2019
add63fd
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 2, 2019
703e727
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 3, 2019
ce32074
bck
original-brownbear Dec 3, 2019
7ff1851
bck
original-brownbear Dec 3, 2019
5cf930b
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 3, 2019
e7428e5
bck
original-brownbear Dec 3, 2019
7588a93
bck
original-brownbear Dec 3, 2019
1984cc0
more multi
original-brownbear Dec 3, 2019
e91a873
works
original-brownbear Dec 3, 2019
116f95f
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 3, 2019
e881459
bck
original-brownbear Dec 3, 2019
2cc0c74
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 10, 2019
609daad
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 10, 2019
e72a50b
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 10, 2019
ffe5adb
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 10, 2019
488f4e7
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 12, 2019
92ab9d5
bck
original-brownbear Dec 12, 2019
f192cb5
Merge remote-tracking branch 'elastic/master' into multi-delete-snapshot
original-brownbear Dec 12, 2019
821c36a
bck
original-brownbear Dec 12, 2019
522b6fa
drop it for now
original-brownbear Dec 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
Expand Down Expand Up @@ -335,13 +335,13 @@ public Cancellable restoreAsync(RestoreSnapshotRequest restoreSnapshotRequest, R
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
* API on elastic.co</a>
*
* @param deleteSnapshotRequest the request
* @param deleteSnapshotsRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public AcknowledgedResponse delete(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(deleteSnapshotRequest,
public AcknowledgedResponse delete(DeleteSnapshotsRequest deleteSnapshotsRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(deleteSnapshotsRequest,
SnapshotRequestConverters::deleteSnapshot, options,
AcknowledgedResponse::fromXContent, emptySet());
}
Expand All @@ -351,14 +351,14 @@ public AcknowledgedResponse delete(DeleteSnapshotRequest deleteSnapshotRequest,
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
* API on elastic.co</a>
*
* @param deleteSnapshotRequest the request
* @param deleteSnapshotsRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable deleteAsync(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options,
public Cancellable deleteAsync(DeleteSnapshotsRequest deleteSnapshotsRequest, RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(deleteSnapshotRequest,
return restHighLevelClient.performRequestAsyncAndParseEntity(deleteSnapshotsRequest,
SnapshotRequestConverters::deleteSnapshot, options,
AcknowledgedResponse::fromXContent, listener, emptySet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest;
Expand Down Expand Up @@ -173,15 +173,15 @@ static Request restoreSnapshot(RestoreSnapshotRequest restoreSnapshotRequest) th
return request;
}

static Request deleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) {
static Request deleteSnapshot(DeleteSnapshotsRequest deleteSnapshotsRequest) {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot")
.addPathPart(deleteSnapshotRequest.repository())
.addPathPart(deleteSnapshotRequest.snapshot())
.addPathPart(deleteSnapshotsRequest.repository())
.addCommaSeparatedPathParts(deleteSnapshotsRequest.snapshots())
.build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(deleteSnapshotRequest.masterNodeTimeout());
parameters.withMasterTimeout(deleteSnapshotsRequest.masterNodeTimeout());
request.addParameters(parameters.asMap());
return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void testCreateSnapshot() throws IOException {
if (waitForCompletion == false) {
// If we don't wait for the snapshot to complete we have to cancel it to not leak the snapshot task
AcknowledgedResponse deleteResponse = execute(
new DeleteSnapshotRequest(repository, snapshot),
new DeleteSnapshotsRequest(repository, snapshot),
highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync
);
assertTrue(deleteResponse.isAcknowledged());
Expand Down Expand Up @@ -301,7 +301,7 @@ public void testDeleteSnapshot() throws IOException {
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(RestStatus.OK, createSnapshotResponse.status());

DeleteSnapshotRequest request = new DeleteSnapshotRequest(repository, snapshot);
DeleteSnapshotsRequest request = new DeleteSnapshotsRequest(repository, snapshot);
AcknowledgedResponse response = execute(request, highLevelClient().snapshot()::delete, highLevelClient().snapshot()::deleteAsync);

assertTrue(response.isAcknowledged());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest;
Expand Down Expand Up @@ -267,12 +267,12 @@ public void testDeleteSnapshot() {

String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s", repository, snapshot);

DeleteSnapshotRequest deleteSnapshotRequest = new DeleteSnapshotRequest();
deleteSnapshotRequest.repository(repository);
deleteSnapshotRequest.snapshot(snapshot);
RequestConvertersTests.setRandomMasterTimeout(deleteSnapshotRequest, expectedParams);
DeleteSnapshotsRequest deleteSnapshotsRequest = new DeleteSnapshotsRequest();
deleteSnapshotsRequest.repository(repository);
deleteSnapshotsRequest.snapshots(new String[]{snapshot});
RequestConvertersTests.setRandomMasterTimeout(deleteSnapshotsRequest, expectedParams);

Request request = SnapshotRequestConverters.deleteSnapshot(deleteSnapshotRequest);
Request request = SnapshotRequestConverters.deleteSnapshot(deleteSnapshotsRequest);
assertThat(request.getEndpoint(), equalTo(endpoint));
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
assertThat(request.getParameters(), equalTo(expectedParams));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
Expand Down Expand Up @@ -752,8 +752,7 @@ public void testSnapshotDeleteSnapshot() throws IOException {
createTestSnapshots();

// tag::delete-snapshot-request
DeleteSnapshotRequest request = new DeleteSnapshotRequest(repositoryName);
request.snapshot(snapshotName);
DeleteSnapshotsRequest request = new DeleteSnapshotsRequest(repositoryName, snapshotName);
// end::delete-snapshot-request

// tag::delete-snapshot-request-masterTimeout
Expand All @@ -774,7 +773,7 @@ public void testSnapshotDeleteSnapshot() throws IOException {
public void testSnapshotDeleteSnapshotAsync() throws InterruptedException {
RestHighLevelClient client = highLevelClient();
{
DeleteSnapshotRequest request = new DeleteSnapshotRequest();
DeleteSnapshotsRequest request = new DeleteSnapshotsRequest();

// tag::delete-snapshot-execute-listener
ActionListener<AcknowledgedResponse> listener =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void testUrlRepository() throws Exception {
assertThat(getSnapshotsResponse.getSnapshots("url-repo").size(), equalTo(1));

logger.info("--> delete snapshot");
AcknowledgedResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get();
AcknowledgedResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshots("test-repo",
new String[]{"test-snap"}).get();
assertAcked(deleteSnapshotResponse);

logger.info("--> list available shapshot again, no snapshots should be returned");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
/**
* Delete snapshot request builder
*/
public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteSnapshotRequest,
public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteSnapshotsRequest,
AcknowledgedResponse, DeleteSnapshotRequestBuilder> {

/**
* Constructs delete snapshot request builder
*/
public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action) {
super(client, action, new DeleteSnapshotRequest());
super(client, action, new DeleteSnapshotsRequest());
}

/**
* Constructs delete snapshot request builder with specified repository and snapshot names
*/
public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action, String repository, String snapshot) {
super(client, action, new DeleteSnapshotRequest(repository, snapshot));
public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action, String repository, String[] snapshots) {
super(client, action, new DeleteSnapshotsRequest(repository, snapshots));
}

/**
Expand All @@ -57,11 +57,11 @@ public DeleteSnapshotRequestBuilder setRepository(String repository) {
/**
* Sets the snapshot name
*
* @param snapshot snapshot name
* @param snapshots snapshot names
* @return this builder
*/
public DeleteSnapshotRequestBuilder setSnapshot(String snapshot) {
request.snapshot(snapshot);
public DeleteSnapshotRequestBuilder setSnapshots(String... snapshots) {
request.snapshots(snapshots);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.action.admin.cluster.snapshots.delete;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeRequest;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -35,16 +36,18 @@
* files that are associated with this particular snapshot. All files that are shared with
* at least one other existing snapshot are left intact.
*/
public class DeleteSnapshotRequest extends MasterNodeRequest<DeleteSnapshotRequest> {
public class DeleteSnapshotsRequest extends MasterNodeRequest<DeleteSnapshotsRequest> {

public static final Version MULTI_DELETE_VERSION = Version.V_8_0_0;

private String repository;

private String snapshot;
private String[] snapshots;

/**
* Constructs a new delete snapshots request
*/
public DeleteSnapshotRequest() {
public DeleteSnapshotsRequest() {
}

/**
Expand All @@ -53,31 +56,53 @@ public DeleteSnapshotRequest() {
* @param repository repository name
* @param snapshot snapshot name
*/
public DeleteSnapshotRequest(String repository, String snapshot) {
public DeleteSnapshotsRequest(String repository, String snapshot) {
this(repository, new String[]{snapshot});
}

/**
* Constructs a new delete snapshots request with repository and snapshot name
*
* @param repository repository name
* @param snapshots snapshot names
*/
public DeleteSnapshotsRequest(String repository, String[] snapshots) {
this.repository = repository;
this.snapshot = snapshot;
this.snapshots = snapshots;
}

/**
* Constructs a new delete snapshots request with repository name
*
* @param repository repository name
*/
public DeleteSnapshotRequest(String repository) {
public DeleteSnapshotsRequest(String repository) {
this.repository = repository;
}

public DeleteSnapshotRequest(StreamInput in) throws IOException {
public DeleteSnapshotsRequest(StreamInput in) throws IOException {
super(in);
repository = in.readString();
snapshot = in.readString();
if (in.getVersion().onOrAfter(MULTI_DELETE_VERSION)) {
snapshots = in.readStringArray();
} else {
snapshots = new String[] {in.readString()};
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(repository);
out.writeString(snapshot);
if (out.getVersion().onOrAfter(MULTI_DELETE_VERSION)) {
out.writeStringArray(snapshots);
} else {
if (snapshots.length != 1) {
throw new IllegalArgumentException(
"Can't write snapshot delete with more than one snapshot to version [" + out.getVersion() + "]");
}
out.writeString(snapshots[0]);
}
}

@Override
Expand All @@ -86,14 +111,14 @@ public ActionRequestValidationException validate() {
if (repository == null) {
validationException = addValidationError("repository is missing", validationException);
}
if (snapshot == null) {
if (snapshots == null || snapshots.length == 0) {
validationException = addValidationError("snapshot is missing", validationException);
}
return validationException;
}


public DeleteSnapshotRequest repository(String repository) {
public DeleteSnapshotsRequest repository(String repository) {
this.repository = repository;
return this;
}
Expand All @@ -112,17 +137,17 @@ public String repository() {
*
* @return repository name
*/
public String snapshot() {
return this.snapshot;
public String[] snapshots() {
return this.snapshots;
}

/**
* Sets snapshot name
*
* @return this request
*/
public DeleteSnapshotRequest snapshot(String snapshot) {
this.snapshot = snapshot;
public DeleteSnapshotsRequest snapshots(String[] snapshots) {
this.snapshots = snapshots;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
/**
* Transport action for delete snapshot operation
*/
public class TransportDeleteSnapshotAction extends TransportMasterNodeAction<DeleteSnapshotRequest, AcknowledgedResponse> {
public class TransportDeleteSnapshotAction extends TransportMasterNodeAction<DeleteSnapshotsRequest, AcknowledgedResponse> {
private final SnapshotsService snapshotsService;

@Inject
public TransportDeleteSnapshotAction(TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, SnapshotsService snapshotsService, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) {
super(DeleteSnapshotAction.NAME, transportService, clusterService, threadPool, actionFilters,
DeleteSnapshotRequest::new,indexNameExpressionResolver);
DeleteSnapshotsRequest::new,indexNameExpressionResolver);
this.snapshotsService = snapshotsService;
}

Expand All @@ -63,15 +63,15 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException {
}

@Override
protected ClusterBlockException checkBlock(DeleteSnapshotRequest request, ClusterState state) {
protected ClusterBlockException checkBlock(DeleteSnapshotsRequest request, ClusterState state) {
// Cluster is not affected but we look up repositories in metadata
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}

@Override
protected void masterOperation(Task task, final DeleteSnapshotRequest request, ClusterState state,
protected void masterOperation(Task task, final DeleteSnapshotsRequest request, ClusterState state,
final ActionListener<AcknowledgedResponse> listener) {
snapshotsService.deleteSnapshot(request.repository(), request.snapshot(),
snapshotsService.deleteSnapshots(request.repository(), request.snapshots(),
ActionListener.map(listener, v -> new AcknowledgedResponse(true)), false);
}
}
Loading