-
Notifications
You must be signed in to change notification settings - Fork 25.3k
API for adding and removing indices from a data stream #79279
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
604ffea
REST endpoint for data stream modification service
danhermann 62c067c
no one defies the checkstyle gods
danhermann 8b40466
especially not in the server module!
danhermann f485e11
Classify action as non-operator and add stub for YAML test
danhermann 2bfd2b4
add a test and a comment for IndicesOptions
danhermann 3c34705
finalize YAML test
danhermann 4acb612
more specific catch in test
danhermann 9861b37
move request class into action class, move all classes from xpack to …
danhermann 3c26d6b
add unit test for request class
danhermann 65fdd9d
address remaining review comments
danhermann 027ef7a
fix test
danhermann 8dba4a9
Merge branch 'master' into 75852_rest_endpoint
elasticmachine 8403d45
add mutateInstance test method
danhermann 2aaafdb
Merge branch 'master' into 75852_rest_endpoint
elasticmachine 50e24f7
API spec comments
danhermann 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
28 changes: 28 additions & 0 deletions
28
rest-api-spec/src/main/resources/rest-api-spec/api/indices.modify_data_stream.json
This file contains hidden or 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,28 @@ | ||
{ | ||
"indices.modify_data_stream":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", | ||
"description":"Modifies a data stream" | ||
}, | ||
"stability":"stable", | ||
"visibility":"public", | ||
"headers":{ | ||
"accept": [ "application/json"], | ||
"content_type": ["application/json"] | ||
}, | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_data_stream/_modify", | ||
"methods":["POST"] | ||
} | ||
] | ||
}, | ||
"params":{ | ||
}, | ||
"body":{ | ||
"description":"The data stream modifications", | ||
"required":true | ||
} | ||
} | ||
} |
This file contains hidden or 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
133 changes: 133 additions & 0 deletions
133
server/src/main/java/org/elasticsearch/action/datastreams/ModifyDataStreamsAction.java
This file contains hidden or 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,133 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.datastreams; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.IndicesRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.AcknowledgedRequest; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.cluster.metadata.DataStreamAction; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.xcontent.ParseField; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
public class ModifyDataStreamsAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final ModifyDataStreamsAction INSTANCE = new ModifyDataStreamsAction(); | ||
public static final String NAME = "indices:admin/data_stream/modify"; | ||
|
||
private ModifyDataStreamsAction() { | ||
super(NAME, AcknowledgedResponse::readFrom); | ||
} | ||
|
||
public static final class Request | ||
extends AcknowledgedRequest<Request> | ||
implements IndicesRequest, ToXContentObject { | ||
|
||
// relevant only for authorizing the request, so require every specified | ||
// index to exist, expand wildcards only to open indices, prohibit | ||
// wildcard expressions that resolve to zero indices, and do not attempt | ||
// to resolve expressions as aliases | ||
private static final IndicesOptions INDICES_OPTIONS = | ||
IndicesOptions.fromOptions(false, false, true, false, true, false, true, false); | ||
|
||
private final List<DataStreamAction> actions; | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
actions = in.readList(DataStreamAction::new); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeList(actions); | ||
} | ||
|
||
public Request(List<DataStreamAction> actions) { | ||
this.actions = Collections.unmodifiableList(actions); | ||
} | ||
|
||
public List<DataStreamAction> getActions() { | ||
return actions; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startArray("actions"); | ||
for (DataStreamAction action : actions) { | ||
action.toXContent(builder, params); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (actions.isEmpty()) { | ||
return addValidationError("must specify at least one data stream modification action", null); | ||
} | ||
return null; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<Request, Void> PARSER = new ConstructingObjectParser<>( | ||
"data_stream_actions", | ||
args -> new Request(((List<DataStreamAction>) args[0])) | ||
); | ||
static { | ||
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), DataStreamAction.PARSER, new ParseField("actions")); | ||
} | ||
|
||
@Override | ||
public String[] indices() { | ||
return actions.stream().map(DataStreamAction::getDataStream).toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public IndicesOptions indicesOptions() { | ||
return INDICES_OPTIONS; | ||
} | ||
|
||
@Override | ||
public boolean includeDataStreams() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || obj.getClass() != getClass()) { | ||
return false; | ||
} | ||
Request other = (Request) obj; | ||
return Arrays.equals(actions.toArray(), other.actions.toArray()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(actions); | ||
} | ||
|
||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
.../src/main/java/org/elasticsearch/action/datastreams/ModifyDataStreamsTransportAction.java
This file contains hidden or 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,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.datastreams; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.AcknowledgedTransportMasterNodeAction; | ||
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.metadata.MetadataDataStreamsService; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public class ModifyDataStreamsTransportAction extends AcknowledgedTransportMasterNodeAction< | ||
ModifyDataStreamsAction.Request> { | ||
|
||
private final MetadataDataStreamsService metadataDataStreamsService; | ||
|
||
@Inject | ||
public ModifyDataStreamsTransportAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
MetadataDataStreamsService metadataDataStreamsService | ||
) { | ||
super( | ||
ModifyDataStreamsAction.NAME, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
ModifyDataStreamsAction.Request::new, | ||
indexNameExpressionResolver, | ||
ThreadPool.Names.SAME | ||
); | ||
this.metadataDataStreamsService = metadataDataStreamsService; | ||
} | ||
|
||
@Override | ||
protected void masterOperation( | ||
Task task, | ||
ModifyDataStreamsAction.Request request, | ||
ClusterState state, | ||
ActionListener<AcknowledgedResponse> listener | ||
) throws Exception { | ||
metadataDataStreamsService.modifyDataStream(request, listener); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(ModifyDataStreamsAction.Request request, ClusterState state) { | ||
ClusterBlockException globalBlock = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); | ||
if (globalBlock != null) { | ||
return globalBlock; | ||
} | ||
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, | ||
indexNameExpressionResolver.concreteIndexNames(state, request)); | ||
} | ||
|
||
} |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.