-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Clone Snapshot Request Handling Scaffolding #63037
Merged
original-brownbear
merged 8 commits into
elastic:master
from
original-brownbear:clone-snapshot-api-2
Sep 30, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7fbe2e3
Add Clone Snapshot Request Handling Scaffolding
original-brownbear ebb9dcc
Merge remote-tracking branch 'elastic/master' into clone-snapshot-api-2
original-brownbear 756c051
fix var name
original-brownbear 3026cb6
Merge remote-tracking branch 'elastic/master' into clone-snapshot-api-2
original-brownbear 77aca29
CR comments
original-brownbear 59de423
fix up rest request
original-brownbear 2e91048
indices options
original-brownbear 7714634
fix default indices resolve
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...main/java/org/elasticsearch/action/admin/cluster/snapshots/clone/CloneSnapshotAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.clone; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
|
||
public final class CloneSnapshotAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final CloneSnapshotAction INSTANCE = new CloneSnapshotAction(); | ||
public static final String NAME = "cluster:admin/snapshot/clone"; | ||
|
||
private CloneSnapshotAction() { | ||
super(NAME, AcknowledgedResponse::new); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
...ain/java/org/elasticsearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.clone; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.IndicesRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
public class CloneSnapshotRequest extends MasterNodeRequest<CloneSnapshotRequest> implements IndicesRequest.Replaceable{ | ||
|
||
private final String repository; | ||
|
||
private final String source; | ||
|
||
private final String target; | ||
|
||
private String[] indices; | ||
|
||
private IndicesOptions indicesOptions = IndicesOptions.strictExpandHidden(); | ||
|
||
public CloneSnapshotRequest(StreamInput in) throws IOException { | ||
super(in); | ||
repository = in.readString(); | ||
source = in.readString(); | ||
target = in.readString(); | ||
indices = in.readStringArray(); | ||
indicesOptions = IndicesOptions.readIndicesOptions(in); | ||
} | ||
|
||
/** | ||
* Creates a clone snapshot request for cloning the given source snapshot's indices into the given target snapshot on the given | ||
* repository. | ||
* | ||
* @param repository repository that source snapshot belongs to and that the target snapshot will be created in | ||
* @param source source snapshot name | ||
* @param target target snapshot name | ||
* @param indices indices to clone from source to target | ||
*/ | ||
public CloneSnapshotRequest(String repository, String source, String target, String[] indices) { | ||
tlrx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.repository = repository; | ||
this.source = source; | ||
this.target = target; | ||
this.indices = indices; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(repository); | ||
out.writeString(source); | ||
out.writeString(target); | ||
out.writeStringArray(indices); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also serialize indices options |
||
indicesOptions.writeIndicesOptions(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (source == null) { | ||
validationException = addValidationError("source snapshot name is missing", null); | ||
} | ||
if (target == null) { | ||
validationException = addValidationError("target snapshot name is missing", null); | ||
} | ||
if (repository == null) { | ||
validationException = addValidationError("repository is missing", validationException); | ||
} | ||
if (indices == null) { | ||
validationException = addValidationError("indices is null", validationException); | ||
} else if (indices.length == 0) { | ||
validationException = addValidationError("indices patterns are empty", validationException); | ||
} else { | ||
for (String index : indices) { | ||
if (index == null) { | ||
validationException = addValidationError("index is null", validationException); | ||
break; | ||
} | ||
} | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public String[] indices() { | ||
return this.indices; | ||
} | ||
|
||
@Override | ||
public IndicesOptions indicesOptions() { | ||
return indicesOptions; | ||
} | ||
|
||
@Override | ||
public CloneSnapshotRequest indices(String... indices) { | ||
tlrx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.indices = indices; | ||
return this; | ||
} | ||
|
||
/** | ||
* @see CloneSnapshotRequestBuilder#setIndicesOptions | ||
*/ | ||
public CloneSnapshotRequest indicesOptions(IndicesOptions indicesOptions) { | ||
this.indicesOptions = indicesOptions; | ||
return this; | ||
} | ||
|
||
public String repository() { | ||
return this.repository; | ||
} | ||
|
||
public String target() { | ||
return this.target; | ||
} | ||
|
||
public String source() { | ||
return this.source; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...a/org/elasticsearch/action/admin/cluster/snapshots/clone/CloneSnapshotRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.clone; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; | ||
import org.elasticsearch.client.ElasticsearchClient; | ||
import org.elasticsearch.common.Strings; | ||
|
||
public class CloneSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<CloneSnapshotRequest, AcknowledgedResponse, | ||
CloneSnapshotRequestBuilder> { | ||
|
||
protected CloneSnapshotRequestBuilder(ElasticsearchClient client, ActionType<AcknowledgedResponse> action, | ||
CloneSnapshotRequest request) { | ||
super(client, action, request); | ||
} | ||
|
||
public CloneSnapshotRequestBuilder(ElasticsearchClient client, ActionType<AcknowledgedResponse> action, | ||
String repository, String source, String target) { | ||
this(client, action, new CloneSnapshotRequest(repository, source, target, Strings.EMPTY_ARRAY)); | ||
} | ||
|
||
/** | ||
* Sets a list of indices that should be cloned from the source to the target snapshot | ||
* <p> | ||
* The list of indices supports multi-index syntax. For example: "+test*" ,"-test42" will clone all indices with | ||
* prefix "test" except index "test42". | ||
* | ||
* @return this builder | ||
*/ | ||
public CloneSnapshotRequestBuilder setIndices(String... indices) { | ||
tlrx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
request.indices(indices); | ||
return this; | ||
} | ||
|
||
/** | ||
* Specifies the indices options. Like what type of requested indices to ignore. For example indices that don't exist. | ||
* | ||
* @param indicesOptions the desired behaviour regarding indices options | ||
* @return this request | ||
*/ | ||
public CloneSnapshotRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { | ||
request.indicesOptions(indicesOptions); | ||
return this; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../org/elasticsearch/action/admin/cluster/snapshots/clone/TransportCloneSnapshotAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.snapshots.clone; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.block.ClusterBlockLevel; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.snapshots.SnapshotsService; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Transport action for the clone snapshot operation. | ||
*/ | ||
public final class TransportCloneSnapshotAction extends TransportMasterNodeAction<CloneSnapshotRequest, AcknowledgedResponse> { | ||
|
||
private final SnapshotsService snapshotsService; | ||
|
||
@Inject | ||
public TransportCloneSnapshotAction(TransportService transportService, ClusterService clusterService, | ||
ThreadPool threadPool, SnapshotsService snapshotsService, ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
super(CloneSnapshotAction.NAME, transportService, clusterService, threadPool, actionFilters, CloneSnapshotRequest::new, | ||
indexNameExpressionResolver); | ||
this.snapshotsService = snapshotsService; | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return ThreadPool.Names.SAME; | ||
} | ||
|
||
@Override | ||
protected AcknowledgedResponse read(StreamInput in) throws IOException { | ||
return new AcknowledgedResponse(in); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(CloneSnapshotRequest 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 CloneSnapshotRequest request, ClusterState state, | ||
final ActionListener<AcknowledgedResponse> listener) { | ||
throw new UnsupportedOperationException("not implemented yet"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we comment this for now and only uncomment it once REST integration tests and the whole feature are done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly made this active here to make sure our
RestController
can handle the shared path with the create-snapshot action. Turned it only accepts this if the parameter names are the same across both actions so I left it in place to make sure we don't break anything.I'm only going to merge this to
master
before final completion anyway, so maybe we can just leave it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did not think about this. Let's keep it as it is and wait for the full feature to be done and merged before backporting it.