-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
REST endpoint and tests for data stream migration #64415
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
35 changes: 35 additions & 0 deletions
35
...src/main/java/org/elasticsearch/xpack/datastreams/rest/RestMigrateToDataStreamAction.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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.datastreams.rest; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
import org.elasticsearch.xpack.core.MigrateToDataStreamAction; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class RestMigrateToDataStreamAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "migrate_to_data_stream_action"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(RestRequest.Method.POST, "/_data_stream/_migrate/{name}")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
MigrateToDataStreamAction.Request req = new MigrateToDataStreamAction.Request(request.param("name")); | ||
return channel -> client.execute(MigrateToDataStreamAction.INSTANCE, req, new RestToXContentListener<>(channel)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
x-pack/plugin/src/test/resources/rest-api-spec/api/indices.migrate_to_data_stream.json
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,27 @@ | ||
{ | ||
"indices.migrate_to_data_stream":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", | ||
"description":"Migrates an alias to a data stream" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_data_stream/_migrate/{name}", | ||
"methods":[ | ||
"POST" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the alias to migrate" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...k/plugin/src/test/resources/rest-api-spec/test/data_stream/130_migrate_to_data_stream.yml
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,69 @@ | ||
--- | ||
"Migrate to data stream": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "change to 7.10.99 after backport" | ||
features: allowed_warnings | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [my-template1] has index patterns [migrate-me-to-data-stream] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template1] will take precedence during new index creation" | ||
indices.put_index_template: | ||
name: my-template1 | ||
body: | ||
index_patterns: [migrate-me-to-data-stream] | ||
data_stream: {} | ||
|
||
- do: | ||
indices.create: | ||
index: test_index1 | ||
body: | ||
aliases: | ||
migrate-me-to-data-stream: | ||
is_write_index: true | ||
|
||
- do: | ||
index: | ||
index: test_index1 | ||
body: { "foo": "bar1", "@timestamp": "2009-11-15T14:12:12" } | ||
|
||
- do: | ||
indices.create: | ||
index: test_index2 | ||
body: | ||
aliases: | ||
migrate-me-to-data-stream: {} | ||
|
||
- do: | ||
index: | ||
index: test_index2 | ||
body: { "foo": "bar2", "@timestamp": "2009-11-15T14:12:13" } | ||
|
||
- do: | ||
indices.migrate_to_data_stream: | ||
name: migrate-me-to-data-stream | ||
- is_true: acknowledged | ||
|
||
- do: | ||
indices.resolve_index: | ||
name: ['test_index*','migrate-me-to-data-stream*'] | ||
expand_wildcards: [all] | ||
|
||
- match: {indices.0.name: test_index1} | ||
- match: {indices.0.attributes.0: hidden} | ||
- match: {indices.0.attributes.1: open} | ||
- match: {indices.0.data_stream: migrate-me-to-data-stream} | ||
- match: {indices.1.name: test_index2} | ||
- match: {indices.1.attributes.0: hidden} | ||
- match: {indices.1.attributes.1: open} | ||
- match: {indices.1.data_stream: migrate-me-to-data-stream} | ||
- length: {aliases: 0} | ||
- match: {data_streams.0.name: migrate-me-to-data-stream} | ||
- match: {data_streams.0.backing_indices.0: test_index2} | ||
- match: {data_streams.0.backing_indices.1: test_index1} | ||
- match: {data_streams.0.timestamp_field: "@timestamp"} | ||
|
||
- do: | ||
indices.delete_data_stream: | ||
name: migrate-me-to-data-stream | ||
- is_true: acknowledged |
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.
I think
change to 7.10.99 after backport
should bechange to 7.9.99 after backport
?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.
I don't think the migrate feature will be available until the 7.11 release?
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.
🤦 true, I somehow always think the feature makes it into the 7.10 release :)