Data Streams: fix bwc test (#59528) (#59534)

(cherry picked from commit ed1a5c00abed8c63ad395ea93df7a303da7b7a65)
Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This commit is contained in:
Andrei Dan 2020-07-14 15:17:20 +01:00 committed by GitHub
parent b357c1b77a
commit d477aa14ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 19 deletions

View File

@ -14,15 +14,12 @@ import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.ObjectPath;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -55,7 +52,6 @@ import java.util.stream.Collectors;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM; import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.upgrades.FullClusterRestartIT.assertNumHits; import static org.elasticsearch.upgrades.FullClusterRestartIT.assertNumHits;
import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
@ -877,15 +873,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
public void testDataStreams() throws Exception { public void testDataStreams() throws Exception {
assumeTrue("no data streams in versions before " + Version.V_7_9_0, getOldClusterVersion().onOrAfter(Version.V_7_9_0)); assumeTrue("no data streams in versions before " + Version.V_7_9_0, getOldClusterVersion().onOrAfter(Version.V_7_9_0));
if (isRunningAgainstOldCluster()) { if (isRunningAgainstOldCluster()) {
String mapping = "{\n" + createComposableTemplate(client(), "dst", "ds");
" \"properties\": {\n" +
" \"@timestamp\": {\n" +
" \"type\": \"date\"\n" +
" }\n" +
" }\n" +
" }";
Template template = new Template(null, new CompressedXContent(mapping), null);
createComposableTemplate(client(), "dst", "ds", template);
Request indexRequest = new Request("POST", "/ds/_doc/1?op_type=create&refresh"); Request indexRequest = new Request("POST", "/ds/_doc/1?op_type=create&refresh");
XContentBuilder builder = JsonXContent.contentBuilder().startObject() XContentBuilder builder = JsonXContent.contentBuilder().startObject()
@ -909,16 +897,13 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
assertNumHits("ds", 1, 1); assertNumHits("ds", 1, 1);
} }
private static void createComposableTemplate(RestClient client, String templateName, String indexPattern, Template template) private static void createComposableTemplate(RestClient client, String templateName, String indexPattern)
throws IOException { throws IOException {
XContentBuilder builder = jsonBuilder();
template.toXContent(builder, ToXContent.EMPTY_PARAMS);
StringEntity templateJSON = new StringEntity( StringEntity templateJSON = new StringEntity(
String.format(Locale.ROOT, "{\n" + String.format(Locale.ROOT, "{\n" +
" \"index_patterns\": \"%s\",\n" + " \"index_patterns\": \"%s\",\n" +
" \"data_stream\": { \"timestamp_field\": \"@timestamp\" },\n" + " \"data_stream\": {}\n" +
" \"template\": %s\n" + "}", indexPattern),
"}", indexPattern, Strings.toString(builder)),
ContentType.APPLICATION_JSON); ContentType.APPLICATION_JSON);
Request createIndexTemplateRequest = new Request("PUT", "_index_template/" + templateName); Request createIndexTemplateRequest = new Request("PUT", "_index_template/" + templateName);
createIndexTemplateRequest.setEntity(templateJSON); createIndexTemplateRequest.setEntity(templateJSON);