From 045aaaed2ac8f596371dafebfac98dbddea77b15 Mon Sep 17 00:00:00 2001 From: jaymode Date: Fri, 28 Feb 2020 14:00:38 -0700 Subject: [PATCH 01/21] Add logstash module with wrapped APIs --- modules/logstash/build.gradle | 23 +++ .../logstash/LogstashPlugin.java | 100 +++++++++++++ .../logstash/LogstashPluginTests.java | 37 +++++ .../logstash/LogstashSystemIndexIT.java | 132 ++++++++++++++++++ 4 files changed, 292 insertions(+) create mode 100644 modules/logstash/build.gradle create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java create mode 100644 modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java create mode 100644 modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java diff --git a/modules/logstash/build.gradle b/modules/logstash/build.gradle new file mode 100644 index 0000000000000..68bb45487ee56 --- /dev/null +++ b/modules/logstash/build.gradle @@ -0,0 +1,23 @@ +/* + * 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. + */ + +esplugin { + description 'Plugin exposing APIs for the Logstash system index' + classname 'org.elasticsearch.logstash.LogstashPlugin' +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java new file mode 100644 index 0000000000000..999be689e5338 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java @@ -0,0 +1,100 @@ +/* + * 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.logstash; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.SystemIndexPlugin; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.document.RestDeleteAction; +import org.elasticsearch.rest.action.document.RestGetAction; +import org.elasticsearch.rest.action.document.RestIndexAction; +import org.elasticsearch.rest.action.document.RestMultiGetAction; +import org.elasticsearch.rest.action.search.RestClearScrollAction; +import org.elasticsearch.rest.action.search.RestSearchAction; +import org.elasticsearch.rest.action.search.RestSearchScrollAction; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class LogstashPlugin extends Plugin implements SystemIndexPlugin, ActionPlugin { + + public Collection getSystemIndexDescriptors(Settings settings) { + return Collections.singleton(new SystemIndexDescriptor(".logstash*", "Logstash system indices for storing pipelines")); + } + + @Override + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { + return Collections.unmodifiableList(Arrays.asList( + new LogstashWrappedRestHandler(new RestGetAction()), + new LogstashWrappedRestHandler(new RestMultiGetAction(settings)), + new LogstashWrappedRestHandler(new RestIndexAction()), + new LogstashWrappedRestHandler(new RestDeleteAction()), + new LogstashWrappedRestHandler(new RestSearchAction()), + new LogstashWrappedRestHandler(new RestSearchScrollAction()), + new LogstashWrappedRestHandler(new RestClearScrollAction()) + )); + } + + static class LogstashWrappedRestHandler extends BaseRestHandler.Wrapper { + + private final List allowedIndexPatterns = Collections.singletonList(".logstash"); + + LogstashWrappedRestHandler(BaseRestHandler delegate) { + super(delegate); + } + + @Override + public String getName() { + return "logstash_" + super.getName(); + } + + @Override + public List routes() { + return super.routes().stream().map(route -> new Route(route.getMethod(), "/_logstash" + route.getPath())) + .collect(Collectors.toUnmodifiableList()); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + client.threadPool().getThreadContext().allowSystemIndexAccess(allowedIndexPatterns); + return super.prepareRequest(request, client); + } + } +} diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java new file mode 100644 index 0000000000000..ab4d3332ef14f --- /dev/null +++ b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java @@ -0,0 +1,37 @@ +/* + * 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.logstash; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.test.ESTestCase; + +import java.util.stream.Collectors; + +import static org.hamcrest.Matchers.contains; + +public class LogstashPluginTests extends ESTestCase { + + public void testSystemIndices() { + assertThat(new LogstashPlugin().getSystemIndexDescriptors(Settings.EMPTY).stream() + .map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toUnmodifiableList()), + contains(".logstash*")); + } +} diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java new file mode 100644 index 0000000000000..2f0643ed44199 --- /dev/null +++ b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java @@ -0,0 +1,132 @@ +/* + * 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.logstash; + +import org.apache.http.util.EntityUtils; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.test.rest.ESRestTestCase; + +import java.io.IOException; +import java.util.Map; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + +public class LogstashSystemIndexIT extends ESRestTestCase { + + public void testIndexingDoc() throws IOException { + Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); + request.setJsonEntity("{ \"foo\" : \"bar\" }"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + } + + public void testDeleteFromLogstashIndex() throws IOException { + Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); + request.setJsonEntity("{ \"foo\" : \"bar\" }"); + request.addParameter("refresh", "true"); + + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + + Request deleteRequest = new Request("DELETE", "/_logstash/.logstash/_doc/1"); + Response deleteResponse = client().performRequest(deleteRequest); + assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200)); + } + + public void testGetFromLogstashIndex() throws IOException { + Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); + request.setJsonEntity("{ \"foo\" : \"bar\" }"); + + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + + Request getRequest = new Request("GET", "/_logstash/.logstash/_doc/1"); + Response getResponse = client().performRequest(getRequest); + assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); + String responseBody = EntityUtils.toString(getResponse.getEntity()); + assertThat(responseBody, containsString("foo")); + assertThat(responseBody, containsString("bar")); + } + + public void testMultiGetFromLogstashIndex() throws IOException { + Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); + request.setJsonEntity("{ \"foo\" : \"bar\" }"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + request = new Request("POST", "/_logstash/.logstash/_doc/2"); + request.setJsonEntity("{ \"baz\" : \"tag\" }"); + response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + + Request getRequest = new Request("GET", "/_logstash/_mget"); + getRequest.setJsonEntity("{ \"docs\" : [ { \"_index\" : \".logstash\", \"_id\" : \"1\" }, " + + "{ \"_index\" : \".logstash\", \"_id\" : \"2\" } ] }\n"); + Response getResponse = client().performRequest(getRequest); + assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); + String responseBody = EntityUtils.toString(getResponse.getEntity()); + assertThat(responseBody, containsString("foo")); + assertThat(responseBody, containsString("bar")); + assertThat(responseBody, containsString("baz")); + assertThat(responseBody, containsString("tag")); + } + + public void testScrollingDocs() throws IOException { + Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); + request.setJsonEntity("{ \"foo\" : \"bar\" }"); + Response response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + request = new Request("POST", "/_logstash/.logstash/_doc/2"); + request.setJsonEntity("{ \"baz\" : \"tag\" }"); + response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + request = new Request("POST", "/_logstash/.logstash/_doc/3"); + request.setJsonEntity("{ \"boom\" : \"ab\" }"); + request.addParameter("refresh", "true"); + response = client().performRequest(request); + assertThat(response.getStatusLine().getStatusCode(), is(201)); + + Request searchRequest = new Request("GET", "/_logstash/.logstash/_search"); + searchRequest.setJsonEntity("{ \"size\" : 1,\n\"query\" : { \"match_all\" : {} } }\n"); + searchRequest.addParameter("scroll", "1m"); + response = client().performRequest(searchRequest); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + Map map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); + assertNotNull(map.get("_scroll_id")); + String scrollId = (String) map.get("_scroll_id"); + + Request scrollRequest = new Request("POST", "/_logstash/_search/scroll"); + scrollRequest.addParameter("scroll_id", scrollId); + scrollRequest.addParameter("scroll", "1m"); + response = client().performRequest(scrollRequest); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); + assertNotNull(map.get("_scroll_id")); + scrollId = (String) map.get("_scroll_id"); + + Request clearScrollRequest = new Request("DELETE", "/_logstash/_search/scroll"); + clearScrollRequest.addParameter("scroll_id", scrollId); + response = client().performRequest(clearScrollRequest); + assertThat(response.getStatusLine().getStatusCode(), is(200)); + } +} From 742c6216b4bf508b5752da70953bd1e2b401b35a Mon Sep 17 00:00:00 2001 From: jaymode Date: Mon, 9 Mar 2020 13:19:57 -0600 Subject: [PATCH 02/21] remove wrapped APIs and add dedicated logstash APIs --- build.gradle | 1 + .../logstash/LogstashPlugin.java | 103 +++++---- .../org/elasticsearch/logstash/Pipeline.java | 115 ++++++++++ .../logstash/action/DeletePipelineAction.java | 32 +++ .../action/DeletePipelineRequest.java | 49 ++++ .../action/DeletePipelineResponse.java | 49 ++++ .../logstash/action/GetPipelineAction.java | 32 +++ .../logstash/action/GetPipelineRequest.java | 58 +++++ .../logstash/action/GetPipelineResponse.java | 63 ++++++ .../logstash/action/PutPipelineAction.java | 32 +++ .../logstash/action/PutPipelineRequest.java | 73 ++++++ .../logstash/action/PutPipelineResponse.java | 51 +++++ .../action/TransportDeletePipelineAction.java | 51 +++++ .../action/TransportGetPipelineAction.java | 156 +++++++++++++ .../action/TransportPutPipelineAction.java | 52 +++++ .../rest/RestDeletePipelineAction.java | 65 ++++++ .../logstash/rest/RestGetPipelineAction.java | 65 ++++++ .../logstash/rest/RestPutPipelineAction.java | 75 +++++++ .../src/main/resources/pipelines.json | 12 + .../logstash/LogstashPluginTests.java | 10 +- .../logstash/LogstashSystemIndexIT.java | 211 +++++++++++------- 21 files changed, 1226 insertions(+), 129 deletions(-) create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java create mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java create mode 100644 modules/logstash/src/main/resources/pipelines.json diff --git a/build.gradle b/build.gradle index 39d227461a5c6..798cd3b3720b4 100644 --- a/build.gradle +++ b/build.gradle @@ -114,6 +114,7 @@ subprojects { ':distribution:tools:keystore-cli', ':distribution:tools:launchers', ':distribution:tools:plugin-cli', + ':modules:logstash', ':qa:os', ':x-pack:plugin:autoscaling', ':x-pack:plugin:enrich' diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java index 999be689e5338..d98275be69010 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java @@ -19,82 +19,89 @@ package org.elasticsearch.logstash; -import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.common.xcontent.DeprecationHandler; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.logstash.action.DeletePipelineAction; +import org.elasticsearch.logstash.action.GetPipelineAction; +import org.elasticsearch.logstash.action.PutPipelineAction; +import org.elasticsearch.logstash.action.TransportDeletePipelineAction; +import org.elasticsearch.logstash.action.TransportGetPipelineAction; +import org.elasticsearch.logstash.action.TransportPutPipelineAction; +import org.elasticsearch.logstash.rest.RestDeletePipelineAction; +import org.elasticsearch.logstash.rest.RestGetPipelineAction; +import org.elasticsearch.logstash.rest.RestPutPipelineAction; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.document.RestDeleteAction; -import org.elasticsearch.rest.action.document.RestGetAction; -import org.elasticsearch.rest.action.document.RestIndexAction; -import org.elasticsearch.rest.action.document.RestMultiGetAction; -import org.elasticsearch.rest.action.search.RestClearScrollAction; -import org.elasticsearch.rest.action.search.RestSearchAction; -import org.elasticsearch.rest.action.search.RestSearchScrollAction; import java.io.IOException; -import java.util.Arrays; +import java.io.UncheckedIOException; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.function.Supplier; -import java.util.stream.Collectors; +import java.util.function.UnaryOperator; public class LogstashPlugin extends Plugin implements SystemIndexPlugin, ActionPlugin { + @Override public Collection getSystemIndexDescriptors(Settings settings) { return Collections.singleton(new SystemIndexDescriptor(".logstash*", "Logstash system indices for storing pipelines")); } @Override - public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, - IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, - IndexNameExpressionResolver indexNameExpressionResolver, - Supplier nodesInCluster) { - return Collections.unmodifiableList(Arrays.asList( - new LogstashWrappedRestHandler(new RestGetAction()), - new LogstashWrappedRestHandler(new RestMultiGetAction(settings)), - new LogstashWrappedRestHandler(new RestIndexAction()), - new LogstashWrappedRestHandler(new RestDeleteAction()), - new LogstashWrappedRestHandler(new RestSearchAction()), - new LogstashWrappedRestHandler(new RestSearchScrollAction()), - new LogstashWrappedRestHandler(new RestClearScrollAction()) - )); + public List> getActions() { + return List.of( + new ActionHandler<>(PutPipelineAction.INSTANCE, TransportPutPipelineAction.class), + new ActionHandler<>(GetPipelineAction.INSTANCE, TransportGetPipelineAction.class), + new ActionHandler<>(DeletePipelineAction.INSTANCE, TransportDeletePipelineAction.class) + ); } - static class LogstashWrappedRestHandler extends BaseRestHandler.Wrapper { - - private final List allowedIndexPatterns = Collections.singletonList(".logstash"); - - LogstashWrappedRestHandler(BaseRestHandler delegate) { - super(delegate); - } - - @Override - public String getName() { - return "logstash_" + super.getName(); - } - - @Override - public List routes() { - return super.routes().stream().map(route -> new Route(route.getMethod(), "/_logstash" + route.getPath())) - .collect(Collectors.toUnmodifiableList()); - } + @Override + public List getRestHandlers( + Settings settings, + RestController restController, + ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, + SettingsFilter settingsFilter, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster + ) { + return List.of(new RestPutPipelineAction(), new RestGetPipelineAction(), new RestDeletePipelineAction()); + } - @Override - protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - client.threadPool().getThreadContext().allowSystemIndexAccess(allowedIndexPatterns); - return super.prepareRequest(request, client); - } + @Override + public UnaryOperator> getIndexTemplateMetaDataUpgrader() { + return map -> { + try ( + XContentParser parser = JsonXContent.jsonXContent.createParser( + NamedXContentRegistry.EMPTY, + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, + LogstashPlugin.class.getResourceAsStream("/pipelines.json") + ) + ) { + IndexTemplateMetaData metaData = IndexTemplateMetaData.Builder.fromXContent(parser, ".logstash-pipeline"); + map.put(".logstash-pipeline", metaData); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + return map; + }; } } diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java new file mode 100644 index 0000000000000..3427a37bb1e7a --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java @@ -0,0 +1,115 @@ +/* + * 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.logstash; + +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser.ValueType; + +import java.time.Instant; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; + +import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; + +public class Pipeline { + + @SuppressWarnings("unchecked") + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "pipeline", + true, + (objects, id) -> { + Iterator iterator = Arrays.asList(objects).iterator(); + return new Pipeline( + id, + (Instant) iterator.next(), + (Map) iterator.next(), + (String) iterator.next(), + (String) iterator.next(), + (Map) iterator.next() + ); + } + ); + + public static final ParseField LAST_MODIFIED = new ParseField("last_modified"); + public static final ParseField PIPELINE_METADATA = new ParseField("pipeline_metadata"); + public static final ParseField USERNAME = new ParseField("username"); + public static final ParseField PIPELINE = new ParseField("pipeline"); + public static final ParseField PIPELINE_SETTINGS = new ParseField("pipeline_settings"); + + static { + PARSER.declareField(constructorArg(), (parser, s) -> { + final String instantISOString = parser.text(); + return Instant.parse(instantISOString); + }, LAST_MODIFIED, ValueType.STRING); + PARSER.declareObject(constructorArg(), (parser, s) -> parser.map(), PIPELINE_METADATA); + PARSER.declareString(constructorArg(), USERNAME); + PARSER.declareString(constructorArg(), PIPELINE); + PARSER.declareObject(constructorArg(), (parser, s) -> parser.map(), PIPELINE_SETTINGS); + } + + private final String id; + private final Instant lastModified; + private final Map pipelineMetadata; + private final String username; + private final String pipeline; + private final Map pipelineSettings; + + public Pipeline( + String id, + Instant lastModified, + Map pipelineMetadata, + String username, + String pipeline, + Map pipelineSettings + ) { + this.id = id; + this.lastModified = lastModified; + this.pipelineMetadata = pipelineMetadata; + this.username = username; + this.pipeline = pipeline; + this.pipelineSettings = pipelineSettings; + } + + public String getId() { + return id; + } + + public Instant getLastModified() { + return lastModified; + } + + public Map getPipelineMetadata() { + return pipelineMetadata; + } + + public String getUsername() { + return username; + } + + public String getPipeline() { + return pipeline; + } + + public Map getPipelineSettings() { + return pipelineSettings; + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java new file mode 100644 index 0000000000000..387e4a46a6ca9 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java @@ -0,0 +1,32 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class DeletePipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/delete"; + public static final DeletePipelineAction INSTANCE = new DeletePipelineAction(); + + private DeletePipelineAction() { + super(NAME, DeletePipelineResponse::new); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java new file mode 100644 index 0000000000000..94d79cc2fb8e2 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java @@ -0,0 +1,49 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + +public class DeletePipelineRequest extends ActionRequest { + + private final String id; + + public DeletePipelineRequest(String id) { + this.id = id; + } + + public DeletePipelineRequest(StreamInput in) throws IOException { + super(in); + this.id = in.readString(); + } + + public String id() { + return id; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java new file mode 100644 index 0000000000000..89514700b19db --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java @@ -0,0 +1,49 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +public class DeletePipelineResponse extends ActionResponse { + + private final boolean deleted; + + public DeletePipelineResponse(boolean deleted) { + this.deleted = deleted; + } + + public DeletePipelineResponse(StreamInput in) throws IOException { + super(in); + this.deleted = in.readBoolean(); + } + + public boolean isDeleted() { + return deleted; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeBoolean(deleted); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java new file mode 100644 index 0000000000000..ee93fc8c324b2 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java @@ -0,0 +1,32 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class GetPipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/get"; + public static final GetPipelineAction INSTANCE = new GetPipelineAction(); + + private GetPipelineAction() { + super(NAME, GetPipelineResponse::new); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java new file mode 100644 index 0000000000000..b6ae83a1343a0 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.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.logstash.action; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +public class GetPipelineRequest extends ActionRequest { + + private final List ids; + + public GetPipelineRequest(List ids) { + this.ids = Objects.requireNonNull(ids); + } + + public GetPipelineRequest(StreamInput in) throws IOException { + super(in); + ids = in.readStringList(); + } + + public List ids() { + return ids; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringCollection(ids); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java new file mode 100644 index 0000000000000..27c7153e75e5a --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java @@ -0,0 +1,63 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.bytes.BytesReference; +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 java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; + +public class GetPipelineResponse extends ActionResponse implements ToXContentObject { + + private final Map pipelines; + + public GetPipelineResponse(Map pipelines) { + this.pipelines = pipelines; + } + + public GetPipelineResponse(StreamInput in) throws IOException { + super(in); + this.pipelines = in.readMap(StreamInput::readString, StreamInput::readBytesReference); + } + + public Map pipelines() { + return pipelines; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeMap(pipelines, StreamOutput::writeString, StreamOutput::writeBytesReference); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + for (Entry entry : pipelines.entrySet()) { + builder.rawField(entry.getKey(), entry.getValue().streamInput()); + } + return builder.endObject(); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java new file mode 100644 index 0000000000000..756ca8e768053 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java @@ -0,0 +1,32 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class PutPipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/put"; + public static final PutPipelineAction INSTANCE = new PutPipelineAction(); + + private PutPipelineAction() { + super(NAME, PutPipelineResponse::new); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java new file mode 100644 index 0000000000000..98f6593242b92 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java @@ -0,0 +1,73 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; +import java.util.Objects; + +public class PutPipelineRequest extends ActionRequest { + + private final String id; + private final String source; + private final XContentType xContentType; + + public PutPipelineRequest(String id, String source, XContentType xContentType) { + this.id = id; + this.source = Objects.requireNonNull(source); + this.xContentType = Objects.requireNonNull(xContentType); + } + + public PutPipelineRequest(StreamInput in) throws IOException { + super(in); + this.id = in.readString(); + this.source = in.readString(); + this.xContentType = in.readEnum(XContentType.class); + } + + public String getId() { + return id; + } + + public String getSource() { + return source; + } + + public XContentType getxContentType() { + return xContentType; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(source); + out.writeEnum(xContentType); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java new file mode 100644 index 0000000000000..7105c758414e1 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java @@ -0,0 +1,51 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.rest.RestStatus; + +import java.io.IOException; +import java.util.Objects; + +public class PutPipelineResponse extends ActionResponse { + + private final RestStatus status; + + public PutPipelineResponse(RestStatus status) { + this.status = Objects.requireNonNull(status); + } + + public PutPipelineResponse(StreamInput in) throws IOException { + super(in); + this.status = in.readEnum(RestStatus.class); + } + + public RestStatus getStatus() { + return status; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeEnum(status); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java new file mode 100644 index 0000000000000..98debc4e126f7 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java @@ -0,0 +1,51 @@ +/* + * 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.logstash.action; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.DocWriteResponse.Result; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.HandledTransportAction; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.transport.TransportService; + +public class TransportDeletePipelineAction extends HandledTransportAction { + + private final Client client; + + @Inject + public TransportDeletePipelineAction(TransportService transportService, ActionFilters actionFilters, Client client) { + super(DeletePipelineAction.NAME, transportService, actionFilters, DeletePipelineRequest::new); + this.client = client; + } + + @Override + protected void doExecute(Task task, DeletePipelineRequest request, ActionListener listener) { + client.prepareDelete(".logstash", request.id()) + .execute( + ActionListener.wrap( + deleteResponse -> listener.onResponse(new DeletePipelineResponse(deleteResponse.getResult() == Result.DELETED)), + listener::onFailure + ) + ); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java new file mode 100644 index 0000000000000..8bfbdf846a540 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java @@ -0,0 +1,156 @@ +/* + * 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.logstash.action; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessage; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.search.ClearScrollRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.HandledTransportAction; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.transport.TransportService; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +public class TransportGetPipelineAction extends HandledTransportAction { + + private static final Logger logger = LogManager.getLogger(TransportGetPipelineAction.class); + private final Client client; + + @Inject + public TransportGetPipelineAction(TransportService transportService, ActionFilters actionFilters, Client client) { + super(GetPipelineAction.NAME, transportService, actionFilters, GetPipelineRequest::new); + this.client = client; + } + + @Override + protected void doExecute(Task task, GetPipelineRequest request, ActionListener listener) { + if (request.ids().isEmpty()) { + client.prepareSearch(".logstash") + .setSource( + SearchSourceBuilder.searchSource() + .fetchSource(true) + .query(QueryBuilders.matchAllQuery()) + .size(1000) + .trackTotalHits(true) + ) + .setScroll(TimeValue.timeValueMinutes(1L)) + .execute(ActionListener.wrap(searchResponse -> { + final int numHits = Math.toIntExact(searchResponse.getHits().getTotalHits().value); + final Map pipelineSources = new HashMap<>(numHits); + final Consumer clearScroll = (response) -> { + if (response != null && response.getScrollId() != null) { + ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); + clearScrollRequest.addScrollId(response.getScrollId()); + client.clearScroll( + clearScrollRequest, + ActionListener.wrap( + (r) -> {}, + e -> logger.warn( + new ParameterizedMessage("clear scroll failed for scroll id [{}]", response.getScrollId()), + e + ) + ) + ); + } + }; + handleSearchResponse(searchResponse, pipelineSources, clearScroll, listener); + }, listener::onFailure)); + } else if (request.ids().size() == 1) { + client.prepareGet(".logstash", request.ids().get(0)).setFetchSource(true).execute(ActionListener.wrap(response -> { + if (response.isExists()) { + listener.onResponse(new GetPipelineResponse(Map.of(response.getId(), response.getSourceAsBytesRef()))); + } else { + listener.onResponse(new GetPipelineResponse(Map.of())); + } + }, listener::onFailure)); + } else { + client.prepareMultiGet() + .addIds(".logstash", request.ids()) + .execute( + ActionListener.wrap( + mGetResponse -> listener.onResponse( + new GetPipelineResponse( + Arrays.stream(mGetResponse.getResponses()) + .filter(itemResponse -> itemResponse.isFailed() == false) + .filter(itemResponse -> itemResponse.getResponse().isExists()) + .map(MultiGetItemResponse::getResponse) + .collect(Collectors.toMap(GetResponse::getId, GetResponse::getSourceAsBytesRef)) + ) + ), + listener::onFailure + ) + ); + } + } + + private void handleSearchResponse( + SearchResponse searchResponse, + Map pipelineSources, + Consumer clearScroll, + ActionListener listener + ) { + for (SearchHit hit : searchResponse.getHits().getHits()) { + pipelineSources.put(hit.getId(), hit.getSourceRef()); + } + + if (pipelineSources.size() > searchResponse.getHits().getTotalHits().value) { + clearScroll.accept(searchResponse); + listener.onFailure( + new IllegalStateException( + "scrolling returned more hits [" + + pipelineSources.size() + + "] than expected [" + + searchResponse.getHits().getTotalHits().value + + "] so bailing out to prevent unbounded " + + "memory consumption." + ) + ); + } else if (pipelineSources.size() == searchResponse.getHits().getTotalHits().value) { + clearScroll.accept(searchResponse); + listener.onResponse(new GetPipelineResponse(pipelineSources)); + } else { + client.prepareSearchScroll(searchResponse.getScrollId()) + .setScroll(TimeValue.timeValueMinutes(1L)) + .execute( + ActionListener.wrap( + searchResponse1 -> handleSearchResponse(searchResponse1, pipelineSources, clearScroll, listener), + listener::onFailure + ) + ); + } + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java new file mode 100644 index 0000000000000..d9ca9e3e4d114 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.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.logstash.action; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.HandledTransportAction; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.transport.TransportService; + +public class TransportPutPipelineAction extends HandledTransportAction { + + private final Client client; + + @Inject + public TransportPutPipelineAction(TransportService transportService, ActionFilters actionFilters, Client client) { + super(PutPipelineAction.NAME, transportService, actionFilters, PutPipelineRequest::new); + this.client = client; + } + + @Override + protected void doExecute(Task task, PutPipelineRequest request, ActionListener listener) { + client.prepareIndex(".logstash") + .setId(request.getId()) + .setSource(request.getSource(), request.getxContentType()) + .execute( + ActionListener.wrap( + indexResponse -> listener.onResponse(new PutPipelineResponse(indexResponse.status())), + listener::onFailure + ) + ); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java new file mode 100644 index 0000000000000..51aab2b078ae1 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java @@ -0,0 +1,65 @@ +/* + * 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.logstash.rest; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.logstash.action.DeletePipelineAction; +import org.elasticsearch.logstash.action.DeletePipelineRequest; +import org.elasticsearch.logstash.action.DeletePipelineResponse; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequest.Method; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.RestActionListener; + +import java.io.IOException; +import java.util.List; + +public class RestDeletePipelineAction extends BaseRestHandler { + + @Override + public String getName() { + return "logstash_delete_pipeline"; + } + + @Override + public List routes() { + return List.of(new Route(Method.DELETE, "/_logstash/pipeline/{id}")); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + final String id = request.param("id"); + return restChannel -> client.execute( + DeletePipelineAction.INSTANCE, + new DeletePipelineRequest(id), + new RestActionListener<>(restChannel) { + @Override + protected void processResponse(DeletePipelineResponse deletePipelineResponse) { + final RestStatus status = deletePipelineResponse.isDeleted() ? RestStatus.OK : RestStatus.NOT_FOUND; + channel.sendResponse(new BytesRestResponse(status, XContentType.JSON.mediaType(), BytesArray.EMPTY)); + } + } + ); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java new file mode 100644 index 0000000000000..ac3a15b380fb4 --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java @@ -0,0 +1,65 @@ +/* + * 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.logstash.rest; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.Strings; +import org.elasticsearch.logstash.action.GetPipelineAction; +import org.elasticsearch.logstash.action.GetPipelineRequest; +import org.elasticsearch.logstash.action.GetPipelineResponse; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequest.Method; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; + +public class RestGetPipelineAction extends BaseRestHandler { + + @Override + public String getName() { + return "logstash_get_pipeline"; + } + + @Override + public List routes() { + return List.of(new Route(Method.GET, "/_logstash/pipeline"), new Route(Method.GET, "/_logstash/pipeline/{id}")); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + final List ids = List.of(request.paramAsStringArray("id", Strings.EMPTY_ARRAY)); + return restChannel -> client.execute( + GetPipelineAction.INSTANCE, + new GetPipelineRequest(ids), + new RestToXContentListener<>(restChannel) { + @Override + protected RestStatus getStatus(GetPipelineResponse response) { + if (response.pipelines().isEmpty() && ids.isEmpty() == false) { + return RestStatus.NOT_FOUND; + } + return RestStatus.OK; + } + } + ); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java new file mode 100644 index 0000000000000..c6cf05812cece --- /dev/null +++ b/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java @@ -0,0 +1,75 @@ +/* + * 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.logstash.rest; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.logstash.Pipeline; +import org.elasticsearch.logstash.action.PutPipelineAction; +import org.elasticsearch.logstash.action.PutPipelineRequest; +import org.elasticsearch.logstash.action.PutPipelineResponse; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequest.Method; +import org.elasticsearch.rest.action.RestActionListener; + +import java.io.IOException; +import java.util.List; + +public class RestPutPipelineAction extends BaseRestHandler { + + @Override + public String getName() { + return "logstash_put_pipeline"; + } + + @Override + public List routes() { + return List.of(new Route(Method.PUT, "/_logstash/pipeline/{id}")); + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + final String id = request.param("id"); + try (XContentParser parser = request.contentParser()) { + // parse pipeline for validation + Pipeline.PARSER.apply(parser, id); + } + + return restChannel -> { + final String content = request.content().utf8ToString(); + client.execute( + PutPipelineAction.INSTANCE, + new PutPipelineRequest(id, content, request.getXContentType()), + new RestActionListener<>(restChannel) { + @Override + protected void processResponse(PutPipelineResponse putPipelineResponse) throws Exception { + channel.sendResponse( + new BytesRestResponse(putPipelineResponse.getStatus(), XContentType.JSON.mediaType(), BytesArray.EMPTY) + ); + } + } + ); + }; + } +} diff --git a/modules/logstash/src/main/resources/pipelines.json b/modules/logstash/src/main/resources/pipelines.json new file mode 100644 index 0000000000000..0c4392b549358 --- /dev/null +++ b/modules/logstash/src/main/resources/pipelines.json @@ -0,0 +1,12 @@ +{ + "index_patterns" : [ ".logstash*" ], + "settings" : { + "number_of_shards": 1, + "number_of_replicas": 0, + "auto_expand_replicas": "0-1" + }, + "mappings" : { + "dynamic" : "false" + }, + "version" : 1 +} diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java index ab4d3332ef14f..bc8cb02ceeef1 100644 --- a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java +++ b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java @@ -30,8 +30,12 @@ public class LogstashPluginTests extends ESTestCase { public void testSystemIndices() { - assertThat(new LogstashPlugin().getSystemIndexDescriptors(Settings.EMPTY).stream() - .map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toUnmodifiableList()), - contains(".logstash*")); + assertThat( + new LogstashPlugin().getSystemIndexDescriptors(Settings.EMPTY) + .stream() + .map(SystemIndexDescriptor::getIndexPattern) + .collect(Collectors.toUnmodifiableList()), + contains(".logstash*") + ); } } diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java index 2f0643ed44199..85cf48622cccb 100644 --- a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java +++ b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java @@ -22,11 +22,18 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; +import org.elasticsearch.client.ResponseException; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.rest.ESRestTestCase; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import static org.hamcrest.Matchers.containsString; @@ -34,99 +41,147 @@ public class LogstashSystemIndexIT extends ESRestTestCase { - public void testIndexingDoc() throws IOException { - Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); - request.setJsonEntity("{ \"foo\" : \"bar\" }"); - Response response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); + public void testTemplateIsPut() throws Exception { + assertBusy( + () -> assertThat( + client().performRequest(new Request("HEAD", "/_template/.logstash-pipeline")).getStatusLine().getStatusCode(), + is(200) + ) + ); } - public void testDeleteFromLogstashIndex() throws IOException { - Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); - request.setJsonEntity("{ \"foo\" : \"bar\" }"); - request.addParameter("refresh", "true"); + public void testPipelineCRUD() throws Exception { + // put pipeline + final String pipelineJson = getPipelineJson(); + createPipeline("test_pipeline", pipelineJson); - Response response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); + // get pipeline + Request getRequest = new Request("GET", "/_logstash/pipeline/test_pipeline"); + Response getResponse = client().performRequest(getRequest); + assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(getResponse.getEntity()), containsString(pipelineJson)); + + // update + final String updatedJson = getPipelineJson("2020-03-09T15:42:35.229Z"); + Request putRequest = new Request("PUT", "/_logstash/pipeline/test_pipeline"); + putRequest.setJsonEntity(updatedJson); + Response putResponse = client().performRequest(putRequest); + assertThat(putResponse.getStatusLine().getStatusCode(), is(200)); - Request deleteRequest = new Request("DELETE", "/_logstash/.logstash/_doc/1"); + getRequest = new Request("GET", "/_logstash/pipeline/test_pipeline"); + getResponse = client().performRequest(getRequest); + assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(getResponse.getEntity()), containsString(updatedJson)); + + // delete + Request deleteRequest = new Request("DELETE", "/_logstash/pipeline/test_pipeline"); Response deleteResponse = client().performRequest(deleteRequest); assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200)); + + // list is now empty + Request listAll = new Request("GET", "/_logstash/pipeline"); + Response listAllResponse = client().performRequest(listAll); + assertThat(listAllResponse.getStatusLine().getStatusCode(), is(200)); + assertThat(EntityUtils.toString(listAllResponse.getEntity()), is("{}")); } - public void testGetFromLogstashIndex() throws IOException { - Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); - request.setJsonEntity("{ \"foo\" : \"bar\" }"); + public void testGetNonExistingPipeline() { + Request getRequest = new Request("GET", "/_logstash/pipeline/test_pipeline"); + ResponseException re = expectThrows(ResponseException.class, () -> client().performRequest(getRequest)); + Response getResponse = re.getResponse(); + assertThat(getResponse.getStatusLine().getStatusCode(), is(404)); + } - Response response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); + public void testDeleteNonExistingPipeline() { + Request deleteRequest = new Request("DELETE", "/_logstash/pipeline/test_pipeline"); + ResponseException re = expectThrows(ResponseException.class, () -> client().performRequest(deleteRequest)); + Response getResponse = re.getResponse(); + assertThat(getResponse.getStatusLine().getStatusCode(), is(404)); + } - Request getRequest = new Request("GET", "/_logstash/.logstash/_doc/1"); + public void testMultiplePipelines() throws IOException { + final int numPipelines = scaledRandomIntBetween(2, 2000); + final List ids = new ArrayList<>(numPipelines); + final String pipelineJson = getPipelineJson(); + for (int i = 0; i < numPipelines; i++) { + final String id = "id" + i; + ids.add(id); + createPipeline(id, pipelineJson); + } + + // test mget-like + final int numToGet = scaledRandomIntBetween(2, Math.min(100, numPipelines)); // limit number to avoid HTTP line length issues + final List mgetIds = randomSubsetOf(numToGet, ids); + final String path = "/_logstash/pipeline/" + Strings.collectionToCommaDelimitedString(mgetIds); + Request getRequest = new Request("GET", path); Response getResponse = client().performRequest(getRequest); assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); - String responseBody = EntityUtils.toString(getResponse.getEntity()); - assertThat(responseBody, containsString("foo")); - assertThat(responseBody, containsString("bar")); + Map responseMap = XContentHelper.convertToMap( + XContentType.JSON.xContent(), + EntityUtils.toString(getResponse.getEntity()), + false + ); + + for (String id : mgetIds) { + assertTrue(responseMap.containsKey(id)); + } + + // TODO need to update this after system indices are truly system indices to enable refresh + refreshAllIndices(); + + // list without any IDs + Request listAll = new Request("GET", "/_logstash/pipeline"); + Response listAllResponse = client().performRequest(listAll); + assertThat(listAllResponse.getStatusLine().getStatusCode(), is(200)); + Map listResponseMap = XContentHelper.convertToMap( + XContentType.JSON.xContent(), + EntityUtils.toString(listAllResponse.getEntity()), + false + ); + for (String id : ids) { + assertTrue(listResponseMap.containsKey(id)); + } + assertThat(listResponseMap.size(), is(ids.size())); } - public void testMultiGetFromLogstashIndex() throws IOException { - Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); - request.setJsonEntity("{ \"foo\" : \"bar\" }"); - Response response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); - request = new Request("POST", "/_logstash/.logstash/_doc/2"); - request.setJsonEntity("{ \"baz\" : \"tag\" }"); - response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); - - Request getRequest = new Request("GET", "/_logstash/_mget"); - getRequest.setJsonEntity("{ \"docs\" : [ { \"_index\" : \".logstash\", \"_id\" : \"1\" }, " + - "{ \"_index\" : \".logstash\", \"_id\" : \"2\" } ] }\n"); - Response getResponse = client().performRequest(getRequest); - assertThat(getResponse.getStatusLine().getStatusCode(), is(200)); - String responseBody = EntityUtils.toString(getResponse.getEntity()); - assertThat(responseBody, containsString("foo")); - assertThat(responseBody, containsString("bar")); - assertThat(responseBody, containsString("baz")); - assertThat(responseBody, containsString("tag")); + private void createPipeline(String id, String json) throws IOException { + Request putRequest = new Request("PUT", "/_logstash/pipeline/" + id); + putRequest.setJsonEntity(json); + Response putResponse = client().performRequest(putRequest); + assertThat(putResponse.getStatusLine().getStatusCode(), is(201)); + } + + private String getPipelineJson() throws IOException { + return getPipelineJson("2020-03-09T15:42:30.229Z"); } - public void testScrollingDocs() throws IOException { - Request request = new Request("POST", "/_logstash/.logstash/_doc/1"); - request.setJsonEntity("{ \"foo\" : \"bar\" }"); - Response response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); - request = new Request("POST", "/_logstash/.logstash/_doc/2"); - request.setJsonEntity("{ \"baz\" : \"tag\" }"); - response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); - request = new Request("POST", "/_logstash/.logstash/_doc/3"); - request.setJsonEntity("{ \"boom\" : \"ab\" }"); - request.addParameter("refresh", "true"); - response = client().performRequest(request); - assertThat(response.getStatusLine().getStatusCode(), is(201)); - - Request searchRequest = new Request("GET", "/_logstash/.logstash/_search"); - searchRequest.setJsonEntity("{ \"size\" : 1,\n\"query\" : { \"match_all\" : {} } }\n"); - searchRequest.addParameter("scroll", "1m"); - response = client().performRequest(searchRequest); - assertThat(response.getStatusLine().getStatusCode(), is(200)); - Map map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); - assertNotNull(map.get("_scroll_id")); - String scrollId = (String) map.get("_scroll_id"); - - Request scrollRequest = new Request("POST", "/_logstash/_search/scroll"); - scrollRequest.addParameter("scroll_id", scrollId); - scrollRequest.addParameter("scroll", "1m"); - response = client().performRequest(scrollRequest); - assertThat(response.getStatusLine().getStatusCode(), is(200)); - map = XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); - assertNotNull(map.get("_scroll_id")); - scrollId = (String) map.get("_scroll_id"); - - Request clearScrollRequest = new Request("DELETE", "/_logstash/_search/scroll"); - clearScrollRequest.addParameter("scroll_id", scrollId); - response = client().performRequest(clearScrollRequest); - assertThat(response.getStatusLine().getStatusCode(), is(200)); + private String getPipelineJson(String date) throws IOException { + try (XContentBuilder builder = JsonXContent.contentBuilder()) { + builder.startObject(); + { + builder.field("description", "test pipeline"); + builder.field("last_modified", date); + builder.startObject("pipeline_metadata"); + { + builder.field("version", 1); + builder.field("type", "logstash_pipeline"); + } + builder.endObject(); + builder.field("username", "john.doe"); + builder.field("pipeline", "\"input\": {},\n \"filter\": {},\n \"output\": {}\n"); + builder.startObject("pipeline_settings"); + { + builder.field("pipeline.batch.delay", 50); + builder.field("pipeline.batch.size", 125); + builder.field("pipeline.workers", 1); + builder.field("queue.checkpoint.writes", 1024); + builder.field("queue.max_bytes", "1gb"); + builder.field("queue.type", "memory"); + } + builder.endObject(); + } + builder.endObject(); + return BytesReference.bytes(builder).utf8ToString(); + } } } From dd17265ff50a21fa0c1cb2dab80e64a8e3f68446 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 10 Mar 2020 12:55:50 -0600 Subject: [PATCH 03/21] merge with x-pack plugin --- build.gradle | 1 - modules/logstash/build.gradle | 23 ---- .../logstash/LogstashPlugin.java | 107 ------------------ .../logstash/action/DeletePipelineAction.java | 32 ------ .../action/DeletePipelineRequest.java | 49 -------- .../action/DeletePipelineResponse.java | 49 -------- .../logstash/action/GetPipelineAction.java | 32 ------ .../logstash/action/PutPipelineAction.java | 32 ------ .../logstash/action/PutPipelineResponse.java | 51 --------- .../src/main/resources/pipelines.json | 12 -- .../logstash/LogstashPluginTests.java | 41 ------- .../xpack/logstash/Logstash.java | 44 +++++-- .../xpack}/logstash/Pipeline.java | 21 +--- .../logstash/action/DeletePipelineAction.java | 19 ++++ .../action/DeletePipelineRequest.java | 36 ++++++ .../action/DeletePipelineResponse.java | 36 ++++++ .../logstash/action/GetPipelineAction.java | 19 ++++ .../logstash/action/GetPipelineRequest.java | 21 +--- .../logstash/action/GetPipelineResponse.java | 21 +--- .../logstash/action/PutPipelineAction.java | 19 ++++ .../logstash/action/PutPipelineRequest.java | 21 +--- .../logstash/action/PutPipelineResponse.java | 38 +++++++ .../action/TransportDeletePipelineAction.java | 21 +--- .../action/TransportGetPipelineAction.java | 21 +--- .../action/TransportPutPipelineAction.java | 21 +--- .../rest/RestDeletePipelineAction.java | 27 ++--- .../logstash/rest/RestGetPipelineAction.java | 27 ++--- .../logstash/rest/RestPutPipelineAction.java | 29 ++--- .../xpack/logstash/LogstashPluginTests.java | 28 +++++ .../test/rest}/LogstashSystemIndexIT.java | 33 +++--- .../xpack/test/rest/XPackRestIT.java | 2 +- 31 files changed, 297 insertions(+), 636 deletions(-) delete mode 100644 modules/logstash/build.gradle delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java delete mode 100644 modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java delete mode 100644 modules/logstash/src/main/resources/pipelines.json delete mode 100644 modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/Pipeline.java (79%) create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineAction.java rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/GetPipelineRequest.java (53%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/GetPipelineResponse.java (64%) create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineAction.java rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/PutPipelineRequest.java (63%) create mode 100644 x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/TransportDeletePipelineAction.java (61%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/TransportGetPipelineAction.java (88%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/action/TransportPutPipelineAction.java (61%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/rest/RestDeletePipelineAction.java (60%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/rest/RestGetPipelineAction.java (59%) rename {modules/logstash/src/main/java/org/elasticsearch => x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack}/logstash/rest/RestPutPipelineAction.java (64%) create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java rename {modules/logstash/src/test/java/org/elasticsearch/logstash => x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest}/LogstashSystemIndexIT.java (89%) diff --git a/build.gradle b/build.gradle index 715a56d224b07..8176f88dab74c 100644 --- a/build.gradle +++ b/build.gradle @@ -114,7 +114,6 @@ subprojects { ':distribution:tools:keystore-cli', ':distribution:tools:launchers', ':distribution:tools:plugin-cli', - ':modules:logstash', ':qa:os', ':qa:wildfly', ':x-pack:plugin:autoscaling', diff --git a/modules/logstash/build.gradle b/modules/logstash/build.gradle deleted file mode 100644 index 68bb45487ee56..0000000000000 --- a/modules/logstash/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -esplugin { - description 'Plugin exposing APIs for the Logstash system index' - classname 'org.elasticsearch.logstash.LogstashPlugin' -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java deleted file mode 100644 index d98275be69010..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/LogstashPlugin.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.logstash; - -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; -import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.IndexScopedSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.common.xcontent.DeprecationHandler; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.indices.SystemIndexDescriptor; -import org.elasticsearch.logstash.action.DeletePipelineAction; -import org.elasticsearch.logstash.action.GetPipelineAction; -import org.elasticsearch.logstash.action.PutPipelineAction; -import org.elasticsearch.logstash.action.TransportDeletePipelineAction; -import org.elasticsearch.logstash.action.TransportGetPipelineAction; -import org.elasticsearch.logstash.action.TransportPutPipelineAction; -import org.elasticsearch.logstash.rest.RestDeletePipelineAction; -import org.elasticsearch.logstash.rest.RestGetPipelineAction; -import org.elasticsearch.logstash.rest.RestPutPipelineAction; -import org.elasticsearch.plugins.ActionPlugin; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestHandler; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; - -public class LogstashPlugin extends Plugin implements SystemIndexPlugin, ActionPlugin { - - @Override - public Collection getSystemIndexDescriptors(Settings settings) { - return Collections.singleton(new SystemIndexDescriptor(".logstash*", "Logstash system indices for storing pipelines")); - } - - @Override - public List> getActions() { - return List.of( - new ActionHandler<>(PutPipelineAction.INSTANCE, TransportPutPipelineAction.class), - new ActionHandler<>(GetPipelineAction.INSTANCE, TransportGetPipelineAction.class), - new ActionHandler<>(DeletePipelineAction.INSTANCE, TransportDeletePipelineAction.class) - ); - } - - @Override - public List getRestHandlers( - Settings settings, - RestController restController, - ClusterSettings clusterSettings, - IndexScopedSettings indexScopedSettings, - SettingsFilter settingsFilter, - IndexNameExpressionResolver indexNameExpressionResolver, - Supplier nodesInCluster - ) { - return List.of(new RestPutPipelineAction(), new RestGetPipelineAction(), new RestDeletePipelineAction()); - } - - @Override - public UnaryOperator> getIndexTemplateMetaDataUpgrader() { - return map -> { - try ( - XContentParser parser = JsonXContent.jsonXContent.createParser( - NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - LogstashPlugin.class.getResourceAsStream("/pipelines.json") - ) - ) { - IndexTemplateMetaData metaData = IndexTemplateMetaData.Builder.fromXContent(parser, ".logstash-pipeline"); - map.put(".logstash-pipeline", metaData); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return map; - }; - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java deleted file mode 100644 index 387e4a46a6ca9..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionType; - -public class DeletePipelineAction extends ActionType { - - public static final String NAME = "cluster:admin/logstash/pipeline/delete"; - public static final DeletePipelineAction INSTANCE = new DeletePipelineAction(); - - private DeletePipelineAction() { - super(NAME, DeletePipelineResponse::new); - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java deleted file mode 100644 index 94d79cc2fb8e2..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineRequest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.common.io.stream.StreamInput; - -import java.io.IOException; - -public class DeletePipelineRequest extends ActionRequest { - - private final String id; - - public DeletePipelineRequest(String id) { - this.id = id; - } - - public DeletePipelineRequest(StreamInput in) throws IOException { - super(in); - this.id = in.readString(); - } - - public String id() { - return id; - } - - @Override - public ActionRequestValidationException validate() { - return null; - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java deleted file mode 100644 index 89514700b19db..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/DeletePipelineResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; - -public class DeletePipelineResponse extends ActionResponse { - - private final boolean deleted; - - public DeletePipelineResponse(boolean deleted) { - this.deleted = deleted; - } - - public DeletePipelineResponse(StreamInput in) throws IOException { - super(in); - this.deleted = in.readBoolean(); - } - - public boolean isDeleted() { - return deleted; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeBoolean(deleted); - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java deleted file mode 100644 index ee93fc8c324b2..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionType; - -public class GetPipelineAction extends ActionType { - - public static final String NAME = "cluster:admin/logstash/pipeline/get"; - public static final GetPipelineAction INSTANCE = new GetPipelineAction(); - - private GetPipelineAction() { - super(NAME, GetPipelineResponse::new); - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java deleted file mode 100644 index 756ca8e768053..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionType; - -public class PutPipelineAction extends ActionType { - - public static final String NAME = "cluster:admin/logstash/pipeline/put"; - public static final PutPipelineAction INSTANCE = new PutPipelineAction(); - - private PutPipelineAction() { - super(NAME, PutPipelineResponse::new); - } -} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java b/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java deleted file mode 100644 index 7105c758414e1..0000000000000 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.logstash.action; - -import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.rest.RestStatus; - -import java.io.IOException; -import java.util.Objects; - -public class PutPipelineResponse extends ActionResponse { - - private final RestStatus status; - - public PutPipelineResponse(RestStatus status) { - this.status = Objects.requireNonNull(status); - } - - public PutPipelineResponse(StreamInput in) throws IOException { - super(in); - this.status = in.readEnum(RestStatus.class); - } - - public RestStatus getStatus() { - return status; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeEnum(status); - } -} diff --git a/modules/logstash/src/main/resources/pipelines.json b/modules/logstash/src/main/resources/pipelines.json deleted file mode 100644 index 0c4392b549358..0000000000000 --- a/modules/logstash/src/main/resources/pipelines.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "index_patterns" : [ ".logstash*" ], - "settings" : { - "number_of_shards": 1, - "number_of_replicas": 0, - "auto_expand_replicas": "0-1" - }, - "mappings" : { - "dynamic" : "false" - }, - "version" : 1 -} diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java b/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java deleted file mode 100644 index bc8cb02ceeef1..0000000000000 --- a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashPluginTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.logstash; - -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.indices.SystemIndexDescriptor; -import org.elasticsearch.test.ESTestCase; - -import java.util.stream.Collectors; - -import static org.hamcrest.Matchers.contains; - -public class LogstashPluginTests extends ESTestCase { - - public void testSystemIndices() { - assertThat( - new LogstashPlugin().getSystemIndexDescriptors(Settings.EMPTY) - .stream() - .map(SystemIndexDescriptor::getIndexPattern) - .collect(Collectors.toUnmodifiableList()), - contains(".logstash*") - ); - } -} diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java index 177135974fb6c..6d4909a621fa7 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java @@ -9,21 +9,36 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.xpack.core.XPackSettings; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; import org.elasticsearch.xpack.core.template.TemplateUtils; +import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; +import org.elasticsearch.xpack.logstash.action.GetPipelineAction; +import org.elasticsearch.xpack.logstash.action.PutPipelineAction; +import org.elasticsearch.xpack.logstash.action.TransportDeletePipelineAction; +import org.elasticsearch.xpack.logstash.action.TransportGetPipelineAction; +import org.elasticsearch.xpack.logstash.action.TransportPutPipelineAction; +import org.elasticsearch.xpack.logstash.rest.RestDeletePipelineAction; +import org.elasticsearch.xpack.logstash.rest.RestGetPipelineAction; +import org.elasticsearch.xpack.logstash.rest.RestPutPipelineAction; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.function.Supplier; import java.util.function.UnaryOperator; /** @@ -37,17 +52,30 @@ public class Logstash extends Plugin implements SystemIndexPlugin { private static final String OLD_LOGSTASH_INDEX_NAME = "logstash-index-template"; private static final String TEMPLATE_VERSION_VARIABLE = "logstash.template.version"; - private final boolean enabled; - - public Logstash(Settings settings) { - this.enabled = XPackSettings.LOGSTASH_ENABLED.get(settings); + public Logstash() { } @Override public List> getActions() { - return Arrays.asList( + return List.of( new ActionHandler<>(XPackUsageFeatureAction.LOGSTASH, LogstashUsageTransportAction.class), - new ActionHandler<>(XPackInfoFeatureAction.LOGSTASH, LogstashInfoTransportAction.class)); + new ActionHandler<>(XPackInfoFeatureAction.LOGSTASH, LogstashInfoTransportAction.class), + new ActionHandler<>(PutPipelineAction.INSTANCE, TransportPutPipelineAction.class), + new ActionHandler<>(GetPipelineAction.INSTANCE, TransportGetPipelineAction.class), + new ActionHandler<>(DeletePipelineAction.INSTANCE, TransportDeletePipelineAction.class)); + } + + @Override + public List getRestHandlers( + Settings settings, + RestController restController, + ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, + SettingsFilter settingsFilter, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster + ) { + return List.of(new RestPutPipelineAction(), new RestGetPipelineAction(), new RestDeletePipelineAction()); } public UnaryOperator> getIndexTemplateMetaDataUpgrader() { diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Pipeline.java similarity index 79% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Pipeline.java index 3427a37bb1e7a..27d4c34c1f65e 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/Pipeline.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Pipeline.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash; +package org.elasticsearch.xpack.logstash; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ConstructingObjectParser; diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java new file mode 100644 index 0000000000000..494559a40f289 --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class DeletePipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/delete"; + public static final DeletePipelineAction INSTANCE = new DeletePipelineAction(); + + private DeletePipelineAction() { + super(NAME, org.elasticsearch.xpack.logstash.action.DeletePipelineResponse::new); + } +} diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java new file mode 100644 index 0000000000000..ec5c9d8c75274 --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + +public class DeletePipelineRequest extends ActionRequest { + + private final String id; + + public DeletePipelineRequest(String id) { + this.id = id; + } + + public DeletePipelineRequest(StreamInput in) throws IOException { + super(in); + this.id = in.readString(); + } + + public String id() { + return id; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } +} diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java new file mode 100644 index 0000000000000..0f915a94d2964 --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +public class DeletePipelineResponse extends ActionResponse { + + private final boolean deleted; + + public DeletePipelineResponse(boolean deleted) { + this.deleted = deleted; + } + + public DeletePipelineResponse(StreamInput in) throws IOException { + super(in); + this.deleted = in.readBoolean(); + } + + public boolean isDeleted() { + return deleted; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeBoolean(deleted); + } +} diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineAction.java new file mode 100644 index 0000000000000..03b46faaf31a5 --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineAction.java @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class GetPipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/get"; + public static final GetPipelineAction INSTANCE = new GetPipelineAction(); + + private GetPipelineAction() { + super(NAME, GetPipelineResponse::new); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java similarity index 53% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java index b6ae83a1343a0..2c4fb785da889 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java similarity index 64% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java index 27c7153e75e5a..3b3b317ef1716 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/GetPipelineResponse.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.bytes.BytesReference; diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineAction.java new file mode 100644 index 0000000000000..7511e5daeaabe --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineAction.java @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionType; + +public class PutPipelineAction extends ActionType { + + public static final String NAME = "cluster:admin/logstash/pipeline/put"; + public static final PutPipelineAction INSTANCE = new PutPipelineAction(); + + private PutPipelineAction() { + super(NAME, PutPipelineResponse::new); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java similarity index 63% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java index 98f6593242b92..2b682c29b687b 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/PutPipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java new file mode 100644 index 0000000000000..16562a970d919 --- /dev/null +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.rest.RestStatus; + +import java.io.IOException; +import java.util.Objects; + +public class PutPipelineResponse extends ActionResponse { + + private final RestStatus status; + + public PutPipelineResponse(RestStatus status) { + this.status = Objects.requireNonNull(status); + } + + public PutPipelineResponse(StreamInput in) throws IOException { + super(in); + this.status = in.readEnum(RestStatus.class); + } + + public RestStatus getStatus() { + return status; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeEnum(status); + } +} diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java similarity index 61% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java index 98debc4e126f7..2232f6c1ca4d4 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteResponse.Result; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java similarity index 88% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java index 8bfbdf846a540..3d5f23d0a9b6c 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java similarity index 61% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java index d9ca9e3e4d114..e04e80ba93424 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/action/TransportPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.action; +package org.elasticsearch.xpack.logstash.action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java similarity index 60% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java index 51aab2b078ae1..e3ec672e5a21e 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java @@ -1,30 +1,17 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.rest; +package org.elasticsearch.xpack.logstash.rest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.logstash.action.DeletePipelineAction; -import org.elasticsearch.logstash.action.DeletePipelineRequest; -import org.elasticsearch.logstash.action.DeletePipelineResponse; +import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; +import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; +import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestRequest; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java similarity index 59% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java index ac3a15b380fb4..a522ce7dd652f 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java @@ -1,29 +1,16 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.rest; +package org.elasticsearch.xpack.logstash.rest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.logstash.action.GetPipelineAction; -import org.elasticsearch.logstash.action.GetPipelineRequest; -import org.elasticsearch.logstash.action.GetPipelineResponse; +import org.elasticsearch.xpack.logstash.action.GetPipelineAction; +import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; +import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest.Method; diff --git a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java similarity index 64% rename from modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java rename to x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java index c6cf05812cece..e5eb70ccda15f 100644 --- a/modules/logstash/src/main/java/org/elasticsearch/logstash/rest/RestPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java @@ -1,32 +1,19 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash.rest; +package org.elasticsearch.xpack.logstash.rest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.logstash.Pipeline; -import org.elasticsearch.logstash.action.PutPipelineAction; -import org.elasticsearch.logstash.action.PutPipelineRequest; -import org.elasticsearch.logstash.action.PutPipelineResponse; +import org.elasticsearch.xpack.logstash.Pipeline; +import org.elasticsearch.xpack.logstash.action.PutPipelineAction; +import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; +import org.elasticsearch.xpack.logstash.action.PutPipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestRequest; diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java new file mode 100644 index 0000000000000..9c713b9d7e890 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashPluginTests.java @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.test.ESTestCase; + +import java.util.stream.Collectors; + +import static org.hamcrest.Matchers.contains; + +public class LogstashPluginTests extends ESTestCase { + + public void testSystemIndices() { + assertThat( + new Logstash().getSystemIndexDescriptors(Settings.EMPTY) + .stream() + .map(SystemIndexDescriptor::getIndexPattern) + .collect(Collectors.toUnmodifiableList()), + contains(".logstash") + ); + } +} diff --git a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java similarity index 89% rename from modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java rename to x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java index 85cf48622cccb..5d139862f35f3 100644 --- a/modules/logstash/src/test/java/org/elasticsearch/logstash/LogstashSystemIndexIT.java +++ b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.logstash; +package org.elasticsearch.xpack.test.rest; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; @@ -25,6 +12,8 @@ import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; @@ -36,15 +25,23 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.xpack.test.rest.XPackRestIT.BASIC_AUTH_VALUE; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; public class LogstashSystemIndexIT extends ESRestTestCase { + @Override + protected Settings restClientSettings() { + return Settings.builder() + .put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE) + .build(); + } + public void testTemplateIsPut() throws Exception { assertBusy( () -> assertThat( - client().performRequest(new Request("HEAD", "/_template/.logstash-pipeline")).getStatusLine().getStatusCode(), + client().performRequest(new Request("HEAD", "/_template/.logstash-management")).getStatusLine().getStatusCode(), is(200) ) ); diff --git a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java index dd207033554e8..c57d49a2e5077 100644 --- a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +++ b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java @@ -50,7 +50,7 @@ /** Runs rest tests against external cluster */ public class XPackRestIT extends ESClientYamlSuiteTestCase { - private static final String BASIC_AUTH_VALUE = + static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING); public XPackRestIT(ClientYamlTestCandidate testCandidate) { From c94574fac1f45a5ee54005a98ac5ba03a02872b9 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 10 Mar 2020 14:20:23 -0600 Subject: [PATCH 04/21] add system index access allowance --- .../org/elasticsearch/xpack/logstash/Logstash.java | 2 +- .../xpack/logstash/rest/RestDeletePipelineAction.java | 2 ++ .../xpack/logstash/rest/RestGetPipelineAction.java | 8 +++++--- .../xpack/logstash/rest/RestPutPipelineAction.java | 10 ++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java index 6d4909a621fa7..722c9fcff55a4 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java @@ -46,7 +46,7 @@ */ public class Logstash extends Plugin implements SystemIndexPlugin { - private static final String LOGSTASH_CONCRETE_INDEX_NAME = ".logstash"; + public static final String LOGSTASH_CONCRETE_INDEX_NAME = ".logstash"; private static final String LOGSTASH_TEMPLATE_FILE_NAME = "logstash-management"; private static final String LOGSTASH_INDEX_TEMPLATE_NAME = ".logstash-management"; private static final String OLD_LOGSTASH_INDEX_NAME = "logstash-index-template"; diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java index e3ec672e5a21e..23380806ad783 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.xpack.logstash.Logstash; import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; @@ -36,6 +37,7 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final String id = request.param("id"); return restChannel -> client.execute( DeletePipelineAction.INSTANCE, diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java index a522ce7dd652f..5f42228640b8a 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java @@ -8,14 +8,15 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.xpack.logstash.action.GetPipelineAction; -import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; -import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest.Method; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.xpack.logstash.Logstash; +import org.elasticsearch.xpack.logstash.action.GetPipelineAction; +import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; +import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; import java.io.IOException; import java.util.List; @@ -34,6 +35,7 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final List ids = List.of(request.paramAsStringArray("id", Strings.EMPTY_ARRAY)); return restChannel -> client.execute( GetPipelineAction.INSTANCE, diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java index e5eb70ccda15f..79db5e54679ca 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java @@ -10,15 +10,16 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.logstash.Pipeline; -import org.elasticsearch.xpack.logstash.action.PutPipelineAction; -import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; -import org.elasticsearch.xpack.logstash.action.PutPipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest.Method; import org.elasticsearch.rest.action.RestActionListener; +import org.elasticsearch.xpack.logstash.Logstash; +import org.elasticsearch.xpack.logstash.Pipeline; +import org.elasticsearch.xpack.logstash.action.PutPipelineAction; +import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; +import org.elasticsearch.xpack.logstash.action.PutPipelineResponse; import java.io.IOException; import java.util.List; @@ -37,6 +38,7 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final String id = request.param("id"); try (XContentParser parser = request.contentParser()) { // parse pipeline for validation From a63f268e34c7811a10c463ac053e9889d9ae3e07 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 11 Mar 2020 08:43:37 -0600 Subject: [PATCH 05/21] formatting --- .../java/org/elasticsearch/xpack/logstash/Logstash.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java index 0f0247648275d..dd5d87a579182 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/Logstash.java @@ -52,8 +52,7 @@ public class Logstash extends Plugin implements SystemIndexPlugin { private static final String OLD_LOGSTASH_INDEX_NAME = "logstash-index-template"; private static final String TEMPLATE_VERSION_VARIABLE = "logstash.template.version"; - public Logstash() { - } + public Logstash() {} @Override public List> getActions() { @@ -62,7 +61,8 @@ public Logstash() { new ActionHandler<>(XPackInfoFeatureAction.LOGSTASH, LogstashInfoTransportAction.class), new ActionHandler<>(PutPipelineAction.INSTANCE, TransportPutPipelineAction.class), new ActionHandler<>(GetPipelineAction.INSTANCE, TransportGetPipelineAction.class), - new ActionHandler<>(DeletePipelineAction.INSTANCE, TransportDeletePipelineAction.class)); + new ActionHandler<>(DeletePipelineAction.INSTANCE, TransportDeletePipelineAction.class) + ); } @Override From 922d3117dbd16e62267036789d6746f71de68f57 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 11 Mar 2020 11:10:47 -0600 Subject: [PATCH 06/21] serialization tests and fixes --- .../action/DeletePipelineRequest.java | 10 +- .../logstash/action/PutPipelineRequest.java | 7 +- .../logstash/action/PutPipelineResponse.java | 2 +- .../action/TransportPutPipelineAction.java | 4 +- .../logstash/rest/RestPutPipelineAction.java | 2 +- ...lineRequestResponseSerializationTests.java | 100 ++++++++++++++++++ 6 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java index ec5c9d8c75274..d631c74bebe7c 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java @@ -9,15 +9,17 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Objects; public class DeletePipelineRequest extends ActionRequest { private final String id; public DeletePipelineRequest(String id) { - this.id = id; + this.id = Objects.requireNonNull(id); } public DeletePipelineRequest(StreamInput in) throws IOException { @@ -33,4 +35,10 @@ public String id() { public ActionRequestValidationException validate() { return null; } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(id); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java index 2b682c29b687b..e6bfd2471ddc0 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java @@ -34,21 +34,22 @@ public PutPipelineRequest(StreamInput in) throws IOException { this.xContentType = in.readEnum(XContentType.class); } - public String getId() { + public String id() { return id; } - public String getSource() { + public String source() { return source; } - public XContentType getxContentType() { + public XContentType xContentType() { return xContentType; } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); + out.writeString(id); out.writeString(source); out.writeEnum(xContentType); } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java index 16562a970d919..25f0c669a3fc5 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java @@ -27,7 +27,7 @@ public PutPipelineResponse(StreamInput in) throws IOException { this.status = in.readEnum(RestStatus.class); } - public RestStatus getStatus() { + public RestStatus status() { return status; } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java index e04e80ba93424..ebf9311a30677 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java @@ -27,8 +27,8 @@ public TransportPutPipelineAction(TransportService transportService, ActionFilte @Override protected void doExecute(Task task, PutPipelineRequest request, ActionListener listener) { client.prepareIndex(".logstash") - .setId(request.getId()) - .setSource(request.getSource(), request.getxContentType()) + .setId(request.id()) + .setSource(request.source(), request.xContentType()) .execute( ActionListener.wrap( indexResponse -> listener.onResponse(new PutPipelineResponse(indexResponse.status())), diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java index 79db5e54679ca..0e7051bc0b4ca 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java @@ -54,7 +54,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli @Override protected void processResponse(PutPipelineResponse putPipelineResponse) throws Exception { channel.sendResponse( - new BytesRestResponse(putPipelineResponse.getStatus(), XContentType.JSON.mediaType(), BytesArray.EMPTY) + new BytesRestResponse(putPipelineResponse.status(), XContentType.JSON.mediaType(), BytesArray.EMPTY) ); } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java new file mode 100644 index 0000000000000..2e947a8fffcc6 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java @@ -0,0 +1,100 @@ +/* + * 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.xpack.logstash; + +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; +import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; +import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; +import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; +import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; +import org.elasticsearch.xpack.logstash.action.PutPipelineResponse; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class PipelineRequestResponseSerializationTests extends ESTestCase { + + public void testGetPipelineRequestSerialization() throws IOException { + GetPipelineRequest request = new GetPipelineRequest(randomList(0, 50, () -> randomAlphaOfLengthBetween(2, 10))); + BytesStreamOutput out = new BytesStreamOutput(); + request.writeTo(out); + GetPipelineRequest serialized = new GetPipelineRequest(out.bytes().streamInput()); + assertEquals(request.ids(), serialized.ids()); + } + + public void testGetPipelineResponseSerialization() throws IOException { + final int numPipelines = randomIntBetween(1, 10); + final Map map = new HashMap<>(numPipelines); + for (int i = 0; i < numPipelines; i++) { + final String name = randomAlphaOfLengthBetween(2, 10); + final BytesReference ref = new BytesArray(randomByteArrayOfLength(randomIntBetween(1, 16))); + map.put(name, ref); + } + GetPipelineResponse response = new GetPipelineResponse(map); + BytesStreamOutput out = new BytesStreamOutput(); + response.writeTo(out); + GetPipelineResponse serializedResponse = new GetPipelineResponse(out.bytes().streamInput()); + assertEquals(response.pipelines(), serializedResponse.pipelines()); + } + + public void testPutPipelineRequestSerialization() throws IOException { + PutPipelineRequest request = new PutPipelineRequest(randomAlphaOfLength(2), + randomAlphaOfLengthBetween(10, 100), + randomFrom(XContentType.values()) + ); + BytesStreamOutput out = new BytesStreamOutput(); + request.writeTo(out); + PutPipelineRequest serializedRequest = new PutPipelineRequest(out.bytes().streamInput()); + assertEquals(request.id(), serializedRequest.id()); + assertEquals(request.source(), serializedRequest.source()); + assertEquals(request.xContentType(), serializedRequest.xContentType()); + } + + public void testPutPipelineResponseSerialization() throws IOException { + PutPipelineResponse response = new PutPipelineResponse(randomFrom(RestStatus.OK, RestStatus.CREATED)); + BytesStreamOutput out = new BytesStreamOutput(); + response.writeTo(out); + PutPipelineResponse serializedResponse = new PutPipelineResponse(out.bytes().streamInput()); + assertEquals(response.status(), serializedResponse.status()); + } + + public void testDeletePipelineRequestSerialization() throws IOException { + DeletePipelineRequest request = new DeletePipelineRequest(randomAlphaOfLengthBetween(2, 10)); + BytesStreamOutput out = new BytesStreamOutput(); + request.writeTo(out); + DeletePipelineRequest serializedRequest = new DeletePipelineRequest(out.bytes().streamInput()); + assertEquals(request.id(), serializedRequest.id()); + } + + public void testDeletePipelineResponseSerialization() throws IOException { + DeletePipelineResponse response = new DeletePipelineResponse(randomBoolean()); + BytesStreamOutput out = new BytesStreamOutput(); + response.writeTo(out); + DeletePipelineResponse serializedResponse = new DeletePipelineResponse(out.bytes().streamInput()); + assertEquals(response.isDeleted(), serializedResponse.isDeleted()); + } +} From 765963d13695e256144f2a2e9cb5484c713c087d Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 11 Mar 2020 11:11:42 -0600 Subject: [PATCH 07/21] license --- ...lineRequestResponseSerializationTests.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java index 2e947a8fffcc6..fbd921bb13750 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ package org.elasticsearch.xpack.logstash; From b82253e1c0637fd7a05b7c329669ca488f5eb900 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 11 Mar 2020 11:25:12 -0600 Subject: [PATCH 08/21] format --- .../PipelineRequestResponseSerializationTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java index fbd921bb13750..3aaddf781a3f2 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java @@ -49,9 +49,10 @@ public void testGetPipelineResponseSerialization() throws IOException { } public void testPutPipelineRequestSerialization() throws IOException { - PutPipelineRequest request = new PutPipelineRequest(randomAlphaOfLength(2), - randomAlphaOfLengthBetween(10, 100), - randomFrom(XContentType.values()) + PutPipelineRequest request = new PutPipelineRequest( + randomAlphaOfLength(2), + randomAlphaOfLengthBetween(10, 100), + randomFrom(XContentType.values()) ); BytesStreamOutput out = new BytesStreamOutput(); request.writeTo(out); From 7fa4d07daadc6d0308d80d00668c79148ad46221 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 22 Jul 2020 11:35:09 -0600 Subject: [PATCH 09/21] fixes --- .../xpack/logstash/rest/RestDeletePipelineAction.java | 8 +++----- .../xpack/logstash/rest/RestGetPipelineAction.java | 2 -- .../xpack/logstash/rest/RestPutPipelineAction.java | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java index 23380806ad783..6aeadabfa8f39 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java @@ -9,16 +9,15 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.logstash.Logstash; -import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; -import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; -import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest.Method; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestActionListener; +import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; +import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; +import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; import java.io.IOException; import java.util.List; @@ -37,7 +36,6 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final String id = request.param("id"); return restChannel -> client.execute( DeletePipelineAction.INSTANCE, diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java index 5f42228640b8a..0cceb6f803aa3 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestGetPipelineAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.rest.RestRequest.Method; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.logstash.Logstash; import org.elasticsearch.xpack.logstash.action.GetPipelineAction; import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; @@ -35,7 +34,6 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final List ids = List.of(request.paramAsStringArray("id", Strings.EMPTY_ARRAY)); return restChannel -> client.execute( GetPipelineAction.INSTANCE, diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java index 0e7051bc0b4ca..fb505b3ae25ee 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest.Method; import org.elasticsearch.rest.action.RestActionListener; -import org.elasticsearch.xpack.logstash.Logstash; import org.elasticsearch.xpack.logstash.Pipeline; import org.elasticsearch.xpack.logstash.action.PutPipelineAction; import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; @@ -38,7 +37,6 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - client.threadPool().getThreadContext().allowSystemIndexAccess(List.of(Logstash.LOGSTASH_CONCRETE_INDEX_NAME)); final String id = request.param("id"); try (XContentParser parser = request.contentParser()) { // parse pipeline for validation From c839bf7d8759790049d2f9762885259c735aaaa0 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 22 Jul 2020 11:35:42 -0600 Subject: [PATCH 10/21] aesthetics --- .../xpack/logstash/action/DeletePipelineAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java index 494559a40f289..cde8c5dfca2fa 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineAction.java @@ -8,12 +8,12 @@ import org.elasticsearch.action.ActionType; -public class DeletePipelineAction extends ActionType { +public class DeletePipelineAction extends ActionType { public static final String NAME = "cluster:admin/logstash/pipeline/delete"; public static final DeletePipelineAction INSTANCE = new DeletePipelineAction(); private DeletePipelineAction() { - super(NAME, org.elasticsearch.xpack.logstash.action.DeletePipelineResponse::new); + super(NAME, DeletePipelineResponse::new); } } From 6a1be8cb80fadb6078dd0c8b913dec78ba0ed0c7 Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 22 Jul 2020 11:38:48 -0600 Subject: [PATCH 11/21] constants --- .../action/TransportDeletePipelineAction.java | 3 ++- .../action/TransportGetPipelineAction.java | 20 ++++++++++--------- .../action/TransportPutPipelineAction.java | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java index 2232f6c1ca4d4..8286fcd449f27 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportDeletePipelineAction.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.logstash.Logstash; public class TransportDeletePipelineAction extends HandledTransportAction { @@ -27,7 +28,7 @@ public TransportDeletePipelineAction(TransportService transportService, ActionFi @Override protected void doExecute(Task task, DeletePipelineRequest request, ActionListener listener) { - client.prepareDelete(".logstash", request.id()) + client.prepareDelete(Logstash.LOGSTASH_CONCRETE_INDEX_NAME, request.id()) .execute( ActionListener.wrap( deleteResponse -> listener.onResponse(new DeletePipelineResponse(deleteResponse.getResult() == Result.DELETED)), diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java index 3d5f23d0a9b6c..5247648a4c5a3 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java @@ -25,6 +25,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.logstash.Logstash; import java.util.Arrays; import java.util.HashMap; @@ -46,7 +47,7 @@ public TransportGetPipelineAction(TransportService transportService, ActionFilte @Override protected void doExecute(Task task, GetPipelineRequest request, ActionListener listener) { if (request.ids().isEmpty()) { - client.prepareSearch(".logstash") + client.prepareSearch(Logstash.LOGSTASH_CONCRETE_INDEX_NAME) .setSource( SearchSourceBuilder.searchSource() .fetchSource(true) @@ -77,16 +78,17 @@ protected void doExecute(Task task, GetPipelineRequest request, ActionListener { - if (response.isExists()) { - listener.onResponse(new GetPipelineResponse(Map.of(response.getId(), response.getSourceAsBytesRef()))); - } else { - listener.onResponse(new GetPipelineResponse(Map.of())); - } - }, listener::onFailure)); + client.prepareGet(Logstash.LOGSTASH_CONCRETE_INDEX_NAME, request.ids().get(0)).setFetchSource(true) + .execute(ActionListener.wrap(response -> { + if (response.isExists()) { + listener.onResponse(new GetPipelineResponse(Map.of(response.getId(), response.getSourceAsBytesRef()))); + } else { + listener.onResponse(new GetPipelineResponse(Map.of())); + } + }, listener::onFailure)); } else { client.prepareMultiGet() - .addIds(".logstash", request.ids()) + .addIds(Logstash.LOGSTASH_CONCRETE_INDEX_NAME, request.ids()) .execute( ActionListener.wrap( mGetResponse -> listener.onResponse( diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java index ebf9311a30677..eb6608e2c9560 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportPutPipelineAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.logstash.Logstash; public class TransportPutPipelineAction extends HandledTransportAction { @@ -26,7 +27,7 @@ public TransportPutPipelineAction(TransportService transportService, ActionFilte @Override protected void doExecute(Task task, PutPipelineRequest request, ActionListener listener) { - client.prepareIndex(".logstash") + client.prepareIndex(Logstash.LOGSTASH_CONCRETE_INDEX_NAME) .setId(request.id()) .setSource(request.source(), request.xContentType()) .execute( From 1cac8880bec12bbc0033c68389d2eb2be4cfc44b Mon Sep 17 00:00:00 2001 From: jaymode Date: Wed, 22 Jul 2020 12:16:28 -0600 Subject: [PATCH 12/21] spotless --- .../xpack/logstash/action/TransportGetPipelineAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java index 5247648a4c5a3..a9de12d25dc65 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java @@ -78,7 +78,8 @@ protected void doExecute(Task task, GetPipelineRequest request, ActionListener { if (response.isExists()) { listener.onResponse(new GetPipelineResponse(Map.of(response.getId(), response.getSourceAsBytesRef()))); From 2b3d16e7dd4420f40513297b33e880fae318f27e Mon Sep 17 00:00:00 2001 From: William Brafford Date: Tue, 4 Aug 2020 22:23:48 -0400 Subject: [PATCH 13/21] Break out serialization tests into distinct classes --- .../action/DeletePipelineRequest.java | 13 +++ .../action/DeletePipelineResponse.java | 14 +++ .../logstash/action/GetPipelineRequest.java | 13 +++ .../logstash/action/GetPipelineResponse.java | 14 +++ .../logstash/action/PutPipelineRequest.java | 13 +++ .../logstash/action/PutPipelineResponse.java | 13 +++ ...lineRequestResponseSerializationTests.java | 88 ------------------- .../action/DeletePipelineRequestTests.java | 23 +++++ .../action/DeletePipelineResponseTests.java | 23 +++++ .../action/GetPipelineRequestTests.java | 23 +++++ .../action/GetPipelineResponseTests.java | 35 ++++++++ .../action/PutPipelineRequestTests.java | 24 +++++ .../action/PutPipelineResponseTests.java | 24 +++++ 13 files changed, 232 insertions(+), 88 deletions(-) delete mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java index d631c74bebe7c..2eee54a58a283 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequest.java @@ -41,4 +41,17 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(id); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DeletePipelineRequest that = (DeletePipelineRequest) o; + return Objects.equals(id, that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java index 0f915a94d2964..bb04b868a9c7a 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponse.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Objects; public class DeletePipelineResponse extends ActionResponse { @@ -33,4 +34,17 @@ public boolean isDeleted() { public void writeTo(StreamOutput out) throws IOException { out.writeBoolean(deleted); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DeletePipelineResponse that = (DeletePipelineResponse) o; + return deleted == that.deleted; + } + + @Override + public int hashCode() { + return Objects.hash(deleted); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java index 2c4fb785da889..8a7960679c59f 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequest.java @@ -42,4 +42,17 @@ public void writeTo(StreamOutput out) throws IOException { public ActionRequestValidationException validate() { return null; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetPipelineRequest that = (GetPipelineRequest) o; + return Objects.equals(ids, that.ids); + } + + @Override + public int hashCode() { + return Objects.hash(ids); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java index 3b3b317ef1716..c7d58658bf0ce 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponse.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; public class GetPipelineResponse extends ActionResponse implements ToXContentObject { @@ -47,4 +48,17 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } return builder.endObject(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetPipelineResponse that = (GetPipelineResponse) o; + return Objects.equals(pipelines, that.pipelines); + } + + @Override + public int hashCode() { + return Objects.hash(pipelines); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java index e6bfd2471ddc0..525be7f2a1cff 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequest.java @@ -58,4 +58,17 @@ public void writeTo(StreamOutput out) throws IOException { public ActionRequestValidationException validate() { return null; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PutPipelineRequest that = (PutPipelineRequest) o; + return Objects.equals(id, that.id) && Objects.equals(source, that.source) && xContentType == that.xContentType; + } + + @Override + public int hashCode() { + return Objects.hash(id, source, xContentType); + } } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java index 25f0c669a3fc5..44d2ae940b624 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponse.java @@ -35,4 +35,17 @@ public RestStatus status() { public void writeTo(StreamOutput out) throws IOException { out.writeEnum(status); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PutPipelineResponse that = (PutPipelineResponse) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java deleted file mode 100644 index 3aaddf781a3f2..0000000000000 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/PipelineRequestResponseSerializationTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.logstash; - -import org.elasticsearch.common.bytes.BytesArray; -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; -import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; -import org.elasticsearch.xpack.logstash.action.GetPipelineRequest; -import org.elasticsearch.xpack.logstash.action.GetPipelineResponse; -import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; -import org.elasticsearch.xpack.logstash.action.PutPipelineResponse; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -public class PipelineRequestResponseSerializationTests extends ESTestCase { - - public void testGetPipelineRequestSerialization() throws IOException { - GetPipelineRequest request = new GetPipelineRequest(randomList(0, 50, () -> randomAlphaOfLengthBetween(2, 10))); - BytesStreamOutput out = new BytesStreamOutput(); - request.writeTo(out); - GetPipelineRequest serialized = new GetPipelineRequest(out.bytes().streamInput()); - assertEquals(request.ids(), serialized.ids()); - } - - public void testGetPipelineResponseSerialization() throws IOException { - final int numPipelines = randomIntBetween(1, 10); - final Map map = new HashMap<>(numPipelines); - for (int i = 0; i < numPipelines; i++) { - final String name = randomAlphaOfLengthBetween(2, 10); - final BytesReference ref = new BytesArray(randomByteArrayOfLength(randomIntBetween(1, 16))); - map.put(name, ref); - } - GetPipelineResponse response = new GetPipelineResponse(map); - BytesStreamOutput out = new BytesStreamOutput(); - response.writeTo(out); - GetPipelineResponse serializedResponse = new GetPipelineResponse(out.bytes().streamInput()); - assertEquals(response.pipelines(), serializedResponse.pipelines()); - } - - public void testPutPipelineRequestSerialization() throws IOException { - PutPipelineRequest request = new PutPipelineRequest( - randomAlphaOfLength(2), - randomAlphaOfLengthBetween(10, 100), - randomFrom(XContentType.values()) - ); - BytesStreamOutput out = new BytesStreamOutput(); - request.writeTo(out); - PutPipelineRequest serializedRequest = new PutPipelineRequest(out.bytes().streamInput()); - assertEquals(request.id(), serializedRequest.id()); - assertEquals(request.source(), serializedRequest.source()); - assertEquals(request.xContentType(), serializedRequest.xContentType()); - } - - public void testPutPipelineResponseSerialization() throws IOException { - PutPipelineResponse response = new PutPipelineResponse(randomFrom(RestStatus.OK, RestStatus.CREATED)); - BytesStreamOutput out = new BytesStreamOutput(); - response.writeTo(out); - PutPipelineResponse serializedResponse = new PutPipelineResponse(out.bytes().streamInput()); - assertEquals(response.status(), serializedResponse.status()); - } - - public void testDeletePipelineRequestSerialization() throws IOException { - DeletePipelineRequest request = new DeletePipelineRequest(randomAlphaOfLengthBetween(2, 10)); - BytesStreamOutput out = new BytesStreamOutput(); - request.writeTo(out); - DeletePipelineRequest serializedRequest = new DeletePipelineRequest(out.bytes().streamInput()); - assertEquals(request.id(), serializedRequest.id()); - } - - public void testDeletePipelineResponseSerialization() throws IOException { - DeletePipelineResponse response = new DeletePipelineResponse(randomBoolean()); - BytesStreamOutput out = new BytesStreamOutput(); - response.writeTo(out); - DeletePipelineResponse serializedResponse = new DeletePipelineResponse(out.bytes().streamInput()); - assertEquals(response.isDeleted(), serializedResponse.isDeleted()); - } -} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java new file mode 100644 index 0000000000000..55533f617632a --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class DeletePipelineRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return DeletePipelineRequest::new; + } + + @Override + protected DeletePipelineRequest createTestInstance() { + return new DeletePipelineRequest(randomAlphaOfLengthBetween(2, 10)); + } +} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java new file mode 100644 index 0000000000000..0d1c5f0b562dc --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class DeletePipelineResponseTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return DeletePipelineResponse::new; + } + + @Override + protected DeletePipelineResponse createTestInstance() { + return new DeletePipelineResponse(randomBoolean()); + } +} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java new file mode 100644 index 0000000000000..11c3d12c425f1 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class GetPipelineRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return GetPipelineRequest::new; + } + + @Override + protected GetPipelineRequest createTestInstance() { + return new GetPipelineRequest(randomList(0, 50, () -> randomAlphaOfLengthBetween(2, 10))); + } +} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java new file mode 100644 index 0000000000000..a3cc915090a1d --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +import java.util.HashMap; +import java.util.Map; + +public class GetPipelineResponseTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return GetPipelineResponse::new; + } + + @Override + protected GetPipelineResponse createTestInstance() { + final int numPipelines = randomIntBetween(1, 10); + final Map map = new HashMap<>(numPipelines); + for (int i = 0; i < numPipelines; i++) { + final String name = randomAlphaOfLengthBetween(2, 10); + final BytesReference ref = new BytesArray(randomByteArrayOfLength(randomIntBetween(1, 16))); + map.put(name, ref); + } + return new GetPipelineResponse(map); + } +} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java new file mode 100644 index 0000000000000..7b4e8058f30b8 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class PutPipelineRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return PutPipelineRequest::new; + } + + @Override + protected PutPipelineRequest createTestInstance() { + return new PutPipelineRequest(randomAlphaOfLength(2), randomAlphaOfLengthBetween(10, 100), randomFrom(XContentType.values())); + } +} diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java new file mode 100644 index 0000000000000..822fd44105bc6 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.test.AbstractWireSerializingTestCase; + +public class PutPipelineResponseTests extends AbstractWireSerializingTestCase { + + @Override + protected Writeable.Reader instanceReader() { + return PutPipelineResponse::new; + } + + @Override + protected PutPipelineResponse createTestInstance() { + return new PutPipelineResponse(randomFrom(RestStatus.OK, RestStatus.CREATED)); + } +} From de4060325b994f9f513e114c3f1f64214729dc1a Mon Sep 17 00:00:00 2001 From: William Brafford Date: Wed, 5 Aug 2020 16:29:07 -0400 Subject: [PATCH 14/21] Remove test of obsolete setting --- .../LogstashInfoTransportActionTests.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java index 64fef0069cdd9..79adb6d36911c 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.TransportService; @@ -22,9 +21,7 @@ public class LogstashInfoTransportActionTests extends ESTestCase { - public void testEnabledSetting() throws Exception { - boolean enabled = randomBoolean(); - Settings settings = Settings.builder().put("path.home", createTempDir()).put("xpack.logstash.enabled", enabled).build(); + public void testEnabledDefault() throws Exception { LogstashInfoTransportAction featureSet = new LogstashInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), @@ -43,16 +40,6 @@ public void testEnabledSetting() throws Exception { assertThat(serializedUsage.enabled(), is(true)); } - public void testEnabledDefault() throws Exception { - Settings settings = Settings.builder().put("path.home", createTempDir()).build(); - LogstashInfoTransportAction featureSet = new LogstashInfoTransportAction( - mock(TransportService.class), - mock(ActionFilters.class), - null - ); - assertThat(featureSet.enabled(), is(true)); - } - public void testAvailable() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); LogstashInfoTransportAction featureSet = new LogstashInfoTransportAction( From 453b2b1b97696d7248ebe2fa609a924037817466 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Wed, 12 Aug 2020 20:51:52 -0400 Subject: [PATCH 15/21] Add test for pipeline multiget logic --- .../TransportGetPipelineActionTests.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java new file mode 100644 index 0000000000000..2555f0100e855 --- /dev/null +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java @@ -0,0 +1,79 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.logstash.action; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetResponse; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.client.NoOpClient; +import org.elasticsearch.transport.TransportService; + +import java.util.List; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TransportGetPipelineActionTests extends ESTestCase { + + public void testGetPipeline() { + + GetResponse mockResponse = mock(GetResponse.class); + when(mockResponse.getId()).thenReturn("1"); + when(mockResponse.getSourceAsBytesRef()).thenReturn(mock(BytesReference.class)); + when(mockResponse.isExists()).thenReturn(true); + MultiGetResponse.Failure failure = mock(MultiGetResponse.Failure.class); + + MultiGetResponse mgr = new MultiGetResponse( + new MultiGetItemResponse[] { new MultiGetItemResponse(mockResponse, null), new MultiGetItemResponse(null, failure) } + ); + Client client = new NoOpClient(getTestName()) { + @Override + @SuppressWarnings("unchecked") + protected void doExecute( + ActionType action, + Request request, + ActionListener listener + ) { + listener.onResponse((Response) mgr); + } + }; + TransportGetPipelineAction action = new TransportGetPipelineAction(mock(TransportService.class), mock(ActionFilters.class), client); + GetPipelineRequest request = new GetPipelineRequest(List.of("1", "2")); + + ActionListener testActionListener = new ActionListener<>() { + @Override + public void onResponse(GetPipelineResponse getPipelineResponse) { + assertThat(getPipelineResponse, is(notNullValue())); + assertThat(getPipelineResponse.pipelines().size(), equalTo(1)); + + // todo - the multiget response has a contrived failure, but it has been swallowed + // silently. We need to either attach failures to GetPipelineResponse or log a warning + // and test for it here + } + + @Override + public void onFailure(Exception e) { + + } + }; + + action.doExecute(null, request, testActionListener); + + client.close(); + } +} From bc529ac7bdfe83948c8b9c68029902db337278e0 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Thu, 13 Aug 2020 16:59:28 -0400 Subject: [PATCH 16/21] Log failures for partial multiget failure --- .../action/TransportGetPipelineAction.java | 39 ++++++---- .../TransportGetPipelineActionTests.java | 72 +++++++++++++------ 2 files changed, 75 insertions(+), 36 deletions(-) diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java index a9de12d25dc65..49ab4777bd306 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineAction.java @@ -12,6 +12,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetResponse; import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.ActionFilters; @@ -29,6 +30,7 @@ import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -90,20 +92,18 @@ protected void doExecute(Task task, GetPipelineRequest request, ActionListener listener.onResponse( - new GetPipelineResponse( - Arrays.stream(mGetResponse.getResponses()) - .filter(itemResponse -> itemResponse.isFailed() == false) - .filter(itemResponse -> itemResponse.getResponse().isExists()) - .map(MultiGetItemResponse::getResponse) - .collect(Collectors.toMap(GetResponse::getId, GetResponse::getSourceAsBytesRef)) - ) - ), - listener::onFailure - ) - ); + .execute(ActionListener.wrap(mGetResponse -> { + logFailures(mGetResponse); + listener.onResponse( + new GetPipelineResponse( + Arrays.stream(mGetResponse.getResponses()) + .filter(itemResponse -> itemResponse.isFailed() == false) + .filter(itemResponse -> itemResponse.getResponse().isExists()) + .map(MultiGetItemResponse::getResponse) + .collect(Collectors.toMap(GetResponse::getId, GetResponse::getSourceAsBytesRef)) + ) + ); + }, listener::onFailure)); } } @@ -143,4 +143,15 @@ private void handleSearchResponse( ); } } + + private void logFailures(MultiGetResponse multiGetResponse) { + List ids = Arrays.stream(multiGetResponse.getResponses()) + .filter(MultiGetItemResponse::isFailed) + .filter(itemResponse -> itemResponse.getFailure() != null) + .map(itemResponse -> itemResponse.getFailure().getId()) + .collect(Collectors.toList()); + if (ids.isEmpty() == false) { + logger.info("Could not retrieve logstash pipelines with ids: {}", ids); + } + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java index 2555f0100e855..3f5952f54ce48 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java @@ -6,6 +6,9 @@ package org.elasticsearch.xpack.logstash.action; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; @@ -16,7 +19,9 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.MockLogAppender; import org.elasticsearch.test.client.NoOpClient; import org.elasticsearch.transport.TransportService; @@ -30,50 +35,73 @@ public class TransportGetPipelineActionTests extends ESTestCase { - public void testGetPipeline() { - + public void testGetPipelineMultipleIDs() throws Exception { GetResponse mockResponse = mock(GetResponse.class); when(mockResponse.getId()).thenReturn("1"); when(mockResponse.getSourceAsBytesRef()).thenReturn(mock(BytesReference.class)); when(mockResponse.isExists()).thenReturn(true); MultiGetResponse.Failure failure = mock(MultiGetResponse.Failure.class); - - MultiGetResponse mgr = new MultiGetResponse( + when(failure.getId()).thenReturn("2"); + MultiGetResponse multiGetResponse = new MultiGetResponse( new MultiGetItemResponse[] { new MultiGetItemResponse(mockResponse, null), new MultiGetItemResponse(null, failure) } ); - Client client = new NoOpClient(getTestName()) { - @Override - @SuppressWarnings("unchecked") - protected void doExecute( - ActionType action, - Request request, - ActionListener listener - ) { - listener.onResponse((Response) mgr); - } - }; - TransportGetPipelineAction action = new TransportGetPipelineAction(mock(TransportService.class), mock(ActionFilters.class), client); + GetPipelineRequest request = new GetPipelineRequest(List.of("1", "2")); + final MockLogAppender mockLogAppender = new MockLogAppender(); + mockLogAppender.addExpectation( + new MockLogAppender.SeenEventExpectation( + "message", + "org.elasticsearch.xpack.logstash.action.TransportGetPipelineAction", + Level.INFO, + "Could not retrieve logstash pipelines with ids: [2]" + ) + ); + mockLogAppender.start(); + final Logger logger = LogManager.getLogger(TransportGetPipelineAction.class); + ActionListener testActionListener = new ActionListener<>() { @Override public void onResponse(GetPipelineResponse getPipelineResponse) { + // check successful pipeline get assertThat(getPipelineResponse, is(notNullValue())); assertThat(getPipelineResponse.pipelines().size(), equalTo(1)); - // todo - the multiget response has a contrived failure, but it has been swallowed - // silently. We need to either attach failures to GetPipelineResponse or log a warning - // and test for it here + // check that failed pipeline get is logged + mockLogAppender.assertAllExpectationsMatched(); } @Override public void onFailure(Exception e) { - + // do nothing } }; - action.doExecute(null, request, testActionListener); + try (Client client = getMockClient(multiGetResponse)) { + Loggers.addAppender(logger, mockLogAppender); + TransportGetPipelineAction action = new TransportGetPipelineAction( + mock(TransportService.class), + mock(ActionFilters.class), + client + ); + action.doExecute(null, request, testActionListener); + } finally { + Loggers.removeAppender(logger, mockLogAppender); + mockLogAppender.stop(); + } + } - client.close(); + private Client getMockClient(ActionResponse response) { + return new NoOpClient(getTestName()) { + @Override + @SuppressWarnings("unchecked") + protected void doExecute( + ActionType action, + Request request, + ActionListener listener + ) { + listener.onResponse((Response) response); + } + }; } } From 435df7b5afd4f9be33f2a5eecd325d83794c40b7 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Fri, 14 Aug 2020 15:22:26 -0400 Subject: [PATCH 17/21] Clean up and add comments --- .../TransportGetPipelineActionTests.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java index 3f5952f54ce48..e42d76e96ffde 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java @@ -35,19 +35,13 @@ public class TransportGetPipelineActionTests extends ESTestCase { - public void testGetPipelineMultipleIDs() throws Exception { - GetResponse mockResponse = mock(GetResponse.class); - when(mockResponse.getId()).thenReturn("1"); - when(mockResponse.getSourceAsBytesRef()).thenReturn(mock(BytesReference.class)); - when(mockResponse.isExists()).thenReturn(true); - MultiGetResponse.Failure failure = mock(MultiGetResponse.Failure.class); - when(failure.getId()).thenReturn("2"); - MultiGetResponse multiGetResponse = new MultiGetResponse( - new MultiGetItemResponse[] { new MultiGetItemResponse(mockResponse, null), new MultiGetItemResponse(null, failure) } - ); - - GetPipelineRequest request = new GetPipelineRequest(List.of("1", "2")); - + /** + * Test that an error message is logged on a partial failure of + * a TransportGetPipelineAction. + * @throws Exception + */ + public void testGetPipelineMultipleIDsPartialFailure() throws Exception { + // Set up a log appender for detecting log messages final MockLogAppender mockLogAppender = new MockLogAppender(); mockLogAppender.addExpectation( new MockLogAppender.SeenEventExpectation( @@ -60,6 +54,20 @@ public void testGetPipelineMultipleIDs() throws Exception { mockLogAppender.start(); final Logger logger = LogManager.getLogger(TransportGetPipelineAction.class); + // Set up a MultiGetResponse + GetResponse mockResponse = mock(GetResponse.class); + when(mockResponse.getId()).thenReturn("1"); + when(mockResponse.getSourceAsBytesRef()).thenReturn(mock(BytesReference.class)); + when(mockResponse.isExists()).thenReturn(true); + MultiGetResponse.Failure failure = mock(MultiGetResponse.Failure.class); + when(failure.getId()).thenReturn("2"); + MultiGetResponse multiGetResponse = new MultiGetResponse( + new MultiGetItemResponse[] { new MultiGetItemResponse(mockResponse, null), new MultiGetItemResponse(null, failure) } + ); + + GetPipelineRequest request = new GetPipelineRequest(List.of("1", "2")); + + // Set up an ActionListener for the actual test conditions ActionListener testActionListener = new ActionListener<>() { @Override public void onResponse(GetPipelineResponse getPipelineResponse) { From fa51c6270d6ca57129cf0464b25504c06ff26ed9 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Tue, 18 Aug 2020 12:23:51 -0400 Subject: [PATCH 18/21] Fix Javadoc --- .../xpack/logstash/action/TransportGetPipelineActionTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java index e42d76e96ffde..b3c9e15ecfd33 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/TransportGetPipelineActionTests.java @@ -38,7 +38,6 @@ public class TransportGetPipelineActionTests extends ESTestCase { /** * Test that an error message is logged on a partial failure of * a TransportGetPipelineAction. - * @throws Exception */ public void testGetPipelineMultipleIDsPartialFailure() throws Exception { // Set up a log appender for detecting log messages From b734883c7cd6e91fab4d18f8e6e68186f67658e7 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Thu, 10 Sep 2020 13:20:07 -0400 Subject: [PATCH 19/21] Move LogstashSystemIndexIT to javaRestTest task --- .../elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) rename x-pack/plugin/src/{test => javaRestTest}/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java (96%) diff --git a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java similarity index 96% rename from x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java rename to x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java index 5d139862f35f3..37771e7597d28 100644 --- a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java +++ b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.test.SecuritySettingsSourceField; import org.elasticsearch.test.rest.ESRestTestCase; import java.io.IOException; @@ -25,11 +26,13 @@ import java.util.List; import java.util.Map; -import static org.elasticsearch.xpack.test.rest.XPackRestIT.BASIC_AUTH_VALUE; +import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; public class LogstashSystemIndexIT extends ESRestTestCase { + static final String BASIC_AUTH_VALUE = + basicAuthHeaderValue("x_pack_rest_user", SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING); @Override protected Settings restClientSettings() { From 551a789e20a0a111f9697e7bad7fe3c0683ed8fb Mon Sep 17 00:00:00 2001 From: William Brafford Date: Thu, 10 Sep 2020 17:17:58 -0400 Subject: [PATCH 20/21] Respond to PR feedback --- .../action/DeletePipelineRequestTests.java | 5 +++++ .../action/DeletePipelineResponseTests.java | 6 ++++++ .../action/GetPipelineRequestTests.java | 19 +++++++++++++++++++ .../action/GetPipelineResponseTests.java | 8 ++++++++ .../action/PutPipelineRequestTests.java | 9 +++++++++ .../action/PutPipelineResponseTests.java | 8 ++++++++ .../test/rest/LogstashSystemIndexIT.java | 1 - 7 files changed, 55 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java index 55533f617632a..a3682dd1d64d1 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineRequestTests.java @@ -20,4 +20,9 @@ protected Writeable.Reader instanceReader() { protected DeletePipelineRequest createTestInstance() { return new DeletePipelineRequest(randomAlphaOfLengthBetween(2, 10)); } + + @Override + protected DeletePipelineRequest mutateInstance(DeletePipelineRequest instance) { + return new DeletePipelineRequest(instance.id() + randomAlphaOfLength(1)); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java index 0d1c5f0b562dc..b4df0e55144a6 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/DeletePipelineResponseTests.java @@ -20,4 +20,10 @@ protected Writeable.Reader instanceReader() { protected DeletePipelineResponse createTestInstance() { return new DeletePipelineResponse(randomBoolean()); } + + @Override + protected DeletePipelineResponse mutateInstance(DeletePipelineResponse instance) { + // return a response with the opposite boolean value + return new DeletePipelineResponse(instance.isDeleted() == false); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java index 11c3d12c425f1..187e7f664f5f8 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java @@ -9,6 +9,11 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractWireSerializingTestCase; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + public class GetPipelineRequestTests extends AbstractWireSerializingTestCase { @Override @@ -20,4 +25,18 @@ protected Writeable.Reader instanceReader() { protected GetPipelineRequest createTestInstance() { return new GetPipelineRequest(randomList(0, 50, () -> randomAlphaOfLengthBetween(2, 10))); } + + @Override + protected GetPipelineRequest mutateInstance(GetPipelineRequest instance) { + List ids = new ArrayList<>(instance.ids()); + if (randomBoolean()) { + // append another ID + ids.add(randomAlphaOfLengthBetween(2, 10)); + } else { + ids = ids.stream() + .map(id -> id + randomAlphaOfLength(1)) + .collect(Collectors.toList()); + } + return new GetPipelineRequest(ids); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java index a3cc915090a1d..1c2d3573a5b82 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineResponseTests.java @@ -32,4 +32,12 @@ protected GetPipelineResponse createTestInstance() { } return new GetPipelineResponse(map); } + + @Override + protected GetPipelineResponse mutateInstance(GetPipelineResponse instance) { + Map map = new HashMap<>(instance.pipelines().size() + 1); + map.putAll(instance.pipelines()); + map.put(randomAlphaOfLengthBetween(2, 10), new BytesArray(randomByteArrayOfLength(randomIntBetween(1, 16)))); + return new GetPipelineResponse(map); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java index 7b4e8058f30b8..e727ec0422f91 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineRequestTests.java @@ -21,4 +21,13 @@ protected Writeable.Reader instanceReader() { protected PutPipelineRequest createTestInstance() { return new PutPipelineRequest(randomAlphaOfLength(2), randomAlphaOfLengthBetween(10, 100), randomFrom(XContentType.values())); } + + @Override + protected PutPipelineRequest mutateInstance(PutPipelineRequest instance) { + return new PutPipelineRequest( + instance.id() + randomAlphaOfLength(1), + instance.source() + randomAlphaOfLength(1), + instance.xContentType() + ); + } } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java index 822fd44105bc6..6ac6eed557fa1 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/PutPipelineResponseTests.java @@ -21,4 +21,12 @@ protected Writeable.Reader instanceReader() { protected PutPipelineResponse createTestInstance() { return new PutPipelineResponse(randomFrom(RestStatus.OK, RestStatus.CREATED)); } + + @Override + protected PutPipelineResponse mutateInstance(PutPipelineResponse instance) { + if (instance.status() == RestStatus.OK) { + return new PutPipelineResponse(RestStatus.CREATED); + } + return new PutPipelineResponse(RestStatus.OK); + } } diff --git a/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java index 37771e7597d28..bd76b7039bc82 100644 --- a/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java +++ b/x-pack/plugin/src/javaRestTest/java/org/elasticsearch/xpack/test/rest/LogstashSystemIndexIT.java @@ -126,7 +126,6 @@ public void testMultiplePipelines() throws IOException { assertTrue(responseMap.containsKey(id)); } - // TODO need to update this after system indices are truly system indices to enable refresh refreshAllIndices(); // list without any IDs From 5f8a4c3aa409d5dd4165bcbccfd0e5733bb799fe Mon Sep 17 00:00:00 2001 From: William Brafford Date: Thu, 10 Sep 2020 17:37:10 -0400 Subject: [PATCH 21/21] Remove unused imports, apply spotless --- .../xpack/logstash/action/GetPipelineRequestTests.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java index 187e7f664f5f8..629e174c1074e 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/action/GetPipelineRequestTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -33,9 +32,7 @@ protected GetPipelineRequest mutateInstance(GetPipelineRequest instance) { // append another ID ids.add(randomAlphaOfLengthBetween(2, 10)); } else { - ids = ids.stream() - .map(id -> id + randomAlphaOfLength(1)) - .collect(Collectors.toList()); + ids = ids.stream().map(id -> id + randomAlphaOfLength(1)).collect(Collectors.toList()); } return new GetPipelineRequest(ids); }