diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationIssue.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssue.java similarity index 99% rename from x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationIssue.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssue.java index fa8db3ebe553e..402f3b1285c7f 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationIssue.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssue.java @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -package org.elasticsearch.xpack.deprecation; +package org.elasticsearch.xpack.core.deprecation; import org.elasticsearch.Version; import org.elasticsearch.core.Nullable; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/LoggingDeprecationAccumulationHandler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/LoggingDeprecationAccumulationHandler.java similarity index 98% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/LoggingDeprecationAccumulationHandler.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/LoggingDeprecationAccumulationHandler.java index e33b73d3cdba8..4002b1de46386 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/LoggingDeprecationAccumulationHandler.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/LoggingDeprecationAccumulationHandler.java @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -package org.elasticsearch.xpack.core.ml.utils; +package org.elasticsearch.xpack.core.deprecation; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.xcontent.DeprecationHandler; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformer.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformer.java index 550218f8a2271..530a062a344c5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformer.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformer.java @@ -19,6 +19,7 @@ import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformDeprecations.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformDeprecations.java new file mode 100644 index 0000000000000..f42700c66f3f2 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/TransformDeprecations.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 + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.core.transform; + +public class TransformDeprecations { + public static final String BREAKING_CHANGES_BASE_URL = + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html"; + + public static final String QUERY_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_search_changes"; + + public static final String AGGS_BREAKING_CHANGES_URL = BREAKING_CHANGES_BASE_URL + "#breaking_80_aggregations_changes"; + + private TransformDeprecations() {} +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/DestConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/DestConfig.java index 3d57a09b19e8f..04947265d8197 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/DestConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/DestConfig.java @@ -9,18 +9,21 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; @@ -75,6 +78,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(index); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/QueryConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/QueryConfig.java index 7014b4a605681..7630fea72ac80 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/QueryConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/QueryConfig.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; @@ -25,12 +26,17 @@ import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; +import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler; +import org.elasticsearch.xpack.core.transform.TransformDeprecations; import org.elasticsearch.xpack.core.transform.TransformMessages; import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -83,10 +89,8 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni Map source = parser.mapOrdered(); QueryBuilder query = null; - try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); - XContentParser sourceParser = XContentType.JSON.xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, - BytesReference.bytes(xContentBuilder).streamInput())) { - query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser); + try { + query = queryFromXContent(source, registry, LoggingDeprecationHandler.INSTANCE); } catch (Exception e) { if (lenient) { logger.warn(TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY, e); @@ -98,6 +102,20 @@ public static QueryConfig fromXContent(final XContentParser parser, boolean leni return new QueryConfig(source, query); } + private static QueryBuilder queryFromXContent( + Map source, + NamedXContentRegistry namedXContentRegistry, + DeprecationHandler deprecationHandler + ) throws IOException { + QueryBuilder query = null; + XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); + XContentParser sourceParser = XContentType.JSON.xContent() + .createParser(namedXContentRegistry, deprecationHandler, BytesReference.bytes(xContentBuilder).streamInput()); + query = AbstractQueryBuilder.parseInnerQueryBuilder(sourceParser); + + return query; + } + @Override public int hashCode() { return Objects.hash(source, query); @@ -124,4 +142,37 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio } return validationException; } + + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + LoggingDeprecationAccumulationHandler deprecationLogger = new LoggingDeprecationAccumulationHandler(); + + try { + queryFromXContent(source, namedXContentRegistry, deprecationLogger); + } catch (IOException e) { + onDeprecation.accept( + new DeprecationIssue( + Level.CRITICAL, + "Transform [" + id + "]: " + TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_QUERY, + TransformDeprecations.QUERY_BREAKING_CHANGES_URL, + e.getMessage(), + false, + null + ) + ); + } + + deprecationLogger.getDeprecations().forEach(deprecationMessage -> { + onDeprecation.accept( + new DeprecationIssue( + Level.CRITICAL, + "Transform [" + id + "] uses deprecated query options", + TransformDeprecations.QUERY_BREAKING_CHANGES_URL, + deprecationMessage, + false, + null + ) + ); + }); + + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/RetentionPolicyConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/RetentionPolicyConfig.java index 2fb1e340a8041..707f105ff74b4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/RetentionPolicyConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/RetentionPolicyConfig.java @@ -9,8 +9,14 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.io.stream.NamedWriteable; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; + +import java.util.function.Consumer; public interface RetentionPolicyConfig extends ToXContentObject, NamedWriteable { ActionRequestValidationException validate(ActionRequestValidationException validationException); + + void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SettingsConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SettingsConfig.java index a62a5f67cdf11..5589f1da4d211 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SettingsConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SettingsConfig.java @@ -14,15 +14,18 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.aggregations.MultiBucketConsumerService; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.TransformField; import java.io.IOException; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; @@ -139,6 +142,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalInt(maxPageSearchSize); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SourceConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SourceConfig.java index 76f5ad3c5f3ce..a42f5f1c1c875 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SourceConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/SourceConfig.java @@ -9,17 +9,19 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.RemoteClusterLicenseChecker; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; @@ -29,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import static java.util.stream.Collectors.toMap; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; @@ -129,6 +132,10 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return queryConfig.validate(validationException); } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + queryConfig.checkForDeprecations(id, namedXContentRegistry, onDeprecation); + } + public boolean requiresRemoteCluster() { return Arrays.stream(index).anyMatch(RemoteClusterLicenseChecker::isRemoteIndex); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TimeRetentionPolicyConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TimeRetentionPolicyConfig.java index a355e00446739..56a4db63dc4c4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TimeRetentionPolicyConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TimeRetentionPolicyConfig.java @@ -11,16 +11,19 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.core.TimeValue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; @@ -90,6 +93,10 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + @Override + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + } + @Override public void writeTo(final StreamOutput out) throws IOException { out.writeString(field); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfig.java index a365e8908c842..06de022e507b8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfig.java @@ -10,21 +10,25 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.cluster.AbstractDiffable; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ObjectParser; +import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.core.Nullable; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.xpack.core.common.time.TimeUtils; import org.elasticsearch.xpack.core.common.validation.SourceDestValidator; import org.elasticsearch.xpack.core.common.validation.SourceDestValidator.SourceDestValidation; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; +import org.elasticsearch.xpack.core.transform.TransformDeprecations; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.TransformMessages; import org.elasticsearch.xpack.core.transform.transforms.latest.LatestConfig; @@ -33,6 +37,7 @@ import java.io.IOException; import java.time.Instant; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -54,7 +59,8 @@ public class TransformConfig extends AbstractDiffable implement /** Specifies all the possible transform functions. */ public enum Function { - PIVOT, LATEST; + PIVOT, + LATEST; private final ParseField parseField; @@ -66,6 +72,7 @@ public ParseField getParseField() { return parseField; } } + private static final ConstructingObjectParser STRICT_PARSER = createParser(false); private static final ConstructingObjectParser LENIENT_PARSER = createParser(true); static final int MAX_DESCRIPTION_LENGTH = 1_000; @@ -125,6 +132,7 @@ private static ConstructingObjectParser createParser(bo if ((args[7] == null) == (args[8] == null)) { throw new IllegalArgumentException(TransformMessages.TRANSFORM_CONFIGURATION_BAD_FUNCTION_COUNT); } + } @SuppressWarnings("unchecked") @@ -327,9 +335,10 @@ public RetentionPolicyConfig getRetentionPolicyConfig() { */ public List getAdditionalSourceDestValidations() { if ((source.getRuntimeMappings() == null || source.getRuntimeMappings().isEmpty()) == false) { - SourceDestValidation validation = - new SourceDestValidator.RemoteClusterMinimumVersionValidation( - FIELD_CAPS_RUNTIME_MAPPINGS_INTRODUCED_VERSION, "source.runtime_mappings field was set"); + SourceDestValidation validation = new SourceDestValidator.RemoteClusterMinimumVersionValidation( + FIELD_CAPS_RUNTIME_MAPPINGS_INTRODUCED_VERSION, + "source.runtime_mappings field was set" + ); return Collections.singletonList(validation); } else { return Collections.emptyList(); @@ -352,6 +361,45 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + /** + * Parses the transform configuration for deprecations + * + * @param namedXContentRegistry XContent registry required for aggregations and query DSL + * @return The deprecations of this transform + */ + public List checkForDeprecations(NamedXContentRegistry namedXContentRegistry) { + + List deprecations = new ArrayList<>(); + + // V_8_0_0 deprecate beta transforms + if (getVersion() == null || getVersion().before(Version.V_7_15_0)) { + deprecations.add( + new DeprecationIssue( + Level.CRITICAL, // change to WARNING for 7.x + "Transform [" + id + "] is too old", + TransformDeprecations.BREAKING_CHANGES_BASE_URL, + "The configuration uses an old format, you can use [_update] or [_upgrade] to update to configuration", + false, + null + ) + ); + } + + source.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + dest.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + settings.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + if (pivotConfig != null) { + pivotConfig.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + } + if (latestConfig != null) { + latestConfig.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + } + if (retentionPolicyConfig != null) { + retentionPolicyConfig.checkForDeprecations(getId(), namedXContentRegistry, deprecations::add); + } + return deprecations; + } + @Override public void writeTo(final StreamOutput out) throws IOException { out.writeString(id); @@ -551,7 +599,8 @@ private static TransformConfig applyRewriteForUpdate(Builder builder) { builder.getSettings().getMaxPageSearchSize(), builder.getSettings().getDocsPerSecond(), true, - builder.getSettings().getAlignCheckpoints()) + builder.getSettings().getAlignCheckpoints() + ) ); } @@ -562,7 +611,8 @@ private static TransformConfig applyRewriteForUpdate(Builder builder) { builder.getSettings().getMaxPageSearchSize(), builder.getSettings().getDocsPerSecond(), builder.getSettings().getDatesAsEpochMillis(), - false) + false + ) ); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/latest/LatestConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/latest/LatestConfig.java index 51ba7b0a923e2..9cfb1fc595daf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/latest/LatestConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/latest/LatestConfig.java @@ -8,17 +8,19 @@ package org.elasticsearch.xpack.core.transform.transforms.latest; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; import java.io.IOException; @@ -27,6 +29,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; @@ -108,6 +111,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/AggregationConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/AggregationConfig.java index 3b0401b0a38fd..63b8e0caf1da7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/AggregationConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/AggregationConfig.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; @@ -24,6 +25,10 @@ import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; import org.elasticsearch.search.aggregations.PipelineAggregationBuilder; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; +import org.elasticsearch.xpack.core.deprecation.LoggingDeprecationAccumulationHandler; +import org.elasticsearch.xpack.core.transform.TransformDeprecations; import org.elasticsearch.xpack.core.transform.TransformMessages; import java.io.IOException; @@ -33,6 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -105,7 +111,7 @@ private static void addAggNames(String namePrefix, PipelineAggregationBuilder pi public static AggregationConfig fromXContent(final XContentParser parser, boolean lenient) throws IOException { NamedXContentRegistry registry = parser.getXContentRegistry(); - Map source = parser.mapOrdered(); + Map source = parser.mapOrdered(); AggregatorFactories.Builder aggregations = null; if (source.isEmpty()) { @@ -115,11 +121,8 @@ public static AggregationConfig fromXContent(final XContentParser parser, boolea throw new IllegalArgumentException(TransformMessages.TRANSFORM_CONFIGURATION_PIVOT_NO_AGGREGATION); } } else { - try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); - XContentParser sourceParser = XContentType.JSON.xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, - BytesReference.bytes(xContentBuilder).streamInput())) { - sourceParser.nextToken(); - aggregations = AggregatorFactories.parseAggregators(sourceParser); + try { + aggregations = aggregationsFromXContent(source, registry, LoggingDeprecationHandler.INSTANCE); } catch (Exception e) { if (lenient) { logger.warn(TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_AGGREGATION, e); @@ -131,6 +134,22 @@ public static AggregationConfig fromXContent(final XContentParser parser, boolea return new AggregationConfig(source, aggregations); } + private static AggregatorFactories.Builder aggregationsFromXContent( + Map source, + NamedXContentRegistry namedXContentRegistry, + DeprecationHandler deprecationHandler + ) throws IOException { + AggregatorFactories.Builder aggregations = null; + + XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().map(source); + XContentParser sourceParser = XContentType.JSON.xContent() + .createParser(namedXContentRegistry, deprecationHandler, BytesReference.bytes(xContentBuilder).streamInput()); + sourceParser.nextToken(); + aggregations = AggregatorFactories.parseAggregators(sourceParser); + + return aggregations; + } + @Override public int hashCode() { return Objects.hash(source, aggregations); @@ -157,4 +176,37 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio } return validationException; } + + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + LoggingDeprecationAccumulationHandler deprecationLogger = new LoggingDeprecationAccumulationHandler(); + + try { + aggregationsFromXContent(source, namedXContentRegistry, deprecationLogger); + } catch (IOException e) { + onDeprecation.accept( + new DeprecationIssue( + Level.CRITICAL, + "Transform [" + id + "]: " + TransformMessages.LOG_TRANSFORM_CONFIGURATION_BAD_AGGREGATION, + TransformDeprecations.AGGS_BREAKING_CHANGES_URL, + e.getMessage(), + false, + null + ) + ); + } + + deprecationLogger.getDeprecations().forEach(deprecationMessage -> { + onDeprecation.accept( + new DeprecationIssue( + Level.CRITICAL, + "Transform [" + id + "] uses deprecated aggregation options", + TransformDeprecations.AGGS_BREAKING_CHANGES_URL, + deprecationMessage, + false, + null + ) + ); + }); + + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GroupConfig.java index 3ccb15e3cd8f6..0cbc1a1aaf707 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GroupConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/GroupConfig.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.TransformMessages; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; @@ -34,6 +35,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; import java.util.regex.Matcher; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -92,6 +94,9 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + } + @Override public void writeTo(StreamOutput out) throws IOException { out.writeMap(source); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfig.java index 02fb909299f72..22e627c260f13 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfig.java @@ -14,11 +14,15 @@ import org.elasticsearch.common.logging.DeprecationCategory; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.core.Nullable; import org.elasticsearch.search.aggregations.MultiBucketConsumerService; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; +import org.elasticsearch.xpack.core.transform.TransformDeprecations; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.utils.ExceptionsHelper; @@ -27,6 +31,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.function.Consumer; import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; @@ -174,6 +179,25 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio return validationException; } + public void checkForDeprecations(String id, NamedXContentRegistry namedXContentRegistry, Consumer onDeprecation) { + if (maxPageSearchSize != null) { + onDeprecation.accept( + // max_page_search_size got deprecated in 7.8, still accepted for 8.x, to be removed in 9.x + new DeprecationIssue( + Level.WARNING, + "Transform [" + id + "] uses deprecated max_page_search_size", + TransformDeprecations.BREAKING_CHANGES_BASE_URL, + "[max_page_search_size] is deprecated inside pivot please use settings instead", + false, + null + ) + ); + } + + groups.checkForDeprecations(id, namedXContentRegistry, onDeprecation); + aggregationConfig.checkForDeprecations(id, namedXContentRegistry, onDeprecation); + } + public static PivotConfig fromXContent(final XContentParser parser, boolean lenient) throws IOException { return lenient ? LENIENT_PARSER.apply(parser, null) : STRICT_PARSER.apply(parser, null); } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationIssueTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssueTests.java similarity index 96% rename from x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationIssueTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssueTests.java index 290522c646d1d..05f1d01dd984b 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationIssueTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationIssueTests.java @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -package org.elasticsearch.xpack.deprecation; +package org.elasticsearch.xpack.core.deprecation; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -14,13 +14,13 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.Tuple; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; import org.junit.Before; import java.io.IOException; import java.util.Map; import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; -import static org.elasticsearch.xpack.deprecation.DeprecationIssue.Level; import static org.hamcrest.core.IsEqual.equalTo; public class DeprecationIssueTests extends ESTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfigTests.java index 8ad9f550e8c7c..3d3b54d9c59c9 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfigTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/TransformConfigTests.java @@ -21,6 +21,8 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.xpack.core.common.validation.SourceDestValidator.RemoteClusterMinimumVersionValidation; import org.elasticsearch.xpack.core.common.validation.SourceDestValidator.SourceDestValidation; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; import org.elasticsearch.xpack.core.transform.AbstractSerializingTransformTestCase; import org.elasticsearch.xpack.core.transform.transforms.latest.LatestConfig; import org.elasticsearch.xpack.core.transform.transforms.latest.LatestConfigTests; @@ -31,6 +33,7 @@ import java.io.IOException; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -91,7 +94,15 @@ public static TransformConfig randomTransformConfig() { return randomTransformConfig(randomAlphaOfLengthBetween(1, 10)); } + public static TransformConfig randomTransformConfigWithDeprecatedFields(String id, Version version) { + return randomTransformConfig(id, version, PivotConfigTests.randomPivotConfigWithDeprecatedFields(), null); + } + public static TransformConfig randomTransformConfig(String id) { + return randomTransformConfig(id, randomBoolean() ? null : Version.CURRENT); + } + + public static TransformConfig randomTransformConfig(String id, Version version) { PivotConfig pivotConfig; LatestConfig latestConfig; if (randomBoolean()) { @@ -102,10 +113,10 @@ public static TransformConfig randomTransformConfig(String id) { latestConfig = LatestConfigTests.randomLatestConfig(); } - return randomTransformConfig(id, pivotConfig, latestConfig); + return randomTransformConfig(id, version, pivotConfig, latestConfig); } - public static TransformConfig randomTransformConfig(String id, PivotConfig pivotConfig, LatestConfig latestConfig) { + public static TransformConfig randomTransformConfig(String id, Version version, PivotConfig pivotConfig, LatestConfig latestConfig) { return new TransformConfig( id, randomSourceConfig(), @@ -119,7 +130,7 @@ public static TransformConfig randomTransformConfig(String id, PivotConfig pivot randomBoolean() ? null : SettingsConfigTests.randomSettingsConfig(), randomBoolean() ? null : randomRetentionPolicyConfig(), randomBoolean() ? null : Instant.now(), - randomBoolean() ? null : Version.CURRENT.toString() + version == null ? null : version.toString() ); } @@ -496,10 +507,9 @@ public void testRewriteForUpdateAlignCheckpoints() throws IOException { assertEquals(Version.CURRENT, transformConfigRewritten.getVersion()); assertFalse(transformConfigRewritten.getSettings().getAlignCheckpoints()); - TransformConfig explicitFalseAfter715 = new TransformConfig.Builder(transformConfig) - .setSettings(new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setAlignCheckpoints(false).build()) - .setVersion(Version.V_7_15_0) - .build(); + TransformConfig explicitFalseAfter715 = new TransformConfig.Builder(transformConfig).setSettings( + new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setAlignCheckpoints(false).build() + ).setVersion(Version.V_7_15_0).build(); transformConfigRewritten = TransformConfig.rewriteForUpdate(explicitFalseAfter715); assertFalse(transformConfigRewritten.getSettings().getAlignCheckpoints()); @@ -570,20 +580,18 @@ public void testRewriteForBWCOfDateNormalization() throws IOException { assertTrue(transformConfigRewritten.getSettings().getDatesAsEpochMillis()); assertEquals(Version.CURRENT, transformConfigRewritten.getVersion()); - TransformConfig explicitTrueAfter711 = new TransformConfig.Builder(transformConfig) - .setSettings(new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setDatesAsEpochMillis(true).build()) - .setVersion(Version.V_7_11_0) - .build(); + TransformConfig explicitTrueAfter711 = new TransformConfig.Builder(transformConfig).setSettings( + new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setDatesAsEpochMillis(true).build() + ).setVersion(Version.V_7_11_0).build(); transformConfigRewritten = TransformConfig.rewriteForUpdate(explicitTrueAfter711); assertTrue(transformConfigRewritten.getSettings().getDatesAsEpochMillis()); // The config is still being rewritten due to "settings.align_checkpoints". assertEquals(Version.CURRENT, transformConfigRewritten.getVersion()); - TransformConfig explicitTrueAfter715 = new TransformConfig.Builder(transformConfig) - .setSettings(new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setDatesAsEpochMillis(true).build()) - .setVersion(Version.V_7_15_0) - .build(); + TransformConfig explicitTrueAfter715 = new TransformConfig.Builder(transformConfig).setSettings( + new SettingsConfig.Builder(transformConfigRewritten.getSettings()).setDatesAsEpochMillis(true).build() + ).setVersion(Version.V_7_15_0).build(); transformConfigRewritten = TransformConfig.rewriteForUpdate(explicitTrueAfter715); assertTrue(transformConfigRewritten.getSettings().getDatesAsEpochMillis()); @@ -690,6 +698,64 @@ public void testGroupByStayInOrder() throws IOException { } } + public void testCheckForDeprecations() { + String id = randomAlphaOfLengthBetween(1, 10); + assertThat(randomTransformConfig(id, Version.CURRENT).checkForDeprecations(xContentRegistry()), is(empty())); + + TransformConfig deprecatedConfig = randomTransformConfigWithDeprecatedFields(id, Version.CURRENT); + + // check _and_ clear warnings + assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead"); + + // important: checkForDeprecations does _not_ create new deprecation warnings + assertThat( + deprecatedConfig.checkForDeprecations(xContentRegistry()), + equalTo( + Collections.singletonList( + new DeprecationIssue( + Level.WARNING, + "Transform [" + id + "] uses deprecated max_page_search_size", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html", + "[max_page_search_size] is deprecated inside pivot please use settings instead", + false, + null + ) + ) + ) + ); + + deprecatedConfig = randomTransformConfigWithDeprecatedFields(id, Version.V_7_4_0); + + // check _and_ clear warnings + assertWarnings("[max_page_search_size] is deprecated inside pivot please use settings instead"); + + // important: checkForDeprecations does _not_ create new deprecation warnings + assertThat( + deprecatedConfig.checkForDeprecations(xContentRegistry()), + equalTo( + List.of( + new DeprecationIssue( + Level.CRITICAL, + "Transform [" + id + "] is too old", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html", + "The configuration uses an old format, you can use [_update] or [_upgrade] to update to configuration", + false, + null + ), + new DeprecationIssue( + Level.WARNING, + "Transform [" + id + "] uses deprecated max_page_search_size", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html", + "[max_page_search_size] is deprecated inside pivot please use settings instead", + false, + null + ) + ) + ) + ); + + } + private TransformConfig createTransformConfigFromString(String json, String id) throws IOException { return createTransformConfigFromString(json, id, false); } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecker.java index c0cbe68995d71..7e64ea8c47113 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecker.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecker.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.OriginSettingClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index fa82c6b234838..d98be7bbbb97d 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -10,6 +10,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.Collections; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java index e216ff7b7d810..ba2b7b8ac21ae 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index 4b55525d6fc4b..272b788be169c 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.Locale; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/MlDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/MlDeprecationChecker.java index 3f6655e4a91bb..d0c501cb9b0fd 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/MlDeprecationChecker.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/MlDeprecationChecker.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.XContentElasticsearchExtension; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.action.util.PageParams; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction; import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 1a66795d626bc..6d06a61908154 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.security.authc.RealmConfig; import org.elasticsearch.xpack.core.security.authc.RealmSettings; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckAction.java index 2233bb2556bb1..590868f5578ea 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.transport.TransportRequest; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java index cccd97689ad5d..8550f9a5624e6 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.Collections; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckAction.java index 886f7b99bb8b8..3e2397af46ecc 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportNodeDeprecationCheckAction.java @@ -18,6 +18,7 @@ import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationChecksTests.java index 4a3c60ac5062c..db2b270376536 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationChecksTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.core.Tuple; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.ArrayList; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java index 24208427aab07..dc32491eaf4be 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java @@ -20,8 +20,11 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.core.Tuple; import org.elasticsearch.indices.TestIndexNameExpressionResolver; import org.elasticsearch.test.AbstractWireSerializingTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; import java.io.IOException; import java.util.Collections; @@ -43,19 +46,19 @@ public class DeprecationInfoActionResponseTests extends AbstractWireSerializingT @Override protected DeprecationInfoAction.Response createTestInstance() { - List clusterIssues = Stream.generate(DeprecationIssueTests::createTestInstance) + List clusterIssues = Stream.generate(DeprecationInfoActionResponseTests::createTestDeprecationIssue) .limit(randomIntBetween(0, 10)).collect(Collectors.toList()); - List nodeIssues = Stream.generate(DeprecationIssueTests::createTestInstance) + List nodeIssues = Stream.generate(DeprecationInfoActionResponseTests::createTestDeprecationIssue) .limit(randomIntBetween(0, 10)).collect(Collectors.toList()); Map> indexIssues = new HashMap<>(); for (int i = 0; i < randomIntBetween(0, 10); i++) { - List perIndexIssues = Stream.generate(DeprecationIssueTests::createTestInstance) + List perIndexIssues = Stream.generate(DeprecationInfoActionResponseTests::createTestDeprecationIssue) .limit(randomIntBetween(0, 10)).collect(Collectors.toList()); indexIssues.put(randomAlphaOfLength(10), perIndexIssues); } Map> pluginIssues = new HashMap<>(); for (int i = 0; i < randomIntBetween(0, 10); i++) { - List perPluginIssues = Stream.generate(DeprecationIssueTests::createTestInstance) + List perPluginIssues = Stream.generate(DeprecationInfoActionResponseTests::createTestDeprecationIssue) .limit(randomIntBetween(0, 10)).collect(Collectors.toList()); pluginIssues.put(randomAlphaOfLength(10), perPluginIssues); } @@ -86,7 +89,7 @@ public void testFrom() throws IOException { boolean clusterIssueFound = randomBoolean(); boolean nodeIssueFound = randomBoolean(); boolean indexIssueFound = randomBoolean(); - DeprecationIssue foundIssue = DeprecationIssueTests.createTestInstance(); + DeprecationIssue foundIssue = createTestDeprecationIssue(); List> clusterSettingsChecks = List.of((s) -> clusterIssueFound ? foundIssue : null); List> indexSettingsChecks = List.of((idx) -> indexIssueFound ? foundIssue : null); @@ -146,4 +149,16 @@ public void testCtorFailure() { ); } } + + private static DeprecationIssue createTestDeprecationIssue() { + String details = randomBoolean() ? randomAlphaOfLength(10) : null; + return new DeprecationIssue( + randomFrom(Level.values()), + randomAlphaOfLength(10), + randomAlphaOfLength(10), + details, + randomBoolean(), + randomMap(1, 5, () -> Tuple.tuple(randomAlphaOfLength(4), randomAlphaOfLength(4))) + ); + } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 98c8a933f3bd4..b271ec46e4650 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 240c9a70c927d..83f2689abf177 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.ArrayList; import java.util.List; diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java index dae8375b73d7f..5728aa516a6b8 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java @@ -13,7 +13,10 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.core.Tuple; import org.elasticsearch.test.AbstractWireSerializingTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue.Level; import java.io.IOException; import java.net.InetAddress; @@ -79,8 +82,21 @@ private static NodesDeprecationCheckAction.NodeResponse randomNodeResponse() { } catch (Exception e) { throw new RuntimeException(e); } - List issuesList = Arrays.asList(randomArray(0,10, DeprecationIssue[]::new, - DeprecationIssueTests::createTestInstance)); + List issuesList = Arrays.asList( + randomArray(0, 10, DeprecationIssue[]::new, NodesDeprecationCheckResponseTests::createTestDeprecationIssue) + ); return new NodesDeprecationCheckAction.NodeResponse(node, issuesList); } + + private static DeprecationIssue createTestDeprecationIssue() { + String details = randomBoolean() ? randomAlphaOfLength(10) : null; + return new DeprecationIssue( + randomFrom(Level.values()), + randomAlphaOfLength(10), + randomAlphaOfLength(10), + details, + randomBoolean(), + randomMap(1, 5, () -> Tuple.tuple(randomAlphaOfLength(4), randomAlphaOfLength(4))) + ); + } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java index 6410ca48230c5..118cfd6cb8c64 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.List; import java.util.Map; diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/FunctionFactoryTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/FunctionFactoryTests.java index 60e4e107ae529..71664c4f79e9b 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/FunctionFactoryTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/FunctionFactoryTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.transform.transforms; +import org.elasticsearch.Version; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.transform.transforms.TransformConfig; import org.elasticsearch.xpack.core.transform.transforms.TransformConfigTests; @@ -21,21 +22,23 @@ public class FunctionFactoryTests extends ESTestCase { public void testCreatePivotFunction() { - TransformConfig config = - TransformConfigTests.randomTransformConfig( - randomAlphaOfLengthBetween(1, 10), - PivotConfigTests.randomPivotConfig(), - null); + TransformConfig config = TransformConfigTests.randomTransformConfig( + randomAlphaOfLengthBetween(1, 10), + Version.CURRENT, + PivotConfigTests.randomPivotConfig(), + null + ); Function function = FunctionFactory.create(config); assertThat(function, is(instanceOf(Pivot.class))); } public void testCreateLatestFunction() { - TransformConfig config = - TransformConfigTests.randomTransformConfig( - randomAlphaOfLengthBetween(1, 10), - null, - LatestConfigTests.randomLatestConfig()); + TransformConfig config = TransformConfigTests.randomTransformConfig( + randomAlphaOfLengthBetween(1, 10), + Version.CURRENT, + null, + LatestConfigTests.randomLatestConfig() + ); Function function = FunctionFactory.create(config); assertThat(function, is(instanceOf(Latest.class))); }