From b537e5968945bd1f8742d5bd317023cd8b48b1ac Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 12 Mar 2020 10:23:16 +0100 Subject: [PATCH 01/14] Initial data stream commit This commits adds a data stream feature flag, initial definition of a data stream and the stubs for the data stream create, delete and get APIs. Also simple serialization tests are added and a rest test to thest the data stream API stubs. This is a large amount of code and mainly mechanical, but this commit should be straightforward to review, because there isn't any real logic. The data stream transport and rest action are behind the data stream feature flag and are only intialized if the feature flag is enabled. The feature flag is enabled if elasticsearch is build as snapshot or a release build and the 'es.datastreams_feature_flag_registered' is enabled. The integ-test-zip sets the feature flag if building a release build, otherwise rest tests would fail. Relates to #53100 --- .../archives/integ-test-zip/build.gradle | 7 + .../api/indices.create_data_stream.json | 31 ++++ .../api/indices.delete_data_stream.json | 26 +++ .../api/indices.get_data_streams.json | 33 ++++ .../test/indices.data_stream/10_basic.yml | 22 +++ .../elasticsearch/action/ActionModule.java | 39 ++++ .../datastream/CreateDataStreamAction.java | 128 +++++++++++++ .../datastream/DeleteDataStreamAction.java | 120 +++++++++++++ .../datastream/GetDataStreamsAction.java | 170 ++++++++++++++++++ .../client/IndicesAdminClient.java | 32 ++++ .../client/support/AbstractClient.java | 33 ++++ .../cluster/metadata/DataStream.java | 116 ++++++++++++ .../cluster/RestCreateDataStreamAction.java | 58 ++++++ .../cluster/RestDeleteDataStreamAction.java | 47 +++++ .../cluster/RestGetDataStreamsAction.java | 52 ++++++ .../CreateDataStreamRequestTests.java | 38 ++++ .../DeleteDataStreamRequestTests.java | 36 ++++ .../GetDataStreamsRequestTests.java | 36 ++++ .../GetDataStreamsResponseTests.java | 60 +++++++ .../cluster/metadata/DataStreamTests.java | 50 ++++++ 20 files changed, 1134 insertions(+) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml create mode 100644 server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java create mode 100644 server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java create mode 100644 server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java create mode 100644 server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java create mode 100644 server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java create mode 100644 server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java create mode 100644 server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java create mode 100644 server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java diff --git a/distribution/archives/integ-test-zip/build.gradle b/distribution/archives/integ-test-zip/build.gradle index ed8f893d7f840..e1373a3cf73fd 100644 --- a/distribution/archives/integ-test-zip/build.gradle +++ b/distribution/archives/integ-test-zip/build.gradle @@ -1,3 +1,4 @@ +import org.elasticsearch.gradle.info.BuildParams /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -32,3 +33,9 @@ integTest.runner { systemProperty 'tests.logfile', '--external--' } } + +testClusters.integTest { + if (BuildParams.isSnapshotBuild() == false) { + systemProperty 'es.datastreams_feature_flag_registered', 'true' + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json new file mode 100644 index 0000000000000..ef8615a69b1ca --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json @@ -0,0 +1,31 @@ +{ + "indices.create_data_stream":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", + "description":"Creates or updates a data stream" + }, + "stability":"experimental", + "url":{ + "paths":[ + { + "path":"/_data_stream/{name}", + "methods":[ + "PUT" + ], + "parts":{ + "name":{ + "type":"string", + "description":"The name of the data stream" + } + } + } + ] + }, + "params":{ + }, + "body":{ + "description":"The data stream definition", + "required":true + } + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json new file mode 100644 index 0000000000000..71ed5808caefc --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json @@ -0,0 +1,26 @@ +{ + "indices.delete_data_stream":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", + "description":"Deletes a data stream." + }, + "stability":"experimental", + "url":{ + "paths":[ + { + "path":"/_data_stream/{name}", + "methods":[ + "DELETE" + ], + "parts":{ + "name":{ + "type":"string", + "description":"The name of the data stream" + } + } + } + ] + }, + "params":{} + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json new file mode 100644 index 0000000000000..42415068d4a5d --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json @@ -0,0 +1,33 @@ +{ + "indices.get_data_streams":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", + "description":"Returns data streams." + }, + "stability":"experimental", + "url":{ + "paths":[ + { + "path":"/_data_streams", + "methods":[ + "GET" + ] + }, + { + "path":"/_data_streams/{name}", + "methods":[ + "GET" + ], + "parts":{ + "name":{ + "type":"list", + "description":"The comma separated names of data streams" + } + } + } + ] + }, + "params":{ + } + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml new file mode 100644 index 0000000000000..cf6d3cabe3d03 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml @@ -0,0 +1,22 @@ +--- +"Test stubs": + - do: + indices.create_data_stream: + name: data-stream2 + body: + timestamp_field_name: "@timestamp" + - is_true: acknowledged + + - do: + indices.get_data_streams: {} + - match: { 0.name: my_data_stream1 } + - match: { 0.timestamp_field_name: '@timestamp' } + - match: { 0.indices: ['my_data_stream1-000000'] } + - match: { 1.name: my_data_stream2 } + - match: { 1.timestamp_field_name: '@timestamp' } + - match: { 1.indices: [] } + + - do: + indices.delete_data_stream: + name: data-stream2 + - is_true: acknowledged diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index affbb7a41dd31..4fe66eb54f117 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -21,12 +21,16 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.elasticsearch.Build; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainAction; import org.elasticsearch.action.admin.cluster.allocation.TransportClusterAllocationExplainAction; import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction; import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; @@ -243,9 +247,11 @@ import org.elasticsearch.rest.action.admin.cluster.RestClusterStatsAction; import org.elasticsearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction; import org.elasticsearch.rest.action.admin.cluster.RestCreateSnapshotAction; +import org.elasticsearch.rest.action.admin.cluster.RestDeleteDataStreamAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteRepositoryAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteSnapshotAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteStoredScriptAction; +import org.elasticsearch.rest.action.admin.cluster.RestGetDataStreamsAction; import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction; import org.elasticsearch.rest.action.admin.cluster.RestGetScriptContextAction; import org.elasticsearch.rest.action.admin.cluster.RestGetScriptLanguageAction; @@ -258,6 +264,7 @@ import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction; import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction; import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction; +import org.elasticsearch.rest.action.admin.cluster.RestCreateDataStreamAction; import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction; import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction; import org.elasticsearch.rest.action.admin.cluster.RestReloadSecureSettingsAction; @@ -361,6 +368,24 @@ public class ActionModule extends AbstractModule { private static final Logger logger = LogManager.getLogger(ActionModule.class); + private static final boolean DATASTREAMS_FEATURE_FLAG_REGISTERED; + + static { + final String property = System.getProperty("es.datastreams_feature_flag_registered"); + if (Build.CURRENT.isSnapshot() && property != null) { + throw new IllegalArgumentException("es.datastreams_feature_flag_registered is only supported in non-snapshot builds"); + } + if (Build.CURRENT.isSnapshot() || "true".equals(property)) { + DATASTREAMS_FEATURE_FLAG_REGISTERED = true; + } else if ("false".equals(property) || property == null) { + DATASTREAMS_FEATURE_FLAG_REGISTERED = false; + } else { + throw new IllegalArgumentException( + "expected es.datastreams_feature_flag_registered to be unset or [true|false] but was [" + property + "]" + ); + } + } + private final Settings settings; private final IndexNameExpressionResolver indexNameExpressionResolver; private final IndexScopedSettings indexScopedSettings; @@ -533,6 +558,13 @@ public void reg actionPlugins.stream().flatMap(p -> p.getActions().stream()).forEach(actions::register); + // Data streams: + if (DATASTREAMS_FEATURE_FLAG_REGISTERED) { + actions.register(CreateDataStreamAction.INSTANCE, CreateDataStreamAction.TransportAction.class); + actions.register(DeleteDataStreamAction.INSTANCE, DeleteDataStreamAction.TransportAction.class); + actions.register(GetDataStreamsAction.INSTANCE, GetDataStreamsAction.TransportAction.class); + } + // Persistent tasks: actions.register(StartPersistentTaskAction.INSTANCE, StartPersistentTaskAction.TransportAction.class); actions.register(UpdatePersistentTaskStatusAction.INSTANCE, UpdatePersistentTaskStatusAction.TransportAction.class); @@ -680,6 +712,13 @@ public void initRestHandlers(Supplier nodesInCluster) { registerHandler.accept(new RestDeletePipelineAction()); registerHandler.accept(new RestSimulatePipelineAction()); + // Data Stream API + if (DATASTREAMS_FEATURE_FLAG_REGISTERED) { + registerHandler.accept(new RestCreateDataStreamAction()); + registerHandler.accept(new RestDeleteDataStreamAction()); + registerHandler.accept(new RestGetDataStreamsAction()); + } + // CAT API registerHandler.accept(new RestAllocationAction()); registerHandler.accept(new RestShardsAction()); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java new file mode 100644 index 0000000000000..df6e829a28af4 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java @@ -0,0 +1,128 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.action.support.master.MasterNodeRequest; +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.common.io.stream.StreamOutput; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.io.IOException; +import java.util.Objects; + +public class CreateDataStreamAction extends ActionType { + + public static final CreateDataStreamAction INSTANCE = new CreateDataStreamAction(); + public static final String NAME = "indices:admin/data_stream/create"; + + private CreateDataStreamAction() { + super(NAME, AcknowledgedResponse::new); + } + + public static class Request extends MasterNodeRequest { + + private final String name; + private String timestampFieldName; + + public Request(String name) { + this.name = name; + } + + public void setTimestampFieldName(String timestampFieldName) { + this.timestampFieldName = timestampFieldName; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + public Request(StreamInput in) throws IOException { + super(in); + this.name = in.readString(); + this.timestampFieldName = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(name); + out.writeString(timestampFieldName); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return name.equals(request.name) && + timestampFieldName.equals(request.timestampFieldName); + } + + @Override + public int hashCode() { + return Objects.hash(name, timestampFieldName); + } + } + + public static class TransportAction extends TransportMasterNodeAction { + + @Inject + public TransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(NAME, transportService, clusterService, threadPool, actionFilters, Request::new, indexNameExpressionResolver); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected AcknowledgedResponse read(StreamInput in) throws IOException { + return new AcknowledgedResponse(in); + } + + @Override + protected void masterOperation(Task task, Request request, ClusterState state, + ActionListener listener) throws Exception { + listener.onResponse(new AcknowledgedResponse(true)); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } + } + +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java new file mode 100644 index 0000000000000..20a2ba4aa2cd6 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java @@ -0,0 +1,120 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.action.support.master.MasterNodeRequest; +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.common.io.stream.StreamOutput; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.io.IOException; +import java.util.Objects; + +public class DeleteDataStreamAction extends ActionType { + + public static final DeleteDataStreamAction INSTANCE = new DeleteDataStreamAction(); + public static final String NAME = "indices:admin/data_stream/delete"; + + private DeleteDataStreamAction() { + super(NAME, AcknowledgedResponse::new); + } + + public static class Request extends MasterNodeRequest { + + private final String name; + + public Request(String name) { + this.name = Objects.requireNonNull(name); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + public Request(StreamInput in) throws IOException { + super(in); + this.name = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(name); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return name.equals(request.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + } + + public static class TransportAction extends TransportMasterNodeAction { + + @Inject + public TransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(NAME, transportService, clusterService, threadPool, actionFilters, Request::new, indexNameExpressionResolver); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected AcknowledgedResponse read(StreamInput in) throws IOException { + return new AcknowledgedResponse(in); + } + + @Override + protected void masterOperation(Task task, Request request, ClusterState state, + ActionListener listener) throws Exception { + listener.onResponse(new AcknowledgedResponse(true)); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } + } + +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java new file mode 100644 index 0000000000000..a19514bb82a03 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java @@ -0,0 +1,170 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.cluster.metadata.DataStream; +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.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class GetDataStreamsAction extends ActionType { + + public static final GetDataStreamsAction INSTANCE = new GetDataStreamsAction(); + public static final String NAME = "indices:admin/data_streams/get"; + + private GetDataStreamsAction() { + super(NAME, Response::new); + } + + public static class Request extends MasterNodeReadRequest { + + private final String[] names; + + public Request(String[] names) { + this.names = Objects.requireNonNull(names); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + public Request(StreamInput in) throws IOException { + super(in); + this.names = in.readStringArray(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(names); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return Arrays.equals(names, request.names); + } + + @Override + public int hashCode() { + return Arrays.hashCode(names); + } + } + + public static class Response extends ActionResponse implements ToXContentObject { + + private final List dataStreams; + + public Response(List dataStreams) { + this.dataStreams = dataStreams; + } + + public Response(StreamInput in) throws IOException { + this(in.readList(DataStream::new)); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeList(dataStreams); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startArray(); + for (DataStream dataStream : dataStreams) { + dataStream.toXContent(builder, params); + } + builder.endArray(); + return builder; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Response response = (Response) o; + return dataStreams.equals(response.dataStreams); + } + + @Override + public int hashCode() { + return Objects.hash(dataStreams); + } + } + + public static class TransportAction extends TransportMasterNodeReadAction { + + @Inject + public TransportAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(NAME, transportService, clusterService, threadPool, actionFilters, Request::new, indexNameExpressionResolver); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected Response read(StreamInput in) throws IOException { + return new Response(in); + } + + @Override + protected void masterOperation(Task task, Request request, ClusterState state, + ActionListener listener) throws Exception { + List dataStreams = List.of( + new DataStream("my_data_stream1", "@timestamp", List.of("my_data_stream1-000000")), + new DataStream("my_data_stream2", "@timestamp", List.of()) + ); + listener.onResponse(new Response(dataStreams)); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } + } + +} diff --git a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 36b34a7b24c85..13f28dbbce210 100644 --- a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -21,6 +21,9 @@ import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; @@ -713,4 +716,33 @@ public interface IndicesAdminClient extends ElasticsearchClient { */ void rolloverIndex(RolloverRequest request, ActionListener listener); + /** + * Store a data stream + */ + void createDataStream(CreateDataStreamAction.Request request, ActionListener listener); + + /** + * Store a data stream + */ + ActionFuture createDataStream(CreateDataStreamAction.Request request); + + /** + * Delete a data stream + */ + void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener); + + /** + * Delete a data stream + */ + ActionFuture deleteDataStream(DeleteDataStreamAction.Request request); + + /** + * Get data streams + */ + void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener); + + /** + * Get data streams + */ + ActionFuture getDataStreams(GetDataStreamsAction.Request request); } diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 1ee480fb55edd..669df02de212b 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -30,6 +30,9 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; @@ -1657,6 +1660,36 @@ public ActionFuture getSettings(GetSettingsRequest request) public void getSettings(GetSettingsRequest request, ActionListener listener) { execute(GetSettingsAction.INSTANCE, request, listener); } + + @Override + public void createDataStream(CreateDataStreamAction.Request request, ActionListener listener) { + execute(CreateDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture createDataStream(CreateDataStreamAction.Request request) { + return execute(CreateDataStreamAction.INSTANCE, request); + } + + @Override + public void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener) { + execute(DeleteDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture deleteDataStream(DeleteDataStreamAction.Request request) { + return execute(DeleteDataStreamAction.INSTANCE, request); + } + + @Override + public void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener) { + execute(GetDataStreamsAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture getDataStreams(GetDataStreamsAction.Request request) { + return execute(GetDataStreamsAction.INSTANCE, request); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java new file mode 100644 index 0000000000000..9d8675ad84236 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java @@ -0,0 +1,116 @@ +/* + * 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.cluster.metadata; + +import org.elasticsearch.cluster.AbstractDiffable; +import org.elasticsearch.cluster.Diff; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +public final class DataStream extends AbstractDiffable implements ToXContentObject { + + private final String name; + private final String timeStampFieldName; + private final List indices; + + public DataStream(String name, String timeStampFieldName, List indices) { + this.name = name; + this.timeStampFieldName = timeStampFieldName; + this.indices = indices; + } + + public String getName() { + return name; + } + + public String getTimeStampFieldName() { + return timeStampFieldName; + } + + public List getIndices() { + return indices; + } + + public DataStream(StreamInput in) throws IOException { + this(in.readString(), in.readString(), in.readStringList()); + } + + public static Diff readDiffFrom(StreamInput in) throws IOException { + return readDiffFrom(DataStream::new, in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(name); + out.writeString(timeStampFieldName); + out.writeStringCollection(indices); + } + + public static final ParseField NAME_FIELD = new ParseField("name"); + public static final ParseField TIMESTAMP_FIELD_NAME_FIELD = new ParseField("timestamp_field_name"); + public static final ParseField INDICES_FIELD = new ParseField("indices"); + + @SuppressWarnings("unchecked") + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("data_stream", + args -> new DataStream((String) args[0], (String) args[1], (List) args[2])); + + static { + PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME_FIELD); + PARSER.declareString(ConstructingObjectParser.constructorArg(), TIMESTAMP_FIELD_NAME_FIELD); + PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), INDICES_FIELD); + } + + public static DataStream fromXContent(XContentParser parser) throws IOException { + return PARSER.parse(parser, null); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(NAME_FIELD.getPreferredName(), name); + builder.field(TIMESTAMP_FIELD_NAME_FIELD.getPreferredName(), timeStampFieldName); + builder.field(INDICES_FIELD.getPreferredName(), indices); + builder.endObject(); + return builder; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataStream that = (DataStream) o; + return name.equals(that.name) && + timeStampFieldName.equals(that.timeStampFieldName) && + indices.equals(that.indices); + } + + @Override + public int hashCode() { + return Objects.hash(name, timeStampFieldName, indices); + } +} diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java new file mode 100644 index 0000000000000..6826d220ac062 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java @@ -0,0 +1,58 @@ +/* + * 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.rest.action.admin.cluster; + +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.cluster.metadata.DataStream; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class RestCreateDataStreamAction extends BaseRestHandler { + + @Override + public String getName() { + return "create_data_stream_action"; + } + + @Override + public List routes() { + return List.of( + new Route(RestRequest.Method.PUT, "/_data_stream/{name}") + ); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + CreateDataStreamAction.Request putDataStreamRequest = new CreateDataStreamAction.Request(request.param("name")); + request.withContentOrSourceParamParserOrNull(parser -> { + Map body = parser.map(); + String timeStampFieldName = (String) body.get(DataStream.TIMESTAMP_FIELD_NAME_FIELD.getPreferredName()); + if (timeStampFieldName != null) { + putDataStreamRequest.setTimestampFieldName(timeStampFieldName); + } + }); + return channel -> client.admin().indices().createDataStream(putDataStreamRequest, new RestToXContentListener<>(channel)); + } +} diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java new file mode 100644 index 0000000000000..747ea3ed5a9bf --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java @@ -0,0 +1,47 @@ +/* + * 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.rest.action.admin.cluster; + +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; + +public class RestDeleteDataStreamAction extends BaseRestHandler { + + @Override + public String getName() { + return "delete_data_stream_action"; + } + + @Override + public List routes() { + return List.of(new Route(RestRequest.Method.DELETE, "/_data_stream/{name}")); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + DeleteDataStreamAction.Request deleteDataStreamRequest = new DeleteDataStreamAction.Request(request.param("name")); + return channel -> client.admin().indices().deleteDataStream(deleteDataStreamRequest, new RestToXContentListener<>(channel)); + } +} diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java new file mode 100644 index 0000000000000..658cb8d8fb5fe --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java @@ -0,0 +1,52 @@ +/* + * 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.rest.action.admin.cluster; + +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.Strings; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; + +public class RestGetDataStreamsAction extends BaseRestHandler { + + @Override + public String getName() { + return "get_data_streams_action"; + } + + @Override + public List routes() { + return List.of( + new Route(RestRequest.Method.GET, "/_data_streams"), + new Route(RestRequest.Method.GET, "/_data_streams/{name}") + ); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + String[] names = Strings.splitStringByCommaToArray(request.param("name")); + GetDataStreamsAction.Request getDataStreamsRequest = new GetDataStreamsAction.Request(names); + return channel -> client.admin().indices().getDataStreams(getDataStreamsRequest, new RestToXContentListener<>(channel)); + } +} diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java new file mode 100644 index 0000000000000..d6a846c205fb3 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java @@ -0,0 +1,38 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction.Request; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class CreateDataStreamRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return Request::new; + } + + @Override + protected Request createTestInstance() { + Request request = new Request(randomAlphaOfLength(8)); + request.setTimestampFieldName(randomAlphaOfLength(8)); + return request; + } +} diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java new file mode 100644 index 0000000000000..f460065699795 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java @@ -0,0 +1,36 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction.Request; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class DeleteDataStreamRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return Request::new; + } + + @Override + protected Request createTestInstance() { + return new Request(randomAlphaOfLength(8)); + } +} diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java new file mode 100644 index 0000000000000..062bdef629cc9 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java @@ -0,0 +1,36 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Request; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class GetDataStreamsRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return Request::new; + } + + @Override + protected Request createTestInstance() { + return new Request(generateRandomStringArray(8, 8, false)); + } +} diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java new file mode 100644 index 0000000000000..5c74c515634cc --- /dev/null +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java @@ -0,0 +1,60 @@ +/* + * 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.indices.datastream; + +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Response; +import org.elasticsearch.cluster.metadata.DataStream; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentParser.Token; +import org.elasticsearch.test.AbstractSerializingTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class GetDataStreamsResponseTests extends AbstractSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return Response::new; + } + + @Override + protected Response doParseInstance(XContentParser parser) throws IOException { + List dataStreams = new ArrayList<>(); + for (Token token = parser.nextToken(); token != Token.END_ARRAY; token = parser.nextToken()) { + if (token == Token.START_OBJECT) { + dataStreams.add(DataStream.fromXContent(parser)); + } + } + return new Response(dataStreams); + } + + @Override + protected Response createTestInstance() { + int numDataStreams = randomIntBetween(0, 8); + List dataStreams = new ArrayList<>(); + for (int i = 0; i < numDataStreams; i++) { + dataStreams.add(new DataStream(randomAlphaOfLength(4), randomAlphaOfLength(4), + List.of(generateRandomStringArray(8, 4, false)))); + } + return new Response(dataStreams); + } +} diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java new file mode 100644 index 0000000000000..072165ab098ef --- /dev/null +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java @@ -0,0 +1,50 @@ +/* + * 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.cluster.metadata; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractSerializingTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class DataStreamTests extends AbstractSerializingTestCase { + + @Override + protected DataStream doParseInstance(XContentParser parser) throws IOException { + return DataStream.fromXContent(parser); + } + + @Override + protected Writeable.Reader instanceReader() { + return DataStream::new; + } + + @Override + protected DataStream createTestInstance() { + int numIndices = randomIntBetween(0, 128); + List indices = new ArrayList<>(numIndices); + for (int i = 0; i < numIndices; i++) { + indices.add(randomAlphaOfLength(10)); + } + return new DataStream(randomAlphaOfLength(10), randomAlphaOfLength(10), indices); + } +} From 9665ea973a87e389d2d468889408ed6faf756980 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 17 Mar 2020 17:30:02 +0100 Subject: [PATCH 02/14] fixed hlrc test --- .../org/elasticsearch/client/RestHighLevelClientTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index a8e8037930741..497c2f0a062ea 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -790,7 +790,10 @@ public void testApiNamingConventions() throws Exception { "indices.get_upgrade", "indices.put_alias", "render_search_template", - "scripts_painless_execute" + "scripts_painless_execute", + "indices.create_data_stream", + "indices.get_data_streams", + "indices.delete_data_stream" }; //These API are not required for high-level client feature completeness String[] notRequiredApi = new String[] { From f7200c7c02f1341e3f6cce241973fdf45e9d72f8 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 17 Mar 2020 17:31:21 +0100 Subject: [PATCH 03/14] ignore bwc until this change has been backported to 7.x branch --- .../rest-api-spec/test/indices.data_stream/10_basic.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml index cf6d3cabe3d03..e06290630308b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml @@ -1,5 +1,9 @@ --- "Test stubs": + - skip: + version: " - 7.99.99" + reason: not backported yet + - do: indices.create_data_stream: name: data-stream2 From e362eeb669b8d20a6bede467155c6a832e1bf1ad Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 17 Mar 2020 19:43:26 +0100 Subject: [PATCH 04/14] changed data stream apis to be a cluster based action. before this commit the data steams api were indices based actions, but data streams aren't indices, data streams encapsulates indices, but are indices themselves. It is a cluster level attribute, and therefor cluster based action fits best for now. Perhaps in the future we will have data stream based actions and then this would be a right fit for the data stream crud apis. --- .../elasticsearch/action/ActionModule.java | 6 +- .../datastream/CreateDataStreamAction.java | 4 +- .../datastream/DeleteDataStreamAction.java | 4 +- .../datastream/GetDataStreamsAction.java | 4 +- .../client/ClusterAdminClient.java | 33 ++++++++++ .../client/IndicesAdminClient.java | 32 --------- .../client/support/AbstractClient.java | 65 ++++++++++--------- .../cluster/RestCreateDataStreamAction.java | 4 +- .../cluster/RestDeleteDataStreamAction.java | 4 +- .../cluster/RestGetDataStreamsAction.java | 4 +- .../CreateDataStreamRequestTests.java | 4 +- .../DeleteDataStreamRequestTests.java | 4 +- .../GetDataStreamsRequestTests.java | 4 +- .../GetDataStreamsResponseTests.java | 4 +- 14 files changed, 89 insertions(+), 87 deletions(-) rename server/src/main/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/CreateDataStreamAction.java (97%) rename server/src/main/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/DeleteDataStreamAction.java (97%) rename server/src/main/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/GetDataStreamsAction.java (98%) rename server/src/test/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/CreateDataStreamRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/DeleteDataStreamRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/GetDataStreamsRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{indices => cluster}/datastream/GetDataStreamsResponseTests.java (94%) diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 4fe66eb54f117..afe52d491a477 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -28,9 +28,9 @@ import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction; import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java similarity index 97% rename from server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java rename to server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java index df6e829a28af4..0da3ab84a37c8 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -43,7 +43,7 @@ public class CreateDataStreamAction extends ActionType { public static final CreateDataStreamAction INSTANCE = new CreateDataStreamAction(); - public static final String NAME = "indices:admin/data_stream/create"; + public static final String NAME = "cluster:admin/data_stream/create"; private CreateDataStreamAction() { super(NAME, AcknowledgedResponse::new); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java similarity index 97% rename from server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java rename to server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java index 20a2ba4aa2cd6..04e3e80c74acd 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -43,7 +43,7 @@ public class DeleteDataStreamAction extends ActionType { public static final DeleteDataStreamAction INSTANCE = new DeleteDataStreamAction(); - public static final String NAME = "indices:admin/data_stream/delete"; + public static final String NAME = "cluster:admin/data_stream/delete"; private DeleteDataStreamAction() { super(NAME, AcknowledgedResponse::new); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java similarity index 98% rename from server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java rename to server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java index a19514bb82a03..e6526c9f6066b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -48,7 +48,7 @@ public class GetDataStreamsAction extends ActionType { public static final GetDataStreamsAction INSTANCE = new GetDataStreamsAction(); - public static final String NAME = "indices:admin/data_streams/get"; + public static final String NAME = "cluster:admin/data_streams/get"; private GetDataStreamsAction() { super(NAME, Response::new); diff --git a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index fdee39fdb1f93..304c024d48065 100644 --- a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -24,6 +24,9 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -718,4 +721,34 @@ public interface ClusterAdminClient extends ElasticsearchClient { * Get a script from the cluster state */ ActionFuture getStoredScript(GetStoredScriptRequest request); + + /** + * Store a data stream + */ + void createDataStream(CreateDataStreamAction.Request request, ActionListener listener); + + /** + * Store a data stream + */ + ActionFuture createDataStream(CreateDataStreamAction.Request request); + + /** + * Delete a data stream + */ + void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener); + + /** + * Delete a data stream + */ + ActionFuture deleteDataStream(DeleteDataStreamAction.Request request); + + /** + * Get data streams + */ + void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener); + + /** + * Get data streams + */ + ActionFuture getDataStreams(GetDataStreamsAction.Request request); } diff --git a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 13f28dbbce210..36b34a7b24c85 100644 --- a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -21,9 +21,6 @@ import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; @@ -716,33 +713,4 @@ public interface IndicesAdminClient extends ElasticsearchClient { */ void rolloverIndex(RolloverRequest request, ActionListener listener); - /** - * Store a data stream - */ - void createDataStream(CreateDataStreamAction.Request request, ActionListener listener); - - /** - * Store a data stream - */ - ActionFuture createDataStream(CreateDataStreamAction.Request request); - - /** - * Delete a data stream - */ - void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener); - - /** - * Delete a data stream - */ - ActionFuture deleteDataStream(DeleteDataStreamAction.Request request); - - /** - * Get data streams - */ - void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener); - - /** - * Get data streams - */ - ActionFuture getDataStreams(GetDataStreamsAction.Request request); } diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 669df02de212b..495afd23428f7 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -30,9 +30,9 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; @@ -1188,6 +1188,36 @@ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(){ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(String id){ return prepareDeleteStoredScript().setId(id); } + + @Override + public void createDataStream(CreateDataStreamAction.Request request, ActionListener listener) { + execute(CreateDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture createDataStream(CreateDataStreamAction.Request request) { + return execute(CreateDataStreamAction.INSTANCE, request); + } + + @Override + public void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener) { + execute(DeleteDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture deleteDataStream(DeleteDataStreamAction.Request request) { + return execute(DeleteDataStreamAction.INSTANCE, request); + } + + @Override + public void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener) { + execute(GetDataStreamsAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture getDataStreams(GetDataStreamsAction.Request request) { + return execute(GetDataStreamsAction.INSTANCE, request); + } } static class IndicesAdmin implements IndicesAdminClient { @@ -1661,35 +1691,6 @@ public void getSettings(GetSettingsRequest request, ActionListener listener) { - execute(CreateDataStreamAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture createDataStream(CreateDataStreamAction.Request request) { - return execute(CreateDataStreamAction.INSTANCE, request); - } - - @Override - public void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener) { - execute(DeleteDataStreamAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture deleteDataStream(DeleteDataStreamAction.Request request) { - return execute(DeleteDataStreamAction.INSTANCE, request); - } - - @Override - public void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener) { - execute(GetDataStreamsAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture getDataStreams(GetDataStreamsAction.Request request) { - return execute(GetDataStreamsAction.INSTANCE, request); - } } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java index 6826d220ac062..64c1d1ad6c799 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.rest.BaseRestHandler; @@ -53,6 +53,6 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli putDataStreamRequest.setTimestampFieldName(timeStampFieldName); } }); - return channel -> client.admin().indices().createDataStream(putDataStreamRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().createDataStream(putDataStreamRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java index 747ea3ed5a9bf..ed6b0353687e3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; @@ -42,6 +42,6 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { DeleteDataStreamAction.Request deleteDataStreamRequest = new DeleteDataStreamAction.Request(request.param("name")); - return channel -> client.admin().indices().deleteDataStream(deleteDataStreamRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().deleteDataStream(deleteDataStreamRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java index 658cb8d8fb5fe..ed333ed56e7b5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; @@ -47,6 +47,6 @@ public List routes() { protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { String[] names = Strings.splitStringByCommaToArray(request.param("name")); GetDataStreamsAction.Request getDataStreamsRequest = new GetDataStreamsAction.Request(names); - return channel -> client.admin().indices().getDataStreams(getDataStreamsRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().getDataStreams(getDataStreamsRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java index d6a846c205fb3..e3b15cada46e1 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction.Request; +import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java index f460065699795..9af8056b194f0 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction.Request; +import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java index 062bdef629cc9..05a6a8881aa6b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Request; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java similarity index 94% rename from server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java rename to server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java index 5c74c515634cc..89726cf2ae30f 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.indices.datastream; +package org.elasticsearch.action.admin.cluster.datastream; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Response; +import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction.Response; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; From 7c22f72413f02e91657181cd5d095e3abe123835 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 17 Mar 2020 19:50:28 +0100 Subject: [PATCH 05/14] this should have been part of the previous commit --- .../org/elasticsearch/client/RestHighLevelClientTests.java | 6 +++--- ...ate_data_stream.json => cluster.create_data_stream.json} | 2 +- ...ete_data_stream.json => cluster.delete_data_stream.json} | 2 +- ....get_data_streams.json => cluster.get_data_streams.json} | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename rest-api-spec/src/main/resources/rest-api-spec/api/{indices.create_data_stream.json => cluster.create_data_stream.json} (95%) rename rest-api-spec/src/main/resources/rest-api-spec/api/{indices.delete_data_stream.json => cluster.delete_data_stream.json} (94%) rename rest-api-spec/src/main/resources/rest-api-spec/api/{indices.get_data_streams.json => cluster.get_data_streams.json} (95%) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 497c2f0a062ea..9d75a2b8c4348 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -791,9 +791,9 @@ public void testApiNamingConventions() throws Exception { "indices.put_alias", "render_search_template", "scripts_painless_execute", - "indices.create_data_stream", - "indices.get_data_streams", - "indices.delete_data_stream" + "cluster.create_data_stream", + "cluster.get_data_streams", + "cluster.delete_data_stream" }; //These API are not required for high-level client feature completeness String[] notRequiredApi = new String[] { diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json similarity index 95% rename from rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json index ef8615a69b1ca..8fad4225f8753 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json @@ -1,5 +1,5 @@ { - "indices.create_data_stream":{ + "cluster.create_data_stream":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Creates or updates a data stream" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json similarity index 94% rename from rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json index 71ed5808caefc..6f439c7009f4e 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json @@ -1,5 +1,5 @@ { - "indices.delete_data_stream":{ + "cluster.delete_data_stream":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Deletes a data stream." diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json similarity index 95% rename from rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json index 42415068d4a5d..bb749fc87f31c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json @@ -1,5 +1,5 @@ { - "indices.get_data_streams":{ + "cluster.get_data_streams":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Returns data streams." From ee721c3ae91a235f3acecf42789587e21e418aeb Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 17 Mar 2020 21:33:20 +0100 Subject: [PATCH 06/14] fixed yaml test --- .../10_basic.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename rest-api-spec/src/main/resources/rest-api-spec/test/{indices.data_stream => cluster.data_stream}/10_basic.yml (84%) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml similarity index 84% rename from rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml rename to rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml index e06290630308b..dd329f1469030 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml @@ -5,14 +5,14 @@ reason: not backported yet - do: - indices.create_data_stream: + cluster.create_data_stream: name: data-stream2 body: timestamp_field_name: "@timestamp" - is_true: acknowledged - do: - indices.get_data_streams: {} + cluster.get_data_streams: {} - match: { 0.name: my_data_stream1 } - match: { 0.timestamp_field_name: '@timestamp' } - match: { 0.indices: ['my_data_stream1-000000'] } @@ -21,6 +21,6 @@ - match: { 1.indices: [] } - do: - indices.delete_data_stream: + cluster.delete_data_stream: name: data-stream2 - is_true: acknowledged From f9ce4cdcbc530679c0416b4d7bf0483e83767f13 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 18 Mar 2020 17:05:15 +0100 Subject: [PATCH 07/14] Also add feature flag in other modules that run the yaml test if a release build is executed --- qa/smoke-test-multinode/build.gradle | 7 +++++++ x-pack/qa/core-rest-tests-with-security/build.gradle | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/qa/smoke-test-multinode/build.gradle b/qa/smoke-test-multinode/build.gradle index 244b5d1e8af6e..ba3b3d1a8a242 100644 --- a/qa/smoke-test-multinode/build.gradle +++ b/qa/smoke-test-multinode/build.gradle @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import org.elasticsearch.gradle.info.BuildParams apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-rest-test' @@ -46,3 +47,9 @@ integTest.runner { ].join(',') } } + +testClusters.integTest { + if (BuildParams.isSnapshotBuild() == false) { + systemProperty 'es.datastreams_feature_flag_registered', 'true' + } +} diff --git a/x-pack/qa/core-rest-tests-with-security/build.gradle b/x-pack/qa/core-rest-tests-with-security/build.gradle index 4fc4428c8ed6f..e7c73f851143f 100644 --- a/x-pack/qa/core-rest-tests-with-security/build.gradle +++ b/x-pack/qa/core-rest-tests-with-security/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' @@ -26,6 +28,10 @@ integTest { } testClusters.integTest { + if (BuildParams.isSnapshotBuild() == false) { + systemProperty 'es.datastreams_feature_flag_registered', 'true' + } + testDistribution = 'DEFAULT' setting 'xpack.ilm.enabled', 'false' setting 'xpack.security.enabled', 'true' From 6586d7c35734fdc8c2446bdc4517685b3babfbd8 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 19 Mar 2020 21:02:02 +0100 Subject: [PATCH 08/14] Reverted the commits that make data stream a cluster based api This reverts commit e362eeb669b8d20a6bede467155c6a832e1bf1ad. --- .../client/RestHighLevelClientTests.java | 6 +- ...m.json => indices.create_data_stream.json} | 2 +- ...m.json => indices.delete_data_stream.json} | 2 +- ...ams.json => indices.get_data_streams.json} | 2 +- .../10_basic.yml | 6 +- .../elasticsearch/action/ActionModule.java | 6 +- .../datastream/CreateDataStreamAction.java | 4 +- .../datastream/DeleteDataStreamAction.java | 4 +- .../datastream/GetDataStreamsAction.java | 4 +- .../client/ClusterAdminClient.java | 33 ---------- .../client/IndicesAdminClient.java | 32 +++++++++ .../client/support/AbstractClient.java | 65 +++++++++---------- .../cluster/RestCreateDataStreamAction.java | 4 +- .../cluster/RestDeleteDataStreamAction.java | 4 +- .../cluster/RestGetDataStreamsAction.java | 4 +- .../CreateDataStreamRequestTests.java | 4 +- .../DeleteDataStreamRequestTests.java | 4 +- .../GetDataStreamsRequestTests.java | 4 +- .../GetDataStreamsResponseTests.java | 4 +- 19 files changed, 96 insertions(+), 98 deletions(-) rename rest-api-spec/src/main/resources/rest-api-spec/api/{cluster.create_data_stream.json => indices.create_data_stream.json} (95%) rename rest-api-spec/src/main/resources/rest-api-spec/api/{cluster.delete_data_stream.json => indices.delete_data_stream.json} (94%) rename rest-api-spec/src/main/resources/rest-api-spec/api/{cluster.get_data_streams.json => indices.get_data_streams.json} (95%) rename rest-api-spec/src/main/resources/rest-api-spec/test/{cluster.data_stream => indices.data_stream}/10_basic.yml (84%) rename server/src/main/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/CreateDataStreamAction.java (97%) rename server/src/main/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/DeleteDataStreamAction.java (97%) rename server/src/main/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/GetDataStreamsAction.java (98%) rename server/src/test/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/CreateDataStreamRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/DeleteDataStreamRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/GetDataStreamsRequestTests.java (91%) rename server/src/test/java/org/elasticsearch/action/admin/{cluster => indices}/datastream/GetDataStreamsResponseTests.java (94%) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 9d75a2b8c4348..497c2f0a062ea 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -791,9 +791,9 @@ public void testApiNamingConventions() throws Exception { "indices.put_alias", "render_search_template", "scripts_painless_execute", - "cluster.create_data_stream", - "cluster.get_data_streams", - "cluster.delete_data_stream" + "indices.create_data_stream", + "indices.get_data_streams", + "indices.delete_data_stream" }; //These API are not required for high-level client feature completeness String[] notRequiredApi = new String[] { diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json similarity index 95% rename from rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json index 8fad4225f8753..ef8615a69b1ca 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.create_data_stream.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.create_data_stream.json @@ -1,5 +1,5 @@ { - "cluster.create_data_stream":{ + "indices.create_data_stream":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Creates or updates a data stream" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json similarity index 94% rename from rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json index 6f439c7009f4e..71ed5808caefc 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_data_stream.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.delete_data_stream.json @@ -1,5 +1,5 @@ { - "cluster.delete_data_stream":{ + "indices.delete_data_stream":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Deletes a data stream." diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json similarity index 95% rename from rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json index bb749fc87f31c..42415068d4a5d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_data_streams.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_data_streams.json @@ -1,5 +1,5 @@ { - "cluster.get_data_streams":{ + "indices.get_data_streams":{ "documentation":{ "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/data-streams.html", "description":"Returns data streams." diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml similarity index 84% rename from rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml rename to rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml index dd329f1469030..e06290630308b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.data_stream/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml @@ -5,14 +5,14 @@ reason: not backported yet - do: - cluster.create_data_stream: + indices.create_data_stream: name: data-stream2 body: timestamp_field_name: "@timestamp" - is_true: acknowledged - do: - cluster.get_data_streams: {} + indices.get_data_streams: {} - match: { 0.name: my_data_stream1 } - match: { 0.timestamp_field_name: '@timestamp' } - match: { 0.indices: ['my_data_stream1-000000'] } @@ -21,6 +21,6 @@ - match: { 1.indices: [] } - do: - cluster.delete_data_stream: + indices.delete_data_stream: name: data-stream2 - is_true: acknowledged diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index afe52d491a477..4fe66eb54f117 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -28,9 +28,9 @@ import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction; -import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; -import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction; import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java similarity index 97% rename from server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java rename to server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java index 0da3ab84a37c8..df6e829a28af4 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -43,7 +43,7 @@ public class CreateDataStreamAction extends ActionType { public static final CreateDataStreamAction INSTANCE = new CreateDataStreamAction(); - public static final String NAME = "cluster:admin/data_stream/create"; + public static final String NAME = "indices:admin/data_stream/create"; private CreateDataStreamAction() { super(NAME, AcknowledgedResponse::new); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java similarity index 97% rename from server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java rename to server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java index 04e3e80c74acd..20a2ba4aa2cd6 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -43,7 +43,7 @@ public class DeleteDataStreamAction extends ActionType { public static final DeleteDataStreamAction INSTANCE = new DeleteDataStreamAction(); - public static final String NAME = "cluster:admin/data_stream/delete"; + public static final String NAME = "indices:admin/data_stream/delete"; private DeleteDataStreamAction() { super(NAME, AcknowledgedResponse::new); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java similarity index 98% rename from server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java rename to server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java index e6526c9f6066b..a19514bb82a03 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; @@ -48,7 +48,7 @@ public class GetDataStreamsAction extends ActionType { public static final GetDataStreamsAction INSTANCE = new GetDataStreamsAction(); - public static final String NAME = "cluster:admin/data_streams/get"; + public static final String NAME = "indices:admin/data_streams/get"; private GetDataStreamsAction() { super(NAME, Response::new); diff --git a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 304c024d48065..fdee39fdb1f93 100644 --- a/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -24,9 +24,6 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; -import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; -import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -721,34 +718,4 @@ public interface ClusterAdminClient extends ElasticsearchClient { * Get a script from the cluster state */ ActionFuture getStoredScript(GetStoredScriptRequest request); - - /** - * Store a data stream - */ - void createDataStream(CreateDataStreamAction.Request request, ActionListener listener); - - /** - * Store a data stream - */ - ActionFuture createDataStream(CreateDataStreamAction.Request request); - - /** - * Delete a data stream - */ - void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener); - - /** - * Delete a data stream - */ - ActionFuture deleteDataStream(DeleteDataStreamAction.Request request); - - /** - * Get data streams - */ - void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener); - - /** - * Get data streams - */ - ActionFuture getDataStreams(GetDataStreamsAction.Request request); } diff --git a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 36b34a7b24c85..13f28dbbce210 100644 --- a/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/server/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -21,6 +21,9 @@ import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; @@ -713,4 +716,33 @@ public interface IndicesAdminClient extends ElasticsearchClient { */ void rolloverIndex(RolloverRequest request, ActionListener listener); + /** + * Store a data stream + */ + void createDataStream(CreateDataStreamAction.Request request, ActionListener listener); + + /** + * Store a data stream + */ + ActionFuture createDataStream(CreateDataStreamAction.Request request); + + /** + * Delete a data stream + */ + void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener); + + /** + * Delete a data stream + */ + ActionFuture deleteDataStream(DeleteDataStreamAction.Request request); + + /** + * Get data streams + */ + void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener); + + /** + * Get data streams + */ + ActionFuture getDataStreams(GetDataStreamsAction.Request request); } diff --git a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 495afd23428f7..669df02de212b 100644 --- a/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -30,9 +30,9 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; -import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; -import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; @@ -1188,36 +1188,6 @@ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(){ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(String id){ return prepareDeleteStoredScript().setId(id); } - - @Override - public void createDataStream(CreateDataStreamAction.Request request, ActionListener listener) { - execute(CreateDataStreamAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture createDataStream(CreateDataStreamAction.Request request) { - return execute(CreateDataStreamAction.INSTANCE, request); - } - - @Override - public void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener) { - execute(DeleteDataStreamAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture deleteDataStream(DeleteDataStreamAction.Request request) { - return execute(DeleteDataStreamAction.INSTANCE, request); - } - - @Override - public void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener) { - execute(GetDataStreamsAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture getDataStreams(GetDataStreamsAction.Request request) { - return execute(GetDataStreamsAction.INSTANCE, request); - } } static class IndicesAdmin implements IndicesAdminClient { @@ -1691,6 +1661,35 @@ public void getSettings(GetSettingsRequest request, ActionListener listener) { + execute(CreateDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture createDataStream(CreateDataStreamAction.Request request) { + return execute(CreateDataStreamAction.INSTANCE, request); + } + + @Override + public void deleteDataStream(DeleteDataStreamAction.Request request, ActionListener listener) { + execute(DeleteDataStreamAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture deleteDataStream(DeleteDataStreamAction.Request request) { + return execute(DeleteDataStreamAction.INSTANCE, request); + } + + @Override + public void getDataStreams(GetDataStreamsAction.Request request, ActionListener listener) { + execute(GetDataStreamsAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture getDataStreams(GetDataStreamsAction.Request request) { + return execute(GetDataStreamsAction.INSTANCE, request); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java index 64c1d1ad6c799..6826d220ac062 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.rest.BaseRestHandler; @@ -53,6 +53,6 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli putDataStreamRequest.setTimestampFieldName(timeStampFieldName); } }); - return channel -> client.admin().cluster().createDataStream(putDataStreamRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().indices().createDataStream(putDataStreamRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java index ed6b0353687e3..747ea3ed5a9bf 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; @@ -42,6 +42,6 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { DeleteDataStreamAction.Request deleteDataStreamRequest = new DeleteDataStreamAction.Request(request.param("name")); - return channel -> client.admin().cluster().deleteDataStream(deleteDataStreamRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().indices().deleteDataStream(deleteDataStreamRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java index ed333ed56e7b5..658cb8d8fb5fe 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.rest.action.admin.cluster; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; @@ -47,6 +47,6 @@ public List routes() { protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { String[] names = Strings.splitStringByCommaToArray(request.param("name")); GetDataStreamsAction.Request getDataStreamsRequest = new GetDataStreamsAction.Request(names); - return channel -> client.admin().cluster().getDataStreams(getDataStreamsRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().indices().getDataStreams(getDataStreamsRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java index e3b15cada46e1..d6a846c205fb3 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/CreateDataStreamRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/CreateDataStreamRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; -import org.elasticsearch.action.admin.cluster.datastream.CreateDataStreamAction.Request; +import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java index 9af8056b194f0..f460065699795 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/DeleteDataStreamRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; -import org.elasticsearch.action.admin.cluster.datastream.DeleteDataStreamAction.Request; +import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java similarity index 91% rename from server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java rename to server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java index 05a6a8881aa6b..062bdef629cc9 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsRequestTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction.Request; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Request; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java similarity index 94% rename from server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java rename to server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java index 89726cf2ae30f..5c74c515634cc 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/datastream/GetDataStreamsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsResponseTests.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.action.admin.cluster.datastream; +package org.elasticsearch.action.admin.indices.datastream; -import org.elasticsearch.action.admin.cluster.datastream.GetDataStreamsAction.Response; +import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction.Response; import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; From 7130a27a40557ec07594d8c0bbc8091cab3e2d38 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 19 Mar 2020 22:40:30 +0100 Subject: [PATCH 09/14] Make data stream crud apis work like a indices based api. --- .../admin/indices/datastream/GetDataStreamsAction.java | 2 +- .../security/authz/privilege/ClusterPrivilegeResolver.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java index a19514bb82a03..1549f056e811f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/datastream/GetDataStreamsAction.java @@ -48,7 +48,7 @@ public class GetDataStreamsAction extends ActionType { public static final GetDataStreamsAction INSTANCE = new GetDataStreamsAction(); - public static final String NAME = "indices:admin/data_streams/get"; + public static final String NAME = "indices:admin/data_stream/get"; private GetDataStreamsAction() { super(NAME, Response::new); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java index 7715b81c30c4b..59d03e1d7fdc8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java @@ -53,7 +53,7 @@ public class ClusterPrivilegeResolver { private static final Set MONITOR_TRANSFORM_PATTERN = Set.of("cluster:monitor/data_frame/*", "cluster:monitor/transform/*"); private static final Set MONITOR_WATCHER_PATTERN = Set.of("cluster:monitor/xpack/watcher/*"); private static final Set MONITOR_ROLLUP_PATTERN = Set.of("cluster:monitor/xpack/rollup/*"); - private static final Set ALL_CLUSTER_PATTERN = Set.of("cluster:*", "indices:admin/template/*"); + private static final Set ALL_CLUSTER_PATTERN = Set.of("cluster:*", "indices:admin/template/*", "indices:admin/data_stream/*"); private static final Set MANAGE_ML_PATTERN = Set.of("cluster:admin/xpack/ml/*", "cluster:monitor/xpack/ml/*"); private static final Set MANAGE_TRANSFORM_PATTERN = Set.of("cluster:admin/data_frame/*", "cluster:monitor/data_frame/*", "cluster:monitor/transform/*", "cluster:admin/transform/*"); @@ -193,7 +193,9 @@ public static Set names() { } public static boolean isClusterAction(String actionName) { - return actionName.startsWith("cluster:") || actionName.startsWith("indices:admin/template/"); + return actionName.startsWith("cluster:") || + actionName.startsWith("indices:admin/template/") || + actionName.startsWith("indices:admin/data_stream/"); } private static String actionToPattern(String text) { From ce73ee8291a398dffdbc34548d35feb6008e9998 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 19 Mar 2020 22:49:00 +0100 Subject: [PATCH 10/14] renamed timestamp field --- .../test/indices.data_stream/10_basic.yml | 6 ++--- .../cluster/metadata/DataStream.java | 22 +++++++++---------- .../cluster/RestCreateDataStreamAction.java | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml index e06290630308b..49754005b6db5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.data_stream/10_basic.yml @@ -8,16 +8,16 @@ indices.create_data_stream: name: data-stream2 body: - timestamp_field_name: "@timestamp" + timestamp_field: "@timestamp" - is_true: acknowledged - do: indices.get_data_streams: {} - match: { 0.name: my_data_stream1 } - - match: { 0.timestamp_field_name: '@timestamp' } + - match: { 0.timestamp_field: '@timestamp' } - match: { 0.indices: ['my_data_stream1-000000'] } - match: { 1.name: my_data_stream2 } - - match: { 1.timestamp_field_name: '@timestamp' } + - match: { 1.timestamp_field: '@timestamp' } - match: { 1.indices: [] } - do: diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java index 9d8675ad84236..f6bba191a173b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java @@ -35,12 +35,12 @@ public final class DataStream extends AbstractDiffable implements ToXContentObject { private final String name; - private final String timeStampFieldName; + private final String timeStampField; private final List indices; - public DataStream(String name, String timeStampFieldName, List indices) { + public DataStream(String name, String timeStampField, List indices) { this.name = name; - this.timeStampFieldName = timeStampFieldName; + this.timeStampField = timeStampField; this.indices = indices; } @@ -48,8 +48,8 @@ public String getName() { return name; } - public String getTimeStampFieldName() { - return timeStampFieldName; + public String getTimeStampField() { + return timeStampField; } public List getIndices() { @@ -67,12 +67,12 @@ public static Diff readDiffFrom(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(name); - out.writeString(timeStampFieldName); + out.writeString(timeStampField); out.writeStringCollection(indices); } public static final ParseField NAME_FIELD = new ParseField("name"); - public static final ParseField TIMESTAMP_FIELD_NAME_FIELD = new ParseField("timestamp_field_name"); + public static final ParseField TIMESTAMP_FIELD_FIELD = new ParseField("timestamp_field"); public static final ParseField INDICES_FIELD = new ParseField("indices"); @SuppressWarnings("unchecked") @@ -81,7 +81,7 @@ public void writeTo(StreamOutput out) throws IOException { static { PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME_FIELD); - PARSER.declareString(ConstructingObjectParser.constructorArg(), TIMESTAMP_FIELD_NAME_FIELD); + PARSER.declareString(ConstructingObjectParser.constructorArg(), TIMESTAMP_FIELD_FIELD); PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), INDICES_FIELD); } @@ -93,7 +93,7 @@ public static DataStream fromXContent(XContentParser parser) throws IOException public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(NAME_FIELD.getPreferredName(), name); - builder.field(TIMESTAMP_FIELD_NAME_FIELD.getPreferredName(), timeStampFieldName); + builder.field(TIMESTAMP_FIELD_FIELD.getPreferredName(), timeStampField); builder.field(INDICES_FIELD.getPreferredName(), indices); builder.endObject(); return builder; @@ -105,12 +105,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; DataStream that = (DataStream) o; return name.equals(that.name) && - timeStampFieldName.equals(that.timeStampFieldName) && + timeStampField.equals(that.timeStampField) && indices.equals(that.indices); } @Override public int hashCode() { - return Objects.hash(name, timeStampFieldName, indices); + return Objects.hash(name, timeStampField, indices); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java index 6826d220ac062..9a11a0d768905 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java @@ -48,7 +48,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli CreateDataStreamAction.Request putDataStreamRequest = new CreateDataStreamAction.Request(request.param("name")); request.withContentOrSourceParamParserOrNull(parser -> { Map body = parser.map(); - String timeStampFieldName = (String) body.get(DataStream.TIMESTAMP_FIELD_NAME_FIELD.getPreferredName()); + String timeStampFieldName = (String) body.get(DataStream.TIMESTAMP_FIELD_FIELD.getPreferredName()); if (timeStampFieldName != null) { putDataStreamRequest.setTimestampFieldName(timeStampFieldName); } From b133074999393f10b0c6f854493157da31a4d1b6 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 20 Mar 2020 09:07:59 +0100 Subject: [PATCH 11/14] fixed compile error after merging in master --- .../src/main/java/org/elasticsearch/action/ActionModule.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index d7c35b1e05e46..749e7a04be6c7 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -378,7 +378,6 @@ public class ActionModule extends AbstractModule { private static final Logger logger = LogManager.getLogger(ActionModule.class); private static final boolean ITV2_FEATURE_FLAG_REGISTERED; - private static final boolean DATASTREAMS_FEATURE_FLAG_REGISTERED; static { final String property = System.getProperty("es.itv2_feature_flag_registered"); @@ -393,7 +392,11 @@ public class ActionModule extends AbstractModule { throw new IllegalArgumentException("expected es.itv2_feature_flag_registered to be unset, true, or false but was [" + property + "]"); } + } + private static final boolean DATASTREAMS_FEATURE_FLAG_REGISTERED; + + static { final String property = System.getProperty("es.datastreams_feature_flag_registered"); if (Build.CURRENT.isSnapshot() && property != null) { throw new IllegalArgumentException("es.datastreams_feature_flag_registered is only supported in non-snapshot builds"); From 56c58794a1e2c37067cedf696152604170133c26 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 20 Mar 2020 09:48:56 +0100 Subject: [PATCH 12/14] fixed merge mistake --- .../java/org/elasticsearch/client/RestHighLevelClientTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 0f488462c1678..b35f59c3740da 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -794,7 +794,6 @@ public void testApiNamingConventions() throws Exception { "cluster.put_component_template", "cluster.get_component_template", "cluster.delete_component_template", - "scripts_painless_execute", "indices.create_data_stream", "indices.get_data_streams", "indices.delete_data_stream" From 1ed4eeaa6ba3618210692ad593c08160d85bca23 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 20 Mar 2020 09:51:18 +0100 Subject: [PATCH 13/14] moved setting system property --- x-pack/qa/core-rest-tests-with-security/build.gradle | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x-pack/qa/core-rest-tests-with-security/build.gradle b/x-pack/qa/core-rest-tests-with-security/build.gradle index 0e662ce8903ee..651c6af0308a2 100644 --- a/x-pack/qa/core-rest-tests-with-security/build.gradle +++ b/x-pack/qa/core-rest-tests-with-security/build.gradle @@ -28,10 +28,6 @@ integTest { } testClusters.integTest { - if (BuildParams.isSnapshotBuild() == false) { - systemProperty 'es.datastreams_feature_flag_registered', 'true' - } - testDistribution = 'DEFAULT' setting 'xpack.ilm.enabled', 'false' setting 'xpack.security.enabled', 'true' @@ -47,5 +43,6 @@ testClusters.integTest { testClusters.integTest { if (BuildParams.isSnapshotBuild() == false) { systemProperty 'es.itv2_feature_flag_registered', 'true' + systemProperty 'es.datastreams_feature_flag_registered', 'true' } } From 9e58488c6c2802d9b142adbbdb047185b58242df Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Fri, 20 Mar 2020 10:07:02 +0100 Subject: [PATCH 14/14] applied review comments --- .../main/java/org/elasticsearch/action/ActionModule.java | 6 +++--- .../{cluster => indices}/RestCreateDataStreamAction.java | 4 ++-- .../{cluster => indices}/RestDeleteDataStreamAction.java | 4 ++-- .../{cluster => indices}/RestGetDataStreamsAction.java | 4 ++-- .../security/authz/privilege/ClusterPrivilegeResolver.java | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) rename server/src/main/java/org/elasticsearch/rest/action/admin/{cluster => indices}/RestCreateDataStreamAction.java (95%) rename server/src/main/java/org/elasticsearch/rest/action/admin/{cluster => indices}/RestDeleteDataStreamAction.java (94%) rename server/src/main/java/org/elasticsearch/rest/action/admin/{cluster => indices}/RestGetDataStreamsAction.java (94%) diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 749e7a04be6c7..894f0805564e3 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -253,11 +253,11 @@ import org.elasticsearch.rest.action.admin.cluster.RestClusterStatsAction; import org.elasticsearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction; import org.elasticsearch.rest.action.admin.cluster.RestCreateSnapshotAction; -import org.elasticsearch.rest.action.admin.cluster.RestDeleteDataStreamAction; +import org.elasticsearch.rest.action.admin.indices.RestDeleteDataStreamAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteRepositoryAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteSnapshotAction; import org.elasticsearch.rest.action.admin.cluster.RestDeleteStoredScriptAction; -import org.elasticsearch.rest.action.admin.cluster.RestGetDataStreamsAction; +import org.elasticsearch.rest.action.admin.indices.RestGetDataStreamsAction; import org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction; import org.elasticsearch.rest.action.admin.cluster.RestGetScriptContextAction; import org.elasticsearch.rest.action.admin.cluster.RestGetScriptLanguageAction; @@ -270,7 +270,7 @@ import org.elasticsearch.rest.action.admin.cluster.RestNodesStatsAction; import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction; import org.elasticsearch.rest.action.admin.cluster.RestPendingClusterTasksAction; -import org.elasticsearch.rest.action.admin.cluster.RestCreateDataStreamAction; +import org.elasticsearch.rest.action.admin.indices.RestCreateDataStreamAction; import org.elasticsearch.rest.action.admin.cluster.RestPutRepositoryAction; import org.elasticsearch.rest.action.admin.cluster.RestPutStoredScriptAction; import org.elasticsearch.rest.action.admin.cluster.RestReloadSecureSettingsAction; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateDataStreamAction.java similarity index 95% rename from server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java rename to server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateDataStreamAction.java index 9a11a0d768905..67b67677195dc 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateDataStreamAction.java @@ -7,7 +7,7 @@ * 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 + * 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 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.rest.action.admin.cluster; +package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; import org.elasticsearch.client.node.NodeClient; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteDataStreamAction.java similarity index 94% rename from server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java rename to server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteDataStreamAction.java index 747ea3ed5a9bf..b69ee981d12b3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDataStreamAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteDataStreamAction.java @@ -7,7 +7,7 @@ * 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 + * 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 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.rest.action.admin.cluster; +package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; import org.elasticsearch.client.node.NodeClient; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetDataStreamsAction.java similarity index 94% rename from server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java rename to server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetDataStreamsAction.java index 658cb8d8fb5fe..fdbe63829882e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetDataStreamsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetDataStreamsAction.java @@ -7,7 +7,7 @@ * 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 + * 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 @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.rest.action.admin.cluster; +package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; import org.elasticsearch.client.node.NodeClient; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java index e3ff022ec35c8..23023001e27f1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java @@ -199,6 +199,7 @@ public static Set names() { public static boolean isClusterAction(String actionName) { return actionName.startsWith("cluster:") || actionName.startsWith("indices:admin/template/") || + // todo: hack until we implement security of data_streams actionName.startsWith("indices:admin/data_stream/"); }