From c4827445f293c5bac612a43bfed357c9a3f23e0f Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Thu, 12 Mar 2020 08:41:30 -0600 Subject: [PATCH 001/285] Deprecate the logstash enabled setting (#53367) The setting, `xpack.logstash.enabled`, exists to enable or disable the logstash extensions found within x-pack. In practice, this setting had no effect on the functionality of the extension. Given this, the setting is now deprecated in preparation for removal. --- .../java/org/elasticsearch/xpack/CcrIntegTestCase.java | 1 - .../org/elasticsearch/xpack/CcrSingleNodeTestCase.java | 1 - .../java/org/elasticsearch/xpack/core/XPackSettings.java | 2 +- .../xpack/ilm/IndexLifecycleInitialisationTests.java | 1 - .../xpack/slm/SnapshotLifecycleInitialisationTests.java | 1 - .../java/org/elasticsearch/xpack/logstash/Logstash.java | 7 +------ .../xpack/logstash/LogstashInfoTransportActionTests.java | 4 ++++ 7 files changed, 6 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java index 7181dd9b6c9a2..c349ea764101f 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java @@ -225,7 +225,6 @@ private NodeConfigurationSource createNodeConfigurationSource(final String leade builder.put(XPackSettings.MONITORING_ENABLED.getKey(), false); builder.put(XPackSettings.WATCHER_ENABLED.getKey(), false); builder.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); - builder.put(XPackSettings.LOGSTASH_ENABLED.getKey(), false); builder.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial"); // Let cluster state api return quickly in order to speed up auto follow tests: builder.put(CcrSettings.CCR_WAIT_FOR_METADATA_TIMEOUT.getKey(), TimeValue.timeValueMillis(100)); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java index cbfd078452368..9858362c811de 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrSingleNodeTestCase.java @@ -48,7 +48,6 @@ protected Settings nodeSettings() { builder.put(XPackSettings.MONITORING_ENABLED.getKey(), false); builder.put(XPackSettings.WATCHER_ENABLED.getKey(), false); builder.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false); - builder.put(XPackSettings.LOGSTASH_ENABLED.getKey(), false); builder.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial"); // Let cluster state api return quickly in order to speed up auto follow tests: builder.put(CcrSettings.CCR_WAIT_FOR_METADATA_TIMEOUT.getKey(), TimeValue.timeValueMillis(100)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java index f61232cf97b1b..740d1015a7eb6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java @@ -82,7 +82,7 @@ private XPackSettings() { /** Setting for enabling or disabling Logstash extensions. Defaults to true. */ public static final Setting LOGSTASH_ENABLED = Setting.boolSetting("xpack.logstash.enabled", true, - Setting.Property.NodeScope); + Setting.Property.NodeScope, Property.Deprecated); /** * Setting for enabling or disabling the index lifecycle extension. Defaults to true. diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java index 4f4c2913fb2a4..965c5beb5af04 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java @@ -100,7 +100,6 @@ protected Settings nodeSettings(int nodeOrdinal) { settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.MONITORING_ENABLED.getKey(), false); settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false); - settings.put(XPackSettings.LOGSTASH_ENABLED.getKey(), false); settings.put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s"); // This is necessary to prevent ILM and SLM installing a lifecycle policy, these tests assume a blank slate diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleInitialisationTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleInitialisationTests.java index 180ff53cf5b97..58f0b632e1321 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleInitialisationTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleInitialisationTests.java @@ -50,7 +50,6 @@ protected Settings nodeSettings() { settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false); settings.put(XPackSettings.MONITORING_ENABLED.getKey(), false); settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false); - settings.put(XPackSettings.LOGSTASH_ENABLED.getKey(), false); settings.put(Environment.PATH_REPO_SETTING.getKey(), repositoryLocation); settings.put(XPackSettings.SNAPSHOT_LIFECYCLE_ENABLED.getKey(), true); 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 9c7ef923c10d1..3d22402e89779 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 @@ -14,7 +14,6 @@ import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; import org.elasticsearch.xpack.core.template.TemplateUtils; @@ -37,11 +36,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"; - private final boolean enabled; - - public Logstash(Settings settings) { - this.enabled = XPackSettings.LOGSTASH_ENABLED.get(settings); - } + public Logstash() {} @Override public List> getActions() { 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 f78d6424fd148..e3872352b944d 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,11 +8,13 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackFeatureSet; +import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse; import org.elasticsearch.xpack.core.logstash.LogstashFeatureSetUsage; @@ -42,6 +44,8 @@ public void testEnabledSetting() throws Exception { usage.writeTo(out); XPackFeatureSet.Usage serializedUsage = new LogstashFeatureSetUsage(out.bytes().streamInput()); assertThat(serializedUsage.enabled(), is(enabled)); + + assertSettingDeprecationsAndWarnings(new Setting[] { XPackSettings.LOGSTASH_ENABLED }); } public void testEnabledDefault() throws Exception { From ae55e06253aa39e8e242e3e2feceab0e8e18e424 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 12 Mar 2020 09:27:25 -0600 Subject: [PATCH 002/285] Add ComponentTemplate to MetaData (#53290) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add ComponentTemplate to MetaData This adds a `ComponentTemplate` datastructure that will be used as part of #53101 (Index Templates v2) to the `MetaData` class. Currently there are no APIs for interacting with this class, so it will always be an empty map (other than in tests). This infrastructure will be built upon to add APIs in a subsequent commit. A `ComponentTemplate` is made up of a `Template`, a version, and a MetaData.Custom class. The `Template` contains similar information to an `IndexTemplateMetaData` object— settings, mappings, and alias configuration. --- .../elasticsearch/cluster/ClusterModule.java | 5 + .../cluster/metadata/ComponentTemplate.java | 300 ++++++++++++++++++ .../metadata/ComponentTemplateMetadata.java | 170 ++++++++++ .../cluster/metadata/MetaData.java | 35 ++ .../ComponentTemplateMetadataTests.java | 70 ++++ .../metadata/ComponentTemplateTests.java | 163 ++++++++++ .../cluster/metadata/MetaDataTests.java | 36 ++- .../metadata/ToAndFromJsonMetaDataTests.java | 16 + 8 files changed, 794 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplate.java create mode 100644 server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadata.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/metadata/ComponentTemplateMetadataTests.java create mode 100644 server/src/test/java/org/elasticsearch/cluster/metadata/ComponentTemplateTests.java diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index e445615e0fc73..70138ecc981bc 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction; import org.elasticsearch.cluster.action.index.NodeMappingRefreshAction; import org.elasticsearch.cluster.action.shard.ShardStateAction; +import org.elasticsearch.cluster.metadata.ComponentTemplateMetadata; import org.elasticsearch.cluster.metadata.IndexGraveyard; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; @@ -127,6 +128,8 @@ public static List getNamedWriteables() { registerMetaDataCustom(entries, IndexGraveyard.TYPE, IndexGraveyard::new, IndexGraveyard::readDiffFrom); registerMetaDataCustom(entries, PersistentTasksCustomMetaData.TYPE, PersistentTasksCustomMetaData::new, PersistentTasksCustomMetaData::readDiffFrom); + registerMetaDataCustom(entries, ComponentTemplateMetadata.TYPE, ComponentTemplateMetadata::new, + ComponentTemplateMetadata::readDiffFrom); // Task Status (not Diffable) entries.add(new Entry(Task.Status.class, PersistentTasksNodeService.Status.NAME, PersistentTasksNodeService.Status::new)); return entries; @@ -145,6 +148,8 @@ public static List getNamedXWriteables() { IndexGraveyard::fromXContent)); entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(PersistentTasksCustomMetaData.TYPE), PersistentTasksCustomMetaData::fromXContent)); + entries.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(ComponentTemplateMetadata.TYPE), + ComponentTemplateMetadata::fromXContent)); return entries; } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplate.java b/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplate.java new file mode 100644 index 0000000000000..2b160b1b2fb11 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/ComponentTemplate.java @@ -0,0 +1,300 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.cluster.metadata; + +import org.elasticsearch.cluster.AbstractDiffable; +import org.elasticsearch.cluster.Diff; +import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.compress.CompressedXContent; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * A component template is a re-usable template as well as metadata about the template. Each + * component template is expected to be valid on its own. For example, if a component template + * contains a field "foo", it's expected to contain all the necessary settings/mappings/etc for the + * "foo" field. These component templates make up the individual pieces composing an index template. + */ +public class ComponentTemplate extends AbstractDiffable implements ToXContentObject { + private static final ParseField TEMPLATE = new ParseField("template"); + private static final ParseField VERSION = new ParseField("version"); + private static final ParseField METADATA = new ParseField("_meta"); + + @SuppressWarnings("unchecked") + private static final ConstructingObjectParser PARSER = + new ConstructingObjectParser<>("component_template", false, + a -> new ComponentTemplate((Template) a[0], (Long) a[1], (Map) a[2])); + + static { + PARSER.declareObject(ConstructingObjectParser.constructorArg(), Template.PARSER, TEMPLATE); + PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), VERSION); + PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.map(), METADATA); + } + + private final Template template; + @Nullable + private final Long version; + @Nullable + private final Map metadata; + + static Diff readComponentTemplateDiffFrom(StreamInput in) throws IOException { + return AbstractDiffable.readDiffFrom(ComponentTemplate::new, in); + } + + public static ComponentTemplate parse(XContentParser parser) { + return PARSER.apply(parser, null); + } + + public ComponentTemplate(Template template, @Nullable Long version, @Nullable Map metadata) { + this.template = template; + this.version = version; + this.metadata = metadata; + } + + public ComponentTemplate(StreamInput in) throws IOException { + this.template = new Template(in); + this.version = in.readOptionalVLong(); + if (in.readBoolean()) { + this.metadata = in.readMap(); + } else { + this.metadata = null; + } + } + + public Template template() { + return template; + } + + @Nullable + public Long version() { + return version; + } + + @Nullable + public Map metadata() { + return metadata; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + this.template.writeTo(out); + out.writeOptionalVLong(this.version); + if (this.metadata == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeMap(this.metadata); + } + } + + @Override + public int hashCode() { + return Objects.hash(template, version, metadata); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj.getClass() != getClass()) { + return false; + } + ComponentTemplate other = (ComponentTemplate) obj; + return Objects.equals(template, other.template) && + Objects.equals(version, other.version) && + Objects.equals(metadata, other.metadata); + } + + @Override + public String toString() { + return Strings.toString(this); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.field(TEMPLATE.getPreferredName(), this.template); + if (this.version != null) { + builder.field(VERSION.getPreferredName(), this.version); + } + if (this.metadata != null) { + builder.field(METADATA.getPreferredName(), this.metadata); + } + builder.endObject(); + return builder; + } + + static class Template extends AbstractDiffable