Skip to content
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 2 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -38,6 +38,7 @@
import org.elasticsearch.xpack.datastreams.action.DeleteDataStreamTransportAction;
import org.elasticsearch.xpack.datastreams.action.GetDataStreamsTransportAction;
import org.elasticsearch.xpack.datastreams.mapper.DataStreamTimestampFieldMapper;
import org.elasticsearch.xpack.datastreams.rest.RestMigrateToDataStreamAction;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -76,6 +77,7 @@ public List<RestHandler> getRestHandlers(
var deleteDsAction = new RestDeleteDataStreamAction();
var getDsAction = new RestGetDataStreamsAction();
var dsStatsAction = new RestDataStreamsStatsAction();
return List.of(createDsAction, deleteDsAction, getDsAction, dsStatsAction);
var migrateAction = new RestMigrateToDataStreamAction();
return List.of(createDsAction, deleteDsAction, getDsAction, dsStatsAction, migrateAction);
}
}
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));
}
}
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":{
}
}
}
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"
Copy link
Member

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 be change to 7.9.99 after backport?

Copy link
Contributor Author

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?

Copy link
Member

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 :)

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