diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MachineLearningClientActionPlugin.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MachineLearningClientActionPlugin.java deleted file mode 100644 index 59ee70ebad2..00000000000 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MachineLearningClientActionPlugin.java +++ /dev/null @@ -1,14 +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.core.ml; - -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.unit.TimeValue; - -public interface MachineLearningClientActionPlugin { - -} diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java index efb7078afe8..5eafbf1b070 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/ExpressionRoleMapping.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.security.authc.support.mapper; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -99,7 +100,8 @@ public class ExpressionRoleMapping implements ToXContentObject, Writeable { /** * The expression that determines whether the roles in this mapping should be applied to any given user. - * If the expression {@link RoleMapperExpression#match(Map) matches} a + * If the expression + * {@link RoleMapperExpression#match(org.elasticsearch.xpack.security.authc.support.mapper.expressiondsl.ExpressionModel) matches} a * org.elasticsearch.xpack.security.authc.support.UserRoleMapper.UserData user, then the user should be assigned this mapping's * {@link #getRoles() roles} */ @@ -133,7 +135,7 @@ public class ExpressionRoleMapping implements ToXContentObject, Writeable { @Override public String toString() { - return getClass().getSimpleName() + "<" + name + " ; " + roles + " = " + expression + ">"; + return getClass().getSimpleName() + "<" + name + " ; " + roles + " = " + Strings.toString(expression) + ">"; } /** diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AllExpression.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AllExpression.java index 11fb5e9728a..d7a4781903b 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AllExpression.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AllExpression.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Map; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -45,8 +44,8 @@ public final class AllExpression implements RoleMapperExpression { } @Override - public boolean match(Map object) { - return elements.stream().allMatch(RoleMapperExpression.predicate(object)); + public boolean match(ExpressionModel model) { + return elements.stream().allMatch(RoleMapperExpression.predicate(model)); } public List getElements() { diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AnyExpression.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AnyExpression.java index 562410a01ad..7f609e73daf 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AnyExpression.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/AnyExpression.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Map; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -45,8 +44,8 @@ public final class AnyExpression implements RoleMapperExpression { } @Override - public boolean match(Map object) { - return elements.stream().anyMatch(RoleMapperExpression.predicate(object)); + public boolean match(ExpressionModel model) { + return elements.stream().anyMatch(RoleMapperExpression.predicate(model)); } public List getElements() { diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExceptExpression.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExceptExpression.java index 9243d963e0c..b85a59ee708 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExceptExpression.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExceptExpression.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl; import java.io.IOException; -import java.util.Map; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -44,8 +43,8 @@ public final class ExceptExpression implements RoleMapperExpression { } @Override - public boolean match(Map object) { - return !expression.match(object); + public boolean match(ExpressionModel model) { + return !expression.match(model); } @Override diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModel.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModel.java new file mode 100644 index 00000000000..8d43f864878 --- /dev/null +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModel.java @@ -0,0 +1,106 @@ +/* + * 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.core.security.authc.support.mapper.expressiondsl; + +import org.elasticsearch.common.Numbers; +import org.elasticsearch.common.collect.Tuple; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +/** + * Represents the "model" object to be evaluated within a {@link RoleMapperExpression}. + * The model is a flat object, where fields are defined by strings and value is either a + * string, boolean, or number, or a collection of the above. + */ +public class ExpressionModel { + + public static final Predicate NULL_PREDICATE = field -> field.getValue() == null; + private Map>> fields; + + public ExpressionModel() { + this.fields = new HashMap<>(); + } + + /** + * Defines a field using a predicate that corresponds to the type of {@code value} + * + * @see #buildPredicate(Object) + */ + public ExpressionModel defineField(String name, Object value) { + return defineField(name, value, buildPredicate(value)); + } + + /** + * Defines a field using a supplied predicate. + */ + public ExpressionModel defineField(String name, Object value, Predicate predicate) { + this.fields.put(name, new Tuple<>(value, predicate)); + return this; + } + + /** + * Returns {@code true} if the named field, matches any of the provided values. + */ + public boolean test(String field, List values) { + final Tuple> tuple = this.fields.get(field); + final Predicate predicate; + if (tuple == null) { + predicate = NULL_PREDICATE; + } else { + predicate = tuple.v2(); + } + return values.stream().anyMatch(predicate); + } + + /** + * Constructs a {@link Predicate} that matches correctly based on the type of the provided parameter. + */ + static Predicate buildPredicate(Object object) { + if (object == null) { + return NULL_PREDICATE; + } + if (object instanceof Boolean) { + return field -> object.equals(field.getValue()); + } + if (object instanceof Number) { + return field -> numberEquals((Number) object, field.getValue()); + } + if (object instanceof String) { + return field -> field.getAutomaton() == null ? object.equals(field.getValue()) : field.getAutomaton().run((String) object); + } + if (object instanceof Collection) { + return ((Collection) object).stream() + .map(element -> buildPredicate(element)) + .reduce((a, b) -> a.or(b)) + .orElse(fieldValue -> false); + } + throw new IllegalArgumentException("Unsupported value type " + object.getClass()); + } + + /** + * A comparison of {@link Number} objects that compares by floating point when either value is a {@link Float} or {@link Double} + * otherwise compares by {@link Numbers#toLongExact long}. + */ + private static boolean numberEquals(Number left, Object other) { + if (left.equals(other)) { + return true; + } + if ((other instanceof Number) == false) { + return false; + } + Number right = (Number) other; + if (left instanceof Double || left instanceof Float + || right instanceof Double || right instanceof Float) { + return Double.compare(left.doubleValue(), right.doubleValue()) == 0; + } + return Numbers.toLongExact(left) == Numbers.toLongExact(right); + } + +} diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java index 10700cf4c77..9a13acc1786 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParser.java @@ -114,7 +114,7 @@ public final class ExpressionParser { private RoleMapperExpression parseFieldExpression(XContentParser parser) throws IOException { checkStartObject(parser); final String fieldName = readFieldName(Fields.FIELD.getPreferredName(), parser); - final List values; + final List values; if (parser.nextToken() == XContentParser.Token.START_ARRAY) { values = parseArray(Fields.FIELD, parser, this::parseFieldValue); } else { @@ -166,19 +166,19 @@ public final class ExpressionParser { } } - private FieldExpression.FieldPredicate parseFieldValue(XContentParser parser) throws IOException { + private FieldExpression.FieldValue parseFieldValue(XContentParser parser) throws IOException { switch (parser.currentToken()) { case VALUE_STRING: - return FieldExpression.FieldPredicate.create(parser.text()); + return new FieldExpression.FieldValue(parser.text()); case VALUE_BOOLEAN: - return FieldExpression.FieldPredicate.create(parser.booleanValue()); + return new FieldExpression.FieldValue(parser.booleanValue()); case VALUE_NUMBER: - return FieldExpression.FieldPredicate.create(parser.longValue()); + return new FieldExpression.FieldValue(parser.longValue()); case VALUE_NULL: - return FieldExpression.FieldPredicate.create(null); + return new FieldExpression.FieldValue(null); default: throw new ElasticsearchParseException("failed to parse rules expression. expected a field value but found [{}] instead", diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java index fc67e1d0a27..0e681b110ef 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java @@ -5,21 +5,19 @@ */ package org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl; -import org.elasticsearch.common.Numbers; +import org.apache.lucene.util.automaton.CharacterRunAutomaton; +import org.elasticsearch.common.Nullable; 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.regex.Regex; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.security.support.Automatons; import java.io.IOException; -import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Predicate; /** * An expression that evaluates to true if a field (map element) matches @@ -31,9 +29,9 @@ public final class FieldExpression implements RoleMapperExpression { public static final String NAME = "field"; private final String field; - private final List values; + private final List values; - public FieldExpression(String field, List values) { + public FieldExpression(String field, List values) { if (field == null || field.isEmpty()) { throw new IllegalArgumentException("null or empty field name (" + field + ")"); } @@ -45,7 +43,7 @@ public final class FieldExpression implements RoleMapperExpression { } public FieldExpression(StreamInput in) throws IOException { - this(in.readString(), in.readList(FieldPredicate::readFrom)); + this(in.readString(), in.readList(FieldValue::readFrom)); } @Override @@ -60,24 +58,15 @@ public final class FieldExpression implements RoleMapperExpression { } @Override - public boolean match(Map object) { - final Object fieldValue = object.get(field); - if (fieldValue instanceof Collection) { - return ((Collection) fieldValue).stream().anyMatch(this::matchValue); - } else { - return matchValue(fieldValue); - } - } - - private boolean matchValue(Object fieldValue) { - return values.stream().anyMatch(predicate -> predicate.test(fieldValue)); + public boolean match(ExpressionModel model) { + return model.test(field, values); } public String getField() { return field; } - public List> getValues() { + public List getValues() { return Collections.unmodifiableList(values); } @@ -107,7 +96,7 @@ public final class FieldExpression implements RoleMapperExpression { values.get(0).toXContent(builder, params); } else { builder.startArray(this.field); - for (FieldPredicate fp : values) { + for (FieldValue fp : values) { fp.toXContent(builder, params); } builder.endArray(); @@ -116,60 +105,40 @@ public final class FieldExpression implements RoleMapperExpression { return builder.endObject(); } - /** - * A special predicate for matching values in a {@link FieldExpression}. This interface - * exists to support the serialisation ({@link ToXContent}, {@link Writeable}) of field - * expressions. - */ - public static class FieldPredicate implements Predicate, ToXContent, Writeable { + public static class FieldValue implements ToXContent, Writeable { private final Object value; - private final Predicate predicate; + @Nullable + private final CharacterRunAutomaton automaton; - private FieldPredicate(Object value, Predicate predicate) { + public FieldValue(Object value) { this.value = value; - this.predicate = predicate; + this.automaton = buildAutomaton(value); } - @Override - public boolean test(Object o) { - return this.predicate.test(o); + private static CharacterRunAutomaton buildAutomaton(Object value) { + if (value instanceof String) { + final String str = (String) value; + if (Regex.isSimpleMatchPattern(str) || isLuceneRegex(str)) { + return new CharacterRunAutomaton(Automatons.patterns(str)); + } + } + return null; } - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) - throws IOException { - return builder.value(value); + private static boolean isLuceneRegex(String str) { + return str.length() > 1 && str.charAt(0) == '/' && str.charAt(str.length() - 1) == '/'; } - /** - * Create an appropriate predicate based on the type and value of the argument. - * The predicate is formed according to the following rules: - *
    - *
  • If value is null, then the predicate evaluates to - * true if-and-only-if the predicate-argument is - * null
  • - *
  • If value is a {@link Boolean}, then the predicate - * evaluates to true if-and-only-if the predicate-argument is - * an {@link Boolean#equals(Object) equal} Boolean
  • - *
  • If value is a {@link Number}, then the predicate - * evaluates to true if-and-only-if the predicate-argument is - * numerically equal to value. This class makes a best-effort to determine - * numeric equality across different implementations of Number, but the - * implementation can only be guaranteed for standard integral representations ( - * Long, Integer, etc)
  • - *
  • If value is a {@link String}, then it is treated as a - * {@link org.apache.lucene.util.automaton.Automaton Lucene automaton} pattern with - * {@link Automatons#predicate(String...) corresponding predicate}. - *
  • - *
- */ - public static FieldPredicate create(Object value) { - Predicate predicate = buildPredicate(value); - return new FieldPredicate(value, predicate); + public Object getValue() { + return value; } - public static FieldPredicate readFrom(StreamInput in) throws IOException { - return create(in.readGenericValue()); + public CharacterRunAutomaton getAutomaton() { + return automaton; + } + + public static FieldValue readFrom(StreamInput in) throws IOException { + return new FieldValue(in.readGenericValue()); } @Override @@ -177,41 +146,9 @@ public final class FieldExpression implements RoleMapperExpression { out.writeGenericValue(value); } - private static Predicate buildPredicate(Object object) { - if (object == null) { - return Objects::isNull; - } - if (object instanceof Boolean) { - return object::equals; - } - if (object instanceof Number) { - return (other) -> numberEquals((Number) object, other); - } - if (object instanceof String) { - final String str = (String) object; - if (str.isEmpty()) { - return obj -> String.valueOf(obj).isEmpty(); - } else { - final Predicate predicate = Automatons.predicate(str); - return obj -> predicate.test(String.valueOf(obj)); - } - } - throw new IllegalArgumentException("Unsupported value type " + object.getClass()); - } - - private static boolean numberEquals(Number left, Object other) { - if (left.equals(other)) { - return true; - } - if ((other instanceof Number) == false) { - return false; - } - Number right = (Number) other; - if (left instanceof Double || left instanceof Float - || right instanceof Double || right instanceof Float) { - return Double.compare(left.doubleValue(), right.doubleValue()) == 0; - } - return Numbers.toLongExact(left) == Numbers.toLongExact(right); + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + return builder.value(value); } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/RoleMapperExpression.java b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/RoleMapperExpression.java index 165d8b51421..89b80d9296e 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/RoleMapperExpression.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/RoleMapperExpression.java @@ -5,27 +5,27 @@ */ package org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl; -import java.util.Map; -import java.util.function.Predicate; - import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.xcontent.ToXContentObject; +import java.util.function.Predicate; + /** * Implementations of this interface represent an expression over a simple object that resolves to - * a boolean value. The "simple object" is implemented as a (flattened) {@link Map}. + * a boolean value. The "simple object" is provided as a {@link ExpressionModel}. */ public interface RoleMapperExpression extends ToXContentObject, NamedWriteable { /** * Determines whether this expression matches against the provided object. + * @param model */ - boolean match(Map object); + boolean match(ExpressionModel model); /** * Adapt this expression to a standard {@link Predicate} */ - default Predicate> asPredicate() { + default Predicate asPredicate() { return this::match; } @@ -34,7 +34,7 @@ public interface RoleMapperExpression extends ToXContentObject, NamedWriteable { * a fixed object. Its purpose is for cases where there is a {@link java.util.stream.Stream} of * expressions, that need to be filtered against a single map. */ - static Predicate predicate(Map map) { + static Predicate predicate(ExpressionModel map) { return expr -> expr.match(map); } diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionRequestTests.java new file mode 100644 index 00000000000..a8224d31d8d --- /dev/null +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionRequestTests.java @@ -0,0 +1,44 @@ +/* + * 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.core.ml.action; + +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.xpack.core.ml.action.CloseJobAction.Request; + +public class CloseJobActionRequestTests extends AbstractStreamableXContentTestCase { + + @Override + protected Request createTestInstance() { + Request request = new Request(randomAlphaOfLengthBetween(1, 20)); + if (randomBoolean()) { + request.setCloseTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); + } + if (randomBoolean()) { + request.setForce(randomBoolean()); + } + if (randomBoolean()) { + request.setAllowNoJobs(randomBoolean()); + } + return request; + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected Request createBlankInstance() { + return new Request(); + } + + @Override + protected Request doParseInstance(XContentParser parser) { + return Request.parseRequest(null, parser); + } +} diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionResponseTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionResponseTests.java index 93bac8f518b..c558a5cba0c 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/CloseJobActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.CloseJobAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteCalendarEventActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventActionRequestTests.java similarity index 86% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteCalendarEventActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventActionRequestTests.java index 99d441708ee..e6f35c76b78 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteCalendarEventActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteCalendarEventActionRequestTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.DeleteCalendarEventAction; import org.elasticsearch.xpack.core.ml.action.DeleteCalendarEventAction.Request; public class DeleteCalendarEventActionRequestTests extends AbstractStreamableTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteDatafeedRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedRequestTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteDatafeedRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedRequestTests.java index 23336d44c98..47cf3dc5eec 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteDatafeedRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDatafeedRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.DeleteDatafeedAction.Request; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteExpiredDataActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteExpiredDataActionResponseTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteExpiredDataActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteExpiredDataActionResponseTests.java index ec94e087483..34a03fb2e40 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteExpiredDataActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteExpiredDataActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteJobRequestTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteJobRequestTests.java index fa780a18b00..2482e9b5625 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteJobRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.DeleteJobAction; diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionRequestTests.java new file mode 100644 index 00000000000..cdcac09e073 --- /dev/null +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionRequestTests.java @@ -0,0 +1,64 @@ +/* + * 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.core.ml.action; + +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.xpack.core.ml.action.ForecastJobAction.Request; + +import static org.hamcrest.Matchers.equalTo; + +public class ForecastJobActionRequestTests extends AbstractStreamableXContentTestCase { + + @Override + protected Request doParseInstance(XContentParser parser) { + return Request.parseRequest(null, parser); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected Request createTestInstance() { + Request request = new Request(randomAlphaOfLengthBetween(1, 20)); + if (randomBoolean()) { + request.setDuration(TimeValue.timeValueSeconds(randomIntBetween(1, 1_000_000)).getStringRep()); + } + if (randomBoolean()) { + request.setExpiresIn(TimeValue.timeValueSeconds(randomIntBetween(0, 1_000_000)).getStringRep()); + } + return request; + } + + @Override + protected Request createBlankInstance() { + return new Request(); + } + + public void testSetDuration_GivenZero() { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setDuration("0")); + assertThat(e.getMessage(), equalTo("[duration] must be positive: [0ms]")); + } + + public void testSetDuration_GivenNegative() { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setDuration("-1s")); + assertThat(e.getMessage(), equalTo("[duration] must be positive: [-1]")); + } + + public void testSetExpiresIn_GivenZero() { + Request request = new Request(); + request.setExpiresIn("0"); + assertThat(request.getExpiresIn(), equalTo(TimeValue.ZERO)); + } + + public void testSetExpiresIn_GivenNegative() { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setExpiresIn("-1s")); + assertThat(e.getMessage(), equalTo("[expires_in] must be non-negative: [-1]")); + } +} diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionResponseTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionResponseTests.java index 123c40ddde2..b6c0759bceb 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ForecastJobActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.ForecastJobAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionRequestTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionRequestTests.java index 08f39238f05..4d1c1ca6084 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionResponseTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionResponseTests.java index 17f7d98378b..4fbb7a92496 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetBucketActionResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetBucketsAction; import org.elasticsearch.xpack.core.ml.action.GetBucketsAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsActionRequestTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsActionRequestTests.java index 95c0e5dc61b..eccfd933e5a 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarEventsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsActionRequestTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsActionRequestTests.java index 80ea99b571f..33584567ef4 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCalendarsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCalendarsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesRequestTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesRequestTests.java index 1ef80abefe8..7e53317478c 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesResponseTests.java similarity index 90% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesResponseTests.java index a149e728e0d..c77d000bb5f 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetCategoriesResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetCategoriesResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetCategoriesAction; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.results.CategoryDefinition; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionRequestTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionRequestTests.java index 1eed91c171d..37a539c0021 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.Writeable; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java index 676352ce9fd..26716695c6e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedStatsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionRequestTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionRequestTests.java index 14f0f882fcc..5fbdfd2e8cb 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.Writeable; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionResponseTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionResponseTests.java index 27ad882c258..f5eef5f1776 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetDatafeedsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionRequestTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionRequestTests.java index bb88839d6e2..234da4d9af5 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.GetFiltersAction; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionResponseTests.java similarity index 91% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionResponseTests.java index f60444a2fa2..c8465c87587 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetFiltersActionResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetFiltersAction; import org.elasticsearch.xpack.core.ml.action.GetFiltersAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.MlFilter; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionRequestTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionRequestTests.java index 742e94c7bfa..af0e1f856f8 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionRequestTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction; import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction.Request; import org.elasticsearch.xpack.core.ml.action.util.PageParams; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionResponseTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionResponseTests.java index c97c2441e93..daeda3ed82a 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetInfluencersActionResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction; import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.results.Influencer; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionRequestTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionRequestTests.java index 232908a6250..913618de38b 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.test.AbstractStreamableTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionResponseTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionResponseTests.java index 6a71f767905..ff979a8570a 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobStatsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobStatsActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -15,7 +15,7 @@ import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.JobState; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCountsTests; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import java.net.InetAddress; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionRequestTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionRequestTests.java index 8c746d2504c..326df1b2989 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.io.stream.Writeable; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionResponseTests.java similarity index 92% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionResponseTests.java index 719755c5ead..fee8a3a8e82 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetJobsActionResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetJobsAction; import org.elasticsearch.xpack.core.ml.action.GetJobsAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.Job; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionRequestTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionRequestTests.java index c6ee60aaf56..ffef7579601 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionRequestTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction; import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction.Request; import org.elasticsearch.xpack.core.ml.action.util.PageParams; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionResponseTests.java similarity index 86% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionResponseTests.java index 52072aa0aa2..0cf34c66f24 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetModelSnapshotsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetModelSnapshotsActionResponseTests.java @@ -3,14 +3,13 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction; import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshotTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotTests; import java.util.ArrayList; import java.util.List; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionRequestTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionRequestTests.java index d2a6bf22789..9799010204c 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionResponseTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionResponseTests.java index a93d0cc1517..8873b340c12 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetOverallBucketsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetOverallBucketsActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.GetOverallBucketsAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionRequestTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionRequestTests.java index fb394f3d060..f710fcc6c1a 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionRequestTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction.Request; import org.elasticsearch.xpack.core.ml.action.util.PageParams; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionResponseTests.java similarity index 92% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionResponseTests.java index 8ecdea0113e..78630e0cf0f 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetRecordsActionResponseTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction.Response; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/OpenJobActionRequestTests.java similarity index 92% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/OpenJobActionRequestTests.java index 71c227955e9..de85907a83e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/OpenJobActionRequestTests.java @@ -3,12 +3,11 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.OpenJobAction; import org.elasticsearch.xpack.core.ml.action.OpenJobAction.Request; public class OpenJobActionRequestTests extends AbstractStreamableXContentTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventActionRequestTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventActionRequestTests.java index 5b21908c402..ce6a64be6c5 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostCalendarEventActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.common.Strings; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionRequestTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionRequestTests.java index c1730162a98..ba4a3ff0647 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionRequestTests.java @@ -3,12 +3,11 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.PostDataAction; import org.elasticsearch.xpack.core.ml.job.config.DataDescription; import org.elasticsearch.xpack.core.ml.job.config.DataDescription.DataFormat; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionResponseTests.java similarity index 81% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionResponseTests.java index 22d604825c1..2f1a9d2e27d 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataActionResponseTests.java @@ -3,12 +3,11 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.PostDataAction; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCountsTests; public class PostDataActionResponseTests extends AbstractStreamableTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushRequestTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushRequestTests.java index bc91699037a..a4fd8c3c470 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.FlushJobAction.Request; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushResponseTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushResponseTests.java index 4b6755121c9..14f067e38ad 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PostDataFlushResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PostDataFlushResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.FlushJobAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedActionRequestTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedActionRequestTests.java index e8f2e99087e..b7828e4b976 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PreviewDatafeedActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.PreviewDatafeedAction.Request; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionRequestTests.java similarity index 87% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionRequestTests.java index da3d60e816e..7d111a31c9d 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionRequestTests.java @@ -3,13 +3,12 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; +import org.elasticsearch.xpack.core.ml.calendars.CalendarTests; import org.elasticsearch.xpack.core.ml.job.config.JobTests; -import org.elasticsearch.xpack.ml.calendars.CalendarTests; public class PutCalendarActionRequestTests extends AbstractStreamableXContentTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java similarity index 80% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java index 2c80dfb5600..941de884554 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutCalendarActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; -import org.elasticsearch.xpack.ml.calendars.CalendarTests; +import org.elasticsearch.xpack.core.ml.calendars.CalendarTests; public class PutCalendarActionResponseTests extends AbstractStreamableTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionRequestTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionRequestTests.java index bba1727f708..f01a360f909 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionResponseTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionResponseTests.java index 7855e0f39f2..e72ac3c726e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutDatafeedActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDatafeedActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutFilterActionRequestTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutFilterActionRequestTests.java index 03c6c55df8a..21845922470 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutFilterActionRequestTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.PutFilterAction; import org.elasticsearch.xpack.core.ml.action.PutFilterAction.Request; import org.elasticsearch.xpack.core.ml.job.config.MlFilter; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionRequestTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionRequestTests.java index 0d87f9ae86a..039954f1414 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentHelper; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionResponseTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionResponseTests.java index 5779f3e72fc..080fbb25e71 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutJobActionResponseTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.ml.action.PutJobAction.Response; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionRequestTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionRequestTests.java index d5038cc1af9..cd1b48cb31a 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionResponseTests.java similarity index 80% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionResponseTests.java index 14e9dcbb973..f24a8ccb9e1 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotActionResponseTests.java @@ -3,12 +3,11 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.RevertModelSnapshotAction; import org.elasticsearch.xpack.core.ml.action.RevertModelSnapshotAction.Response; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshotTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotTests; public class RevertModelSnapshotActionResponseTests extends AbstractStreamableTestCase { diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedActionRequestTests.java new file mode 100644 index 00000000000..1983b314b44 --- /dev/null +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedActionRequestTests.java @@ -0,0 +1,44 @@ +/* + * 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.core.ml.action; + +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction.Request; + +public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTestCase { + + @Override + protected Request createTestInstance() { + Request request = new Request(randomAlphaOfLengthBetween(1, 20)); + if (randomBoolean()) { + request.setStopTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); + } + if (randomBoolean()) { + request.setForce(randomBoolean()); + } + if (randomBoolean()) { + request.setAllowNoDatafeeds(randomBoolean()); + } + return request; + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected Request createBlankInstance() { + return new Request(); + } + + @Override + protected Request doParseInstance(XContentParser parser) { + return Request.parseRequest(null, parser); + } +} diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateCalendarJobActionResquestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobActionResquestTests.java similarity index 88% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateCalendarJobActionResquestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobActionResquestTests.java index 3e86353cf1d..efaf87c8681 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateCalendarJobActionResquestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateCalendarJobActionResquestTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.UpdateCalendarJobAction; public class UpdateCalendarJobActionResquestTests extends AbstractStreamableTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedActionRequestTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedActionRequestTests.java index 8a77e7499d5..af883ee9164 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateDatafeedActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateJobActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateJobActionRequestTests.java similarity index 91% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateJobActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateJobActionRequestTests.java index e129772d288..2db1571a39b 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateJobActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateJobActionRequestTests.java @@ -3,10 +3,9 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.UpdateJobAction; import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits; import org.elasticsearch.xpack.core.ml.job.config.JobUpdate; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionRequestTests.java similarity index 92% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionRequestTests.java index ef00ffb04b7..8ccb8bb2e19 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionRequestTests.java @@ -3,11 +3,10 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.action.UpdateModelSnapshotAction; import org.elasticsearch.xpack.core.ml.action.UpdateModelSnapshotAction.Request; public class UpdateModelSnapshotActionRequestTests diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionResponseTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionResponseTests.java similarity index 79% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionResponseTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionResponseTests.java index 15c63c5cf1e..a8694476ee2 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionResponseTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateModelSnapshotActionResponseTests.java @@ -3,12 +3,11 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.UpdateModelSnapshotAction; import org.elasticsearch.xpack.core.ml.action.UpdateModelSnapshotAction.Response; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshotTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotTests; public class UpdateModelSnapshotActionResponseTests extends AbstractStreamableTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateProcessActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessActionRequestTests.java similarity index 90% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateProcessActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessActionRequestTests.java index 0fca50b49bb..f7ee459bb19 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/UpdateProcessActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/UpdateProcessActionRequestTests.java @@ -3,13 +3,12 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.ml.action.UpdateProcessAction; import org.elasticsearch.xpack.core.ml.job.config.JobUpdate; import org.elasticsearch.xpack.core.ml.job.config.MlFilter; -import org.elasticsearch.xpack.ml.job.config.MlFilterTests; +import org.elasticsearch.xpack.core.ml.job.config.MlFilterTests; import org.elasticsearch.xpack.core.ml.job.config.ModelPlotConfig; import java.util.ArrayList; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorActionRequestTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorActionRequestTests.java index 8d880e5506b..d49908b1f1b 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateDetectorActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateJobConfigActionRequestTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigActionRequestTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateJobConfigActionRequestTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigActionRequestTests.java index 4f3b258ddae..63cfeb0d10e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ValidateJobConfigActionRequestTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/ValidateJobConfigActionRequestTests.java @@ -3,7 +3,7 @@ * 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.ml.action; +package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/PageParamsTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/PageParamsTests.java similarity index 97% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/PageParamsTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/PageParamsTests.java index 9e57c17d2ff..78a47fb068d 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/PageParamsTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/PageParamsTests.java @@ -3,12 +3,11 @@ * 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.ml.action.util; +package org.elasticsearch.xpack.core.ml.action.util; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.action.util.PageParams; import java.io.IOException; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/QueryPageTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/QueryPageTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/QueryPageTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/QueryPageTests.java index 944a600a4c0..8bded1972f2 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/util/QueryPageTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/util/QueryPageTests.java @@ -3,12 +3,11 @@ * 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.ml.action.util; +package org.elasticsearch.xpack.core.ml.action.util; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.test.AbstractWireSerializingTestCase; -import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.results.Influencer; import java.io.IOException; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/calendars/CalendarTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/calendars/CalendarTests.java similarity index 95% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/calendars/CalendarTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/calendars/CalendarTests.java index 4040db5fc9e..4260fbfd46e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/calendars/CalendarTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/calendars/CalendarTests.java @@ -3,12 +3,11 @@ * 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.ml.calendars; +package org.elasticsearch.xpack.core.ml.calendars; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.calendars.Calendar; import org.elasticsearch.xpack.core.ml.job.config.JobTests; import java.io.IOException; diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java index 9d42efd8eb2..8e326e3556b 100644 --- a/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java @@ -5,26 +5,16 @@ */ package org.elasticsearch.xpack.core.ml.integration; -import org.apache.http.HttpStatus; import org.apache.logging.log4j.Logger; -import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction; -import org.elasticsearch.client.Response; import org.elasticsearch.client.RestClient; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.ESRestTestCase; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; - - public class MlRestTestStateCleaner { private final Logger logger; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/MlFilterTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/MlFilterTests.java index 64b76b8c0eb..42102b540f9 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/MlFilterTests.java @@ -3,12 +3,11 @@ * 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.ml.job.config; +package org.elasticsearch.xpack.core.ml.job.config; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.job.config.MlFilter; import java.util.ArrayList; import java.util.Collections; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/ModelPlotConfigTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/ModelPlotConfigTests.java similarity index 91% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/ModelPlotConfigTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/ModelPlotConfigTests.java index 7b9a94eb009..aa54a174194 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/config/ModelPlotConfigTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/config/ModelPlotConfigTests.java @@ -3,12 +3,11 @@ * 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.ml.job.config; +package org.elasticsearch.xpack.core.ml.job.config; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.job.config.ModelPlotConfig; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/DataCountsTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/DataCountsTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/DataCountsTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/DataCountsTests.java index f1ab23a821a..091e6887701 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/DataCountsTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/DataCountsTests.java @@ -3,12 +3,11 @@ * 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.ml.job.process.autodetect.state; +package org.elasticsearch.xpack.core.ml.job.process.autodetect.state; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.joda.time.DateTime; import java.util.Date; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStatsTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSizeStatsTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStatsTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSizeStatsTests.java index 010c4590c87..fbe8e769085 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStatsTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSizeStatsTests.java @@ -3,7 +3,7 @@ * 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.ml.job.process.autodetect.state; +package org.elasticsearch.xpack.core.ml.job.process.autodetect.state; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.unit.TimeValue; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSnapshotTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshotTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSnapshotTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshotTests.java index 42bd034c6cb..91518f8eb28 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSnapshotTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshotTests.java @@ -3,15 +3,12 @@ * 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.ml.job.process.autodetect.state; +package org.elasticsearch.xpack.core.ml.job.process.autodetect.state; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles; import java.util.Arrays; import java.util.Date; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/QuantilesTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/QuantilesTests.java similarity index 94% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/QuantilesTests.java rename to plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/QuantilesTests.java index 935adf05498..93bddbed0ff 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/QuantilesTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/QuantilesTests.java @@ -3,13 +3,12 @@ * 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.ml.job.process.autodetect.state; +package org.elasticsearch.xpack.core.ml.job.process.autodetect.state; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles; import java.util.Date; diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModelPredicateTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModelPredicateTests.java new file mode 100644 index 00000000000..1754e2f8c02 --- /dev/null +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionModelPredicateTests.java @@ -0,0 +1,98 @@ +/* + * 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.core.security.authc.support.mapper.expressiondsl; + +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; + +import java.math.BigInteger; +import java.util.function.Predicate; + +import static org.hamcrest.Matchers.is; + +public class ExpressionModelPredicateTests extends ESTestCase { + + public void testNullValue() throws Exception { + final Predicate predicate = ExpressionModel.buildPredicate(null); + assertThat(predicate.test(new FieldValue(null)), is(true)); + assertThat(predicate.test(new FieldValue("")), is(false)); + assertThat(predicate.test(new FieldValue(1)), is(false)); + assertThat(predicate.test(new FieldValue(true)), is(false)); + } + + public void testBooleanValue() throws Exception { + final boolean matchValue = randomBoolean(); + final Predicate predicate = ExpressionModel.buildPredicate(matchValue); + assertThat(predicate.test(new FieldValue(matchValue)), is(true)); + Object value = !matchValue; + assertThat(predicate.test(new FieldValue(value)), is(false)); + assertThat(predicate.test(new FieldValue(String.valueOf(matchValue))), is(false)); + assertThat(predicate.test(new FieldValue("")), is(false)); + assertThat(predicate.test(new FieldValue(1)), is(false)); + assertThat(predicate.test(new FieldValue(null)), is(false)); + } + + public void testLongValue() throws Exception { + final int intValue = randomInt(); + final long longValue = intValue; + final Predicate predicate = ExpressionModel.buildPredicate(longValue); + + assertThat(predicate.test(new FieldValue(longValue)), is(true)); + assertThat(predicate.test(new FieldValue(intValue)), is(true)); + assertThat(predicate.test(new FieldValue(new BigInteger(String.valueOf(longValue)))), is(true)); + + assertThat(predicate.test(new FieldValue(longValue - 1)), is(false)); + assertThat(predicate.test(new FieldValue(intValue + 1)), is(false)); + assertThat(predicate.test(new FieldValue(String.valueOf(longValue))), is(false)); + assertThat(predicate.test(new FieldValue("")), is(false)); + assertThat(predicate.test(new FieldValue(true)), is(false)); + assertThat(predicate.test(new FieldValue(null)), is(false)); + } + + public void testSimpleAutomatonValue() throws Exception { + final String prefix = randomAlphaOfLength(3); + FieldValue fieldValue = new FieldValue(prefix + "*"); + + assertThat(ExpressionModel.buildPredicate(prefix).test(fieldValue), is(true)); + assertThat(ExpressionModel.buildPredicate(prefix + randomAlphaOfLengthBetween(1, 5)).test(fieldValue), is(true)); + + assertThat(ExpressionModel.buildPredicate("_" + prefix).test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(prefix.substring(0, 1)).test(fieldValue), is(false)); + + assertThat(ExpressionModel.buildPredicate("").test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(1).test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(true).test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(null).test(fieldValue), is(false)); + } + + public void testEmptyStringValue() throws Exception { + final Predicate predicate = ExpressionModel.buildPredicate(""); + + assertThat(predicate.test(new FieldValue("")), is(true)); + + assertThat(predicate.test(new FieldValue(randomAlphaOfLengthBetween(1, 3))), is(false)); + assertThat(predicate.test(new FieldValue(1)), is(false)); + assertThat(predicate.test(new FieldValue(true)), is(false)); + assertThat(predicate.test(new FieldValue(null)), is(false)); + } + + public void testRegexAutomatonValue() throws Exception { + final String substring = randomAlphaOfLength(5); + final FieldValue fieldValue = new FieldValue("/.*" + substring + ".*/"); + + assertThat(ExpressionModel.buildPredicate(substring).test(fieldValue), is(true)); + assertThat(ExpressionModel.buildPredicate(randomAlphaOfLengthBetween(2, 4) + substring + randomAlphaOfLengthBetween(1, 5)) + .test(fieldValue), is(true)); + + assertThat(ExpressionModel.buildPredicate(substring.substring(1, 3)).test(fieldValue), is(false)); + + assertThat(ExpressionModel.buildPredicate("").test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(1).test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(true).test(fieldValue), is(false)); + assertThat(ExpressionModel.buildPredicate(null).test(fieldValue), is(false)); + } + +} \ No newline at end of file diff --git a/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java index 8a4ccda9531..070f36b72e9 100644 --- a/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java +++ b/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/ExpressionParserTests.java @@ -17,18 +17,17 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.XPackClientPlugin; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Predicate; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.iterableWithSize; +import static org.hamcrest.Matchers.notNullValue; public class ExpressionParserTests extends ESTestCase { @@ -37,9 +36,11 @@ public class ExpressionParserTests extends ESTestCase { FieldExpression field = checkExpressionType(parse(json), FieldExpression.class); assertThat(field.getField(), equalTo("username")); assertThat(field.getValues(), iterableWithSize(1)); - final Predicate predicate = field.getValues().get(0); - assertThat(predicate.test("bob@shield.gov"), equalTo(true)); - assertThat(predicate.test("bob@example.net"), equalTo(false)); + final FieldValue value = field.getValues().get(0); + assertThat(value.getValue(), equalTo("*@shield.gov")); + assertThat(value.getAutomaton(), notNullValue()); + assertThat(value.getAutomaton().run("bob@shield.gov"), equalTo(true)); + assertThat(value.getAutomaton().run("bob@example.net"), equalTo(false)); assertThat(json(field), equalTo(json.replaceAll("\\s", ""))); } @@ -65,9 +66,11 @@ public class ExpressionParserTests extends ESTestCase { FieldExpression.class); assertThat(fieldShield.getField(), equalTo("username")); assertThat(fieldShield.getValues(), iterableWithSize(1)); - final Predicate predicateShield = fieldShield.getValues().get(0); - assertThat(predicateShield.test("fury@shield.gov"), equalTo(true)); - assertThat(predicateShield.test("fury@shield.net"), equalTo(false)); + final FieldValue valueShield = fieldShield.getValues().get(0); + assertThat(valueShield.getValue(), equalTo("*@shield.gov")); + assertThat(valueShield.getAutomaton(), notNullValue()); + assertThat(valueShield.getAutomaton().run("fury@shield.gov"), equalTo(true)); + assertThat(valueShield.getAutomaton().run("fury@shield.net"), equalTo(false)); final AllExpression all = checkExpressionType(any.getElements().get(1), AllExpression.class); @@ -77,19 +80,17 @@ public class ExpressionParserTests extends ESTestCase { FieldExpression.class); assertThat(fieldAvengers.getField(), equalTo("username")); assertThat(fieldAvengers.getValues(), iterableWithSize(1)); - final Predicate predicateAvengers = fieldAvengers.getValues().get(0); - assertThat(predicateAvengers.test("stark@avengers.net"), equalTo(true)); - assertThat(predicateAvengers.test("romanov@avengers.org"), equalTo(true)); - assertThat(predicateAvengers.test("fury@shield.gov"), equalTo(false)); + final FieldValue valueAvengers = fieldAvengers.getValues().get(0); + assertThat(valueAvengers.getAutomaton().run("stark@avengers.net"), equalTo(true)); + assertThat(valueAvengers.getAutomaton().run("romanov@avengers.org"), equalTo(true)); + assertThat(valueAvengers.getAutomaton().run("fury@shield.gov"), equalTo(false)); final FieldExpression fieldGroupsAdmin = checkExpressionType(all.getElements().get(1), FieldExpression.class); assertThat(fieldGroupsAdmin.getField(), equalTo("groups")); assertThat(fieldGroupsAdmin.getValues(), iterableWithSize(2)); - assertThat(fieldGroupsAdmin.getValues().get(0).test("admin"), equalTo(true)); - assertThat(fieldGroupsAdmin.getValues().get(0).test("foo"), equalTo(false)); - assertThat(fieldGroupsAdmin.getValues().get(1).test("operators"), equalTo(true)); - assertThat(fieldGroupsAdmin.getValues().get(1).test("foo"), equalTo(false)); + assertThat(fieldGroupsAdmin.getValues().get(0).getValue(), equalTo("admin")); + assertThat(fieldGroupsAdmin.getValues().get(1).getValue(), equalTo("operators")); final ExceptExpression except = checkExpressionType(all.getElements().get(2), ExceptExpression.class); @@ -97,26 +98,25 @@ public class ExpressionParserTests extends ESTestCase { FieldExpression.class); assertThat(fieldDisavowed.getField(), equalTo("groups")); assertThat(fieldDisavowed.getValues(), iterableWithSize(1)); - assertThat(fieldDisavowed.getValues().get(0).test("disavowed"), equalTo(true)); - assertThat(fieldDisavowed.getValues().get(0).test("_disavowed_"), equalTo(false)); + assertThat(fieldDisavowed.getValues().get(0).getValue(), equalTo("disavowed")); - Map hawkeye = new HashMap<>(); - hawkeye.put("username", "hawkeye@avengers.org"); - hawkeye.put("groups", Arrays.asList("operators")); + ExpressionModel hawkeye = new ExpressionModel(); + hawkeye.defineField("username", "hawkeye@avengers.org"); + hawkeye.defineField("groups", Arrays.asList("operators")); assertThat(expr.match(hawkeye), equalTo(true)); - Map captain = new HashMap<>(); - captain.put("username", "america@avengers.net"); + ExpressionModel captain = new ExpressionModel(); + captain.defineField("username", "america@avengers.net"); assertThat(expr.match(captain), equalTo(false)); - Map warmachine = new HashMap<>(); - warmachine.put("username", "warmachine@avengers.net"); - warmachine.put("groups", Arrays.asList("admin", "disavowed")); + ExpressionModel warmachine = new ExpressionModel(); + warmachine.defineField("username", "warmachine@avengers.net"); + warmachine.defineField("groups", Arrays.asList("admin", "disavowed")); assertThat(expr.match(warmachine), equalTo(false)); - Map fury = new HashMap<>(); - fury.put("username", "fury@shield.gov"); - fury.put("groups", Arrays.asList("classified", "directors")); + ExpressionModel fury = new ExpressionModel(); + fury.defineField("username", "fury@shield.gov"); + fury.defineField("groups", Arrays.asList("classified", "directors")); assertThat(expr.asPredicate().test(fury), equalTo(true)); assertThat(json(expr), equalTo(json.replaceAll("\\s", ""))); @@ -161,4 +161,4 @@ public class ExpressionParserTests extends ESTestCase { } return writer.toString(); } -} \ No newline at end of file +} diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetBucketsAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetBucketsAction.java index 6ef07232ad0..45e090fc583 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetBucketsAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetBucketsAction.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.action.GetBucketsAction; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder; import org.elasticsearch.xpack.ml.job.JobManager; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java index 7e3593a3f7d..d59febf12cd 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.core.ml.action.GetCalendarsAction; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; import org.elasticsearch.xpack.core.ml.job.config.Job; -import org.elasticsearch.xpack.core.ml.job.persistence.ScheduledEventsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarsAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarsAction.java index 319a5e43b3b..46cfac5519d 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarsAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarsAction.java @@ -17,7 +17,7 @@ import org.elasticsearch.xpack.core.ml.action.GetCalendarsAction; import org.elasticsearch.xpack.core.ml.action.util.PageParams; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.calendars.Calendar; -import org.elasticsearch.xpack.core.ml.job.persistence.CalendarQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.CalendarQueryBuilder; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; import java.util.Collections; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetInfluencersAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetInfluencersAction.java index 4a54469a87a..6b46d3ec033 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetInfluencersAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetInfluencersAction.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.action.GetInfluencersAction; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder; import org.elasticsearch.xpack.ml.job.JobManager; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java index 989d74038b8..8d4c6dc83ce 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetOverallBucketsAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.xpack.core.ml.action.GetOverallBucketsAction; import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder; import org.elasticsearch.xpack.core.ml.job.results.Bucket; import org.elasticsearch.xpack.core.ml.job.results.OverallBucket; import org.elasticsearch.xpack.core.ml.job.results.Result; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetRecordsAction.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetRecordsAction.java index b017a34a495..879b8c5bba0 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetRecordsAction.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetRecordsAction.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; -import org.elasticsearch.xpack.core.ml.job.persistence.RecordsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.RecordsQueryBuilder; import org.elasticsearch.xpack.ml.job.JobManager; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java index 0bf52a98e11..ecc6573e7bb 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedJobBuilder.java @@ -13,7 +13,7 @@ import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.job.config.DataDescription; import org.elasticsearch.xpack.core.ml.job.config.Job; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.elasticsearch.xpack.core.ml.job.results.Bucket; import org.elasticsearch.xpack.core.ml.job.results.Result; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java index 2bba7cfc17f..6501c5532b0 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java @@ -18,7 +18,11 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.action.UpdateProcessAction; import org.elasticsearch.xpack.ml.job.process.autodetect.UpdateParams; +import org.elasticsearch.xpack.ml.utils.VolatileCursorIterator; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.concurrent.LinkedBlockingQueue; import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; @@ -81,17 +85,20 @@ public class UpdateJobProcessNotifier extends AbstractComponent implements Local } private void processNextUpdate() { + List updates = new ArrayList<>(orderedJobUpdates.size()); try { - UpdateParams updateParams = orderedJobUpdates.poll(); - if (updateParams != null) { - executeRemoteJob(updateParams); - } + orderedJobUpdates.drainTo(updates); + executeProcessUpdates(new VolatileCursorIterator<>(updates)); } catch (Exception e) { - logger.error("Unable while processing next job update", e); + logger.error("Error while processing next job update", e); } } - void executeRemoteJob(UpdateParams update) { + void executeProcessUpdates(Iterator updatesIterator) { + if (updatesIterator.hasNext() == false) { + return; + } + UpdateParams update = updatesIterator.next(); Request request = new Request(update.getJobId(), update.getModelPlotConfig(), update.getDetectorUpdates(), update.getFilter(), update.isUpdateScheduledEvents()); @@ -104,6 +111,7 @@ public class UpdateJobProcessNotifier extends AbstractComponent implements Local } else { logger.error("Failed to update remote job [{}]", update.getJobId()); } + executeProcessUpdates(updatesIterator); } @Override @@ -116,7 +124,9 @@ public class UpdateJobProcessNotifier extends AbstractComponent implements Local } else { logger.error("Failed to update remote job [" + update.getJobId() + "]", e); } + executeProcessUpdates(updatesIterator); } }); } + } diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedResultsIterator.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedResultsIterator.java index c02dfd39574..b5f45bc35c1 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedResultsIterator.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BatchedResultsIterator.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; -import org.elasticsearch.xpack.core.ml.job.persistence.ResultsFilterBuilder; import org.elasticsearch.xpack.core.ml.job.results.Result; public abstract class BatchedResultsIterator extends BatchedDocumentsIterator> { diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/BucketsQueryBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BucketsQueryBuilder.java similarity index 98% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/BucketsQueryBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BucketsQueryBuilder.java index 2f5ee451ee6..252723eae5f 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/BucketsQueryBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/BucketsQueryBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/CalendarQueryBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/CalendarQueryBuilder.java similarity index 97% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/CalendarQueryBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/CalendarQueryBuilder.java index d53a0f71eeb..2674d29e49d 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/CalendarQueryBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/CalendarQueryBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/InfluencersQueryBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilder.java similarity index 98% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/InfluencersQueryBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilder.java index 984c1a6eb18..9cc7afc0418 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/InfluencersQueryBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.xpack.core.ml.job.results.Influencer; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java index 879c19e36b4..1185ecb582c 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java @@ -80,14 +80,9 @@ import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.MlFilter; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.CalendarQueryBuilder; import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery; -import org.elasticsearch.xpack.core.ml.job.persistence.RecordsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.ResultsFilterBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.ScheduledEventsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.CategorizerState; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/RecordsQueryBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/RecordsQueryBuilder.java similarity index 97% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/RecordsQueryBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/RecordsQueryBuilder.java index 8fb86689ecf..b335780a771 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/RecordsQueryBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/RecordsQueryBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -13,6 +13,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; +import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings; import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; import org.elasticsearch.xpack.core.ml.job.results.Result; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ResultsFilterBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilder.java similarity index 98% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ResultsFilterBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilder.java index c31e82dd0b6..745793d9722 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ResultsFilterBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.common.Strings; import org.elasticsearch.index.query.BoolQueryBuilder; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ScheduledEventsQueryBuilder.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java similarity index 98% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ScheduledEventsQueryBuilder.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java index a472365f77d..b065ec93834 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ScheduledEventsQueryBuilder.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java @@ -3,7 +3,7 @@ * 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.core.ml.job.persistence; +package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java index f065849af6b..c95e3a5f6e3 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java @@ -6,7 +6,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect; import org.elasticsearch.xpack.core.ml.job.config.Job; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import java.util.concurrent.ExecutorService; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java index 7d662820949..8d1ea193f33 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java @@ -29,9 +29,9 @@ import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.JobState; import org.elasticsearch.xpack.core.ml.job.config.JobTaskStatus; -import org.elasticsearch.xpack.core.ml.job.persistence.ScheduledEventsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder; import org.elasticsearch.xpack.core.ml.job.process.autodetect.output.FlushAcknowledgement; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; diff --git a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java index 5af8e721e1e..e2c0db068e7 100644 --- a/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java @@ -19,7 +19,7 @@ import org.elasticsearch.xpack.ml.job.process.ProcessCtrl; import org.elasticsearch.xpack.ml.job.process.ProcessPipes; import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutodetectResultsParser; import org.elasticsearch.xpack.ml.job.process.autodetect.output.StateProcessor; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import org.elasticsearch.xpack.ml.utils.NamedPipeHelper; diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/params/AutodetectParams.java b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java similarity index 98% rename from plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/params/AutodetectParams.java rename to plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java index 957bc6707be..9421a3662e1 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/params/AutodetectParams.java +++ b/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java @@ -3,7 +3,7 @@ * 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.core.ml.job.process.autodetect.params; +package org.elasticsearch.xpack.ml.job.process.autodetect.params; import org.elasticsearch.common.Nullable; import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java index b76b8fb439a..87b0b0bec34 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.ml.notifications.Auditor; import java.net.InetAddress; import java.util.Collections; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java index ea10b21e94a..84b5aefcd29 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlMetadataTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.xpack.core.ml.job.config.JobState; import org.elasticsearch.xpack.core.ml.job.config.JobTaskStatus; import org.elasticsearch.xpack.core.ml.job.config.JobTests; import org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData; +import org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests; import java.util.Collections; import java.util.Date; @@ -37,7 +38,7 @@ import java.util.Map; import static org.elasticsearch.xpack.core.ml.job.config.JobTests.buildJobBuilder; import static org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData.INITIAL_ASSIGNMENT; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests.createDatafeedConfig; import static org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests.createDatafeedJob; import static org.hamcrest.Matchers.contains; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionRequestTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java similarity index 93% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionRequestTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java index 517ef47f24a..92721c1e7a1 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/CloseJobActionRequestTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportCloseJobActionTests.java @@ -16,11 +16,9 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.MLMetadataField; @@ -43,41 +41,11 @@ import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class CloseJobActionRequestTests extends AbstractStreamableXContentTestCase { - - @Override - protected Request createTestInstance() { - Request request = new Request(randomAlphaOfLengthBetween(1, 20)); - if (randomBoolean()) { - request.setCloseTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); - } - if (randomBoolean()) { - request.setForce(randomBoolean()); - } - if (randomBoolean()) { - request.setAllowNoJobs(randomBoolean()); - } - return request; - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } - - @Override - protected Request createBlankInstance() { - return new Request(); - } - - @Override - protected Request doParseInstance(XContentParser parser) { - return Request.parseRequest(null, parser); - } +public class TransportCloseJobActionTests extends ESTestCase { public void testValidate_datafeedIsStarted() { MlMetadata.Builder mlBuilder = new MlMetadata.Builder(); diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobActionTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobActionTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobActionTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobActionTests.java index 7c9d3e38e66..1bf40ac881e 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/DeleteJobActionTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportDeleteJobActionTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase; import java.util.Date; -public class DeleteJobActionTests extends ESTestCase { +public class TransportDeleteJobActionTests extends ESTestCase { public void testJobIsDeletedFromState() { MlMetadata mlMetadata = MlMetadata.EMPTY_METADATA; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionRequestTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportForecastJobActionRequestTests.java similarity index 60% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionRequestTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportForecastJobActionRequestTests.java index 6da7daaf39c..be115af6bcd 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/ForecastJobActionRequestTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportForecastJobActionRequestTests.java @@ -8,10 +8,8 @@ package org.elasticsearch.xpack.ml.action; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.Version; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.action.ForecastJobAction; -import org.elasticsearch.xpack.core.ml.action.ForecastJobAction.Request; import org.elasticsearch.xpack.core.ml.job.config.AnalysisConfig; import org.elasticsearch.xpack.core.ml.job.config.DataDescription; import org.elasticsearch.xpack.core.ml.job.config.Detector; @@ -20,57 +18,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Job; import java.util.Collections; import java.util.Date; -import static org.hamcrest.Matchers.equalTo; - -public class ForecastJobActionRequestTests extends AbstractStreamableXContentTestCase { - - @Override - protected Request doParseInstance(XContentParser parser) { - return Request.parseRequest(null, parser); - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } - - @Override - protected Request createTestInstance() { - Request request = new Request(randomAlphaOfLengthBetween(1, 20)); - if (randomBoolean()) { - request.setDuration(TimeValue.timeValueSeconds(randomIntBetween(1, 1_000_000)).getStringRep()); - } - if (randomBoolean()) { - request.setExpiresIn(TimeValue.timeValueSeconds(randomIntBetween(0, 1_000_000)).getStringRep()); - } - return request; - } - - @Override - protected Request createBlankInstance() { - return new Request(); - } - - public void testSetDuration_GivenZero() { - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setDuration("0")); - assertThat(e.getMessage(), equalTo("[duration] must be positive: [0ms]")); - } - - public void testSetDuration_GivenNegative() { - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setDuration("-1s")); - assertThat(e.getMessage(), equalTo("[duration] must be positive: [-1]")); - } - - public void testSetExpiresIn_GivenZero() { - Request request = new Request(); - request.setExpiresIn("0"); - assertThat(request.getExpiresIn(), equalTo(TimeValue.ZERO)); - } - - public void testSetExpiresIn_GivenNegative() { - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new Request().setExpiresIn("-1s")); - assertThat(e.getMessage(), equalTo("[expires_in] must be non-negative: [-1]")); - } +public class TransportForecastJobActionRequestTests extends ESTestCase { public void testValidate_jobVersionCannonBeBefore61() { Job.Builder jobBuilder = createTestJob("forecast-it-test-job-version"); diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsStatsActionTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsActionTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsStatsActionTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsActionTests.java index 115ec09d986..40bc82c6048 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/GetJobsStatsActionTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsActionTests.java @@ -23,7 +23,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class GetJobsStatsActionTests extends ESTestCase { +public class TransportGetJobsStatsActionTests extends ESTestCase { public void testDetermineJobIds() { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java similarity index 99% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java index a8b280ec1fe..d11783c4789 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/OpenJobActionTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportOpenJobActionTests.java @@ -61,7 +61,7 @@ import static org.hamcrest.Matchers.containsString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class OpenJobActionTests extends ESTestCase { +public class TransportOpenJobActionTests extends ESTestCase { public void testValidate_jobMissing() { MlMetadata.Builder mlBuilder = new MlMetadata.Builder(); diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportPreviewDatafeedActionTests.java similarity index 98% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportPreviewDatafeedActionTests.java index 39949c52d4f..c63efb9a909 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/PreviewDatafeedActionTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportPreviewDatafeedActionTests.java @@ -29,7 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class PreviewDatafeedActionTests extends ESTestCase { +public class TransportPreviewDatafeedActionTests extends ESTestCase { private DataExtractor dataExtractor; private ActionListener actionListener; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java similarity index 96% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java index 656c0da89ce..cb5d2470aaa 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedActionTests.java @@ -22,10 +22,10 @@ import java.util.Collections; import java.util.Date; import static org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData.INITIAL_ASSIGNMENT; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.hamcrest.Matchers.equalTo; -public class StartDatafeedActionTests extends ESTestCase { +public class TransportStartDatafeedActionTests extends ESTestCase { public void testValidate_GivenDatafeedIsMissing() { Job job = DatafeedManagerTests.createDatafeedJob().build(new Date()); diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStopDatafeedActionTests.java similarity index 81% rename from plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java rename to plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStopDatafeedActionTests.java index c6eadcbcbec..519336c9f09 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStopDatafeedActionTests.java @@ -6,20 +6,15 @@ package org.elasticsearch.xpack.ml.action; import org.elasticsearch.ResourceNotFoundException; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.MLMetadataField; import org.elasticsearch.xpack.core.ml.MlMetadata; -import org.elasticsearch.xpack.core.ml.MlMetadata.Builder; import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction; import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction; -import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction.Request; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData; -import org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData.Assignment; import org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase; import java.util.ArrayList; @@ -31,42 +26,11 @@ import static org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests.createDat import static org.elasticsearch.xpack.ml.datafeed.DatafeedManagerTests.createDatafeedJob; import static org.hamcrest.Matchers.equalTo; -public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTestCase { - - @Override - protected Request createTestInstance() { - Request request = new Request(randomAlphaOfLengthBetween(1, 20)); - if (randomBoolean()) { - request.setStopTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); - } - if (randomBoolean()) { - request.setForce(randomBoolean()); - } - if (randomBoolean()) { - request.setAllowNoDatafeeds(randomBoolean()); - } - return request; - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } - - @Override - protected Request createBlankInstance() { - return new Request(); - } - - @Override - protected Request doParseInstance(XContentParser parser) { - return Request.parseRequest(null, parser); - } - +public class TransportStopDatafeedActionTests extends ESTestCase { public void testValidate() { PersistentTasksCustomMetaData.Builder tasksBuilder = PersistentTasksCustomMetaData.builder(); tasksBuilder.addTask(MLMetadataField.datafeedTaskId("foo"), StartDatafeedAction.TASK_NAME, - new StartDatafeedAction.DatafeedParams("foo", 0L), new Assignment("node_id", "")); + new StartDatafeedAction.DatafeedParams("foo", 0L), new PersistentTasksCustomMetaData.Assignment("node_id", "")); tasksBuilder.updateTaskStatus(MLMetadataField.datafeedTaskId("foo"), DatafeedState.STARTED); tasksBuilder.build(); @@ -84,7 +48,7 @@ public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTe } public void testResolveDataFeedIds_GivenDatafeedId() { - Builder mlMetadataBuilder = new MlMetadata.Builder(); + MlMetadata.Builder mlMetadataBuilder = new MlMetadata.Builder(); PersistentTasksCustomMetaData.Builder tasksBuilder = PersistentTasksCustomMetaData.builder(); addTask("datafeed_1", 0L, "node-1", DatafeedState.STARTED, tasksBuilder); @@ -116,7 +80,7 @@ public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTe } public void testResolveDataFeedIds_GivenAll() { - Builder mlMetadataBuilder = new MlMetadata.Builder(); + MlMetadata.Builder mlMetadataBuilder = new MlMetadata.Builder(); PersistentTasksCustomMetaData.Builder tasksBuilder = PersistentTasksCustomMetaData.builder(); addTask("datafeed_1", 0L, "node-1", DatafeedState.STARTED, tasksBuilder); @@ -155,8 +119,8 @@ public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTe public static void addTask(String datafeedId, long startTime, String nodeId, DatafeedState state, PersistentTasksCustomMetaData.Builder taskBuilder) { taskBuilder.addTask(MLMetadataField.datafeedTaskId(datafeedId), StartDatafeedAction.TASK_NAME, - new StartDatafeedAction.DatafeedParams(datafeedId, startTime), new Assignment(nodeId, "test assignment")); + new StartDatafeedAction.DatafeedParams(datafeedId, startTime), + new PersistentTasksCustomMetaData.Assignment(nodeId, "test assignment")); taskBuilder.updateTaskStatus(MLMetadataField.datafeedTaskId(datafeedId), state); } - } diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java index 59c7236d28d..2f20fbdbc39 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManagerTests.java @@ -38,7 +38,7 @@ import org.elasticsearch.xpack.core.ml.notifications.AuditorField; import org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData; import org.elasticsearch.xpack.core.persistent.PersistentTasksCustomMetaData.PersistentTask; import org.elasticsearch.xpack.ml.MachineLearning; -import org.elasticsearch.xpack.ml.action.StartDatafeedActionTests; +import org.elasticsearch.xpack.ml.action.TransportStartDatafeedActionTests; import org.elasticsearch.xpack.ml.action.TransportStartDatafeedAction.DatafeedTask; import org.elasticsearch.xpack.ml.job.persistence.MockClientBuilder; import org.elasticsearch.xpack.ml.notifications.Auditor; @@ -52,7 +52,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.function.Consumer; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.mockito.Matchers.any; @@ -199,7 +199,7 @@ public class DatafeedManagerTests extends ESTestCase { Consumer handler = mockConsumer(); StartDatafeedAction.DatafeedParams params = new StartDatafeedAction.DatafeedParams("datafeed_id", 0L); - DatafeedTask task = StartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, + DatafeedTask task = TransportStartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, params, datafeedManager); task = spyDatafeedTask(task); datafeedManager.run(task, handler); @@ -218,7 +218,7 @@ public class DatafeedManagerTests extends ESTestCase { Consumer handler = mockConsumer(); StartDatafeedAction.DatafeedParams params = new StartDatafeedAction.DatafeedParams("datafeed_id", 0L); - DatafeedTask task = StartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, + DatafeedTask task = TransportStartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, params, datafeedManager); task = spyDatafeedTask(task); datafeedManager.run(task, handler); @@ -234,7 +234,7 @@ public class DatafeedManagerTests extends ESTestCase { Consumer handler = mockConsumer(); boolean cancelled = randomBoolean(); StartDatafeedAction.DatafeedParams params = new StartDatafeedAction.DatafeedParams("datafeed_id", 0L); - DatafeedTask task = StartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, + DatafeedTask task = TransportStartDatafeedActionTests.createDatafeedTask(1, "type", "action", null, params, datafeedManager); task = spyDatafeedTask(task); datafeedManager.run(task, handler); diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java index bcb67fed6bd..eae925d1503 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java @@ -41,7 +41,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.createDatafeed; import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.createScheduledJob; import static org.hamcrest.Matchers.containsString; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java index fe47e01447b..c75c5a68f80 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java @@ -22,9 +22,9 @@ import org.elasticsearch.xpack.core.ml.job.config.DataDescription; import org.elasticsearch.xpack.core.ml.job.config.Detector; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.config.JobTests; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.RecordsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.BucketsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.RecordsQueryBuilder; import org.elasticsearch.xpack.core.ml.job.process.autodetect.output.FlushAcknowledgement; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java index eae38e6b5aa..751b490b358 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java @@ -39,9 +39,9 @@ import org.elasticsearch.xpack.core.ml.job.config.MlFilter; import org.elasticsearch.xpack.core.ml.job.config.RuleAction; import org.elasticsearch.xpack.core.ml.job.config.RuleCondition; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; -import org.elasticsearch.xpack.core.ml.job.persistence.CalendarQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.ScheduledEventsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.persistence.CalendarQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; @@ -52,7 +52,7 @@ import org.elasticsearch.xpack.ml.MlSingleNodeTestCase; import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCountsTests; import org.junit.Before; import java.io.IOException; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java index f967cddadab..ae40db716ea 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobManagerTests.java @@ -49,7 +49,7 @@ import java.util.Date; import java.util.List; import static org.elasticsearch.xpack.core.ml.job.config.JobTests.buildJobBuilder; -import static org.elasticsearch.xpack.ml.action.OpenJobActionTests.addJobTask; +import static org.elasticsearch.xpack.ml.action.TransportOpenJobActionTests.addJobTask; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilderTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilderTests.java index af1265cdf7d..18b2cf5db60 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilderTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/InfluencersQueryBuilderTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder; import org.elasticsearch.xpack.core.ml.job.results.Influencer; public class InfluencersQueryBuilderTests extends ESTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java index 251da796b12..cc9acdd0a61 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java @@ -44,10 +44,7 @@ import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields; -import org.elasticsearch.xpack.core.ml.job.persistence.BucketsQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder; -import org.elasticsearch.xpack.core.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery; -import org.elasticsearch.xpack.core.ml.job.persistence.RecordsQueryBuilder; +import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; import org.elasticsearch.xpack.core.ml.job.results.Bucket; diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilderTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilderTests.java index 75db898e856..9e6d6e983dc 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilderTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/ResultsFilterBuilderTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.ml.job.persistence; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.ml.job.persistence.ResultsFilterBuilder; import org.elasticsearch.xpack.core.ml.job.results.Result; public class ResultsFilterBuilderTests extends ESTestCase { diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java index 6b5582a2b6c..c182d756aa0 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.xpack.core.ml.job.config.JobTaskStatus; import org.elasticsearch.xpack.core.ml.job.config.JobUpdate; import org.elasticsearch.xpack.core.ml.job.config.MlFilter; import org.elasticsearch.xpack.core.ml.job.config.ModelPlotConfig; -import org.elasticsearch.xpack.core.ml.job.process.autodetect.params.AutodetectParams; +import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot; @@ -352,7 +352,12 @@ public class AutodetectProcessManagerTests extends ESTestCase { // Also close the job in the current thread, so that we have two simultaneous close requests manager.closeJob(jobTask, false, "in main test thread"); - closeThread.join(500); + // The 10 second timeout here is usually far in excess of what is required. In the vast + // majority of cases the other thread will exit within a few milliseconds. However, it + // has been observed that on some VMs the test can fail because the VM stalls at the + // wrong moment. A 10 second timeout is on a par with the length of time assertBusy() + // would wait under these circumstances. + closeThread.join(10000); assertFalse(closeThread.isAlive()); // Only one of the threads should have called AutodetectCommunicator.close() diff --git a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/AutodetectResultTests.java b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/AutodetectResultTests.java index a685820430f..bf9a6f0a99f 100644 --- a/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/AutodetectResultTests.java +++ b/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/results/AutodetectResultTests.java @@ -18,9 +18,9 @@ import org.elasticsearch.xpack.core.ml.job.results.Forecast; import org.elasticsearch.xpack.core.ml.job.results.ForecastRequestStats; import org.elasticsearch.xpack.core.ml.job.results.Influencer; import org.elasticsearch.xpack.core.ml.job.results.ModelPlot; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshotTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotTests; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles; -import org.elasticsearch.xpack.ml.job.process.autodetect.state.QuantilesTests; +import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.QuantilesTests; import java.util.ArrayList; import java.util.Date; diff --git a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/UserRoleMapper.java b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/UserRoleMapper.java index 95dc26417e6..8c5e27ec2a9 100644 --- a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/UserRoleMapper.java +++ b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/UserRoleMapper.java @@ -5,17 +5,23 @@ */ package org.elasticsearch.xpack.security.authc.support; +import com.unboundid.ldap.sdk.DN; +import com.unboundid.ldap.sdk.LDAPException; +import org.apache.lucene.util.automaton.CharacterRunAutomaton; import org.elasticsearch.action.ActionListener; import org.elasticsearch.common.Nullable; import org.elasticsearch.xpack.core.security.authc.RealmConfig; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.ExpressionModel; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression; import org.elasticsearch.xpack.core.security.authz.permission.Role; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.function.Predicate; /** * Where a realm users an authentication method that does not have in-built support for X-Pack @@ -60,20 +66,24 @@ public interface UserRoleMapper { } /** - * Formats the user data as a Map. - * The map is not nested - all values are simple Java values, but keys may + * Formats the user data as a {@link ExpressionModel}. + * The model does not have nested values - all values are simple Java values, but keys may * contain .. - * For example, the {@link #metadata} values will be stored in the map with a key of + * For example, the {@link #metadata} values will be stored in the model with a key of * "metadata.KEY" where KEY is the key from the metadata object. */ - public Map asMap() { - final Map map = new HashMap<>(); - map.put("username", username); - map.put("dn", dn); - map.put("groups", groups); - metadata.keySet().forEach(k -> map.put("metadata." + k, metadata.get(k))); - map.put("realm.name", realm.name()); - return map; + public ExpressionModel asModel() { + final ExpressionModel model = new ExpressionModel(); + model.defineField("username", username); + model.defineField("dn", dn, new DistinguishedNamePredicate(dn)); + model.defineField("groups", groups, groups.stream() + .>map(DistinguishedNamePredicate::new) + .reduce((a, b) -> a.or(b)) + .orElse(fieldValue -> false) + ); + metadata.keySet().forEach(k -> model.defineField("metadata." + k, metadata.get(k))); + model.defineField("realm.name", realm.name()); + return model; } @Override @@ -126,4 +136,98 @@ public interface UserRoleMapper { return realm; } } + + /** + * A specialised predicate for fields that might be a DistinguishedName (e.g "dn" or "groups"). + * + * The X500 specs define how to compare DistinguishedNames (but we mostly rely on {@link DN#equals(Object)}), + * which means "CN=me,DC=example,DC=com" should be equal to "cn=me, dc=Example, dc=COM" (and other variations). + + * The {@link FieldExpression} class doesn't know about special rules for special data types, but the + * {@link ExpressionModel} class can take a custom {@code Predicate} that tests whether the data in the model + * matches the {@link FieldExpression.FieldValue value} in the expression. + * + * The string constructor parameter may or may not actaully parse as a DN - the "dn" field should + * always be a DN, however groups will be a DN if they're from an LDAP/AD realm, but often won't be for a SAML realm. + * + * Because the {@link FieldExpression.FieldValue} might be a pattern ({@link CharacterRunAutomaton automaton}), + * we sometimes need to do more complex matching than just comparing a DN for equality. + * + */ + class DistinguishedNamePredicate implements Predicate { + private final String string; + private final DN dn; + + public DistinguishedNamePredicate(String string) { + this.string = string; + this.dn = parseDn(string); + } + + private static DN parseDn(String string) { + try { + return new DN(string); + } catch (LDAPException e) { + return null; + } + } + + @Override + public String toString() { + return string; + } + + @Override + public boolean test(FieldExpression.FieldValue fieldValue) { + final CharacterRunAutomaton automaton = fieldValue.getAutomaton(); + if (automaton != null) { + if (automaton.run(string)) { + return true; + } + if (dn != null && automaton.run(dn.toNormalizedString())) { + return true; + } + if (automaton.run(string.toLowerCase(Locale.ROOT)) || automaton.run(string.toUpperCase(Locale.ROOT))) { + return true; + } + if (dn == null) { + return false; + } + + assert fieldValue.getValue() instanceof String : "FieldValue " + fieldValue + " has automaton but value is " + + (fieldValue.getValue() == null ? "" : fieldValue.getValue().getClass()); + String pattern = (String) fieldValue.getValue(); + + // If the pattern is "*,dc=example,dc=com" then the rule is actually trying to express a DN sub-tree match. + // We can use dn.isDescendantOf for that + if (pattern.startsWith("*,")) { + final String suffix = pattern.substring(2); + // if the suffix has a wildcard, then it's not a pure sub-tree match + if (suffix.indexOf('*') == -1) { + final DN dnSuffix = parseDn(suffix); + if (dnSuffix != null && dn.isDescendantOf(dnSuffix, false)) { + return true; + } + } + } + + return false; + } + if (fieldValue.getValue() instanceof String) { + final String testString = (String) fieldValue.getValue(); + if (testString.equalsIgnoreCase(string)) { + return true; + } + if (dn == null) { + return false; + } + + final DN testDn = parseDn(testString); + if (testDn != null) { + return dn.equals(testDn); + } + return testString.equalsIgnoreCase(dn.toNormalizedString()); + } + return false; + } + } } diff --git a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeRoleMappingStore.java b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeRoleMappingStore.java index 80f407440a7..e4e4afc947f 100644 --- a/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeRoleMappingStore.java +++ b/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeRoleMappingStore.java @@ -32,6 +32,7 @@ import org.elasticsearch.xpack.core.security.action.realm.ClearRealmCacheRespons import org.elasticsearch.xpack.core.security.action.rolemapping.DeleteRoleMappingRequest; import org.elasticsearch.xpack.core.security.action.rolemapping.PutRoleMappingRequest; import org.elasticsearch.xpack.core.security.authc.support.mapper.ExpressionRoleMapping; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.ExpressionModel; import org.elasticsearch.xpack.core.security.client.SecurityClient; import org.elasticsearch.xpack.security.SecurityLifecycleService; import org.elasticsearch.xpack.security.authc.support.CachingUsernamePasswordRealm; @@ -327,10 +328,10 @@ public class NativeRoleMappingStore extends AbstractComponent implements UserRol public void resolveRoles(UserData user, ActionListener> listener) { getRoleMappings(null, ActionListener.wrap( mappings -> { - final Map userDataMap = user.asMap(); + final ExpressionModel model = user.asModel(); Stream stream = mappings.stream() .filter(ExpressionRoleMapping::isEnabled) - .filter(m -> m.getExpression().match(userDataMap)); + .filter(m -> m.getExpression().match(model)); if (logger.isTraceEnabled()) { stream = stream.map(m -> { logger.trace("User [{}] matches role-mapping [{}] with roles [{}]", user.getUsername(), m.getName(), diff --git a/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java b/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java index 82dd2320c03..4e51c93f2ad 100644 --- a/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java +++ b/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java @@ -37,6 +37,7 @@ import org.elasticsearch.xpack.core.security.SecurityField; import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.core.security.client.SecurityClient; import org.elasticsearch.xpack.security.LocalStateSecurity; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/rolemapping/TransportPutRoleMappingActionTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/rolemapping/TransportPutRoleMappingActionTests.java index 9ff9871d594..da9eca7a9b6 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/rolemapping/TransportPutRoleMappingActionTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/rolemapping/TransportPutRoleMappingActionTests.java @@ -63,7 +63,7 @@ public class TransportPutRoleMappingActionTests extends ESTestCase { public void testPutValidMapping() throws Exception { final FieldExpression expression = new FieldExpression( "username", - Collections.singletonList(FieldExpression.FieldPredicate.create("*")) + Collections.singletonList(new FieldExpression.FieldValue("*")) ); final PutRoleMappingResponse response = put("anarchy", expression, "superuser", Collections.singletonMap("dumb", true)); diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/DistinguishedNamePredicateTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/DistinguishedNamePredicateTests.java new file mode 100644 index 00000000000..b771ab21ae8 --- /dev/null +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/DistinguishedNamePredicateTests.java @@ -0,0 +1,54 @@ +/* + * 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.security.authc.support; + +import com.unboundid.ldap.sdk.DN; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; + +import java.util.Locale; +import java.util.function.Predicate; + +import static org.hamcrest.Matchers.equalTo; + +public class DistinguishedNamePredicateTests extends ESTestCase { + + public void testMatching() throws Exception { + String randomDn = "CN=" + randomAlphaOfLengthBetween(3, 12) + + ",OU=" + randomAlphaOfLength(4) + + ", O=" + randomAlphaOfLengthBetween(2, 6); + + // Randomly enter the DN in mixed case, lower case or upper case; + final String inputDn; + if (randomBoolean()) { + inputDn = randomBoolean() ? randomDn.toLowerCase(Locale.ENGLISH) : randomDn.toUpperCase(Locale.ENGLISH); + } else { + inputDn = randomDn; + } + final Predicate predicate = new UserRoleMapper.DistinguishedNamePredicate(inputDn); + + assertPredicate(predicate, randomDn, true); + assertPredicate(predicate, randomDn.toLowerCase(Locale.ROOT), true); + assertPredicate(predicate, randomDn.toUpperCase(Locale.ROOT), true); + assertPredicate(predicate, "/" + inputDn + "/", true); + assertPredicate(predicate, new DN(randomDn).toNormalizedString(), true); + assertPredicate(predicate, "*," + new DN(randomDn).getParent().toNormalizedString(), true); + assertPredicate(predicate, "*," + new DN(inputDn).getParent().getParent().toNormalizedString(), true); + assertPredicate(predicate, randomDn.replaceFirst(".*,", "*,"), true); + assertPredicate(predicate, randomDn.replaceFirst("[^,]*,", "*, "), true); + + assertPredicate(predicate, randomDn + ",CN=AU", false); + assertPredicate(predicate, "X" + randomDn, false); + assertPredicate(predicate, "", false); + assertPredicate(predicate, 1.23, false); + assertPredicate(predicate, true, false); + assertPredicate(predicate, null, false); + } + + private void assertPredicate(Predicate predicate, Object value, boolean expected) { + assertThat("Predicate [" + predicate + "] match [" + value + "]", predicate.test(new FieldValue(value)), equalTo(expected)); + } +} \ No newline at end of file diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ExpressionRoleMappingTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ExpressionRoleMappingTests.java index 8c68d15eb07..0a96dd7c248 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ExpressionRoleMappingTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ExpressionRoleMappingTests.java @@ -22,9 +22,6 @@ package org.elasticsearch.xpack.security.authc.support.mapper; -import java.io.IOException; -import java.util.Collections; - import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; @@ -41,6 +38,10 @@ import org.hamcrest.Matchers; import org.junit.Before; import org.mockito.Mockito; +import java.io.IOException; +import java.util.Collections; +import java.util.Locale; + import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -71,10 +72,19 @@ public class ExpressionRoleMappingTests extends ESTestCase { assertThat(mapping.getRoles(), Matchers.containsInAnyOrder("kibana_user", "sales")); assertThat(mapping.getExpression(), instanceOf(AllExpression.class)); - final UserRoleMapper.UserData user1 = new UserRoleMapper.UserData( + final UserRoleMapper.UserData user1a = new UserRoleMapper.UserData( "john.smith", "cn=john.smith,ou=sales,dc=example,dc=com", Collections.emptyList(), Collections.singletonMap("active", true), realm ); + final UserRoleMapper.UserData user1b = new UserRoleMapper.UserData( + user1a.getUsername(), user1a.getDn().toUpperCase(Locale.US), user1a.getGroups(), user1a.getMetadata(), user1a.getRealm() + ); + final UserRoleMapper.UserData user1c = new UserRoleMapper.UserData( + user1a.getUsername(), user1a.getDn().replaceAll(",", ", "), user1a.getGroups(), user1a.getMetadata(), user1a.getRealm() + ); + final UserRoleMapper.UserData user1d = new UserRoleMapper.UserData( + user1a.getUsername(), user1a.getDn().replaceAll("dc=", "DC="), user1a.getGroups(), user1a.getMetadata(), user1a.getRealm() + ); final UserRoleMapper.UserData user2 = new UserRoleMapper.UserData( "jamie.perez", "cn=jamie.perez,ou=sales,dc=example,dc=com", Collections.emptyList(), Collections.singletonMap("active", false), realm @@ -85,9 +95,12 @@ public class ExpressionRoleMappingTests extends ESTestCase { Collections.emptyList(), Collections.singletonMap("active", true), realm ); - assertThat(mapping.getExpression().match(user1.asMap()), equalTo(true)); - assertThat(mapping.getExpression().match(user2.asMap()), equalTo(false)); - assertThat(mapping.getExpression().match(user3.asMap()), equalTo(false)); + assertThat(mapping.getExpression().match(user1a.asModel()), equalTo(true)); + assertThat(mapping.getExpression().match(user1b.asModel()), equalTo(true)); + assertThat(mapping.getExpression().match(user1c.asModel()), equalTo(true)); + assertThat(mapping.getExpression().match(user1d.asModel()), equalTo(true)); + assertThat(mapping.getExpression().match(user2.asModel()), equalTo(false)); + assertThat(mapping.getExpression().match(user3.asModel()), equalTo(false)); } public void testParsingFailsIfRulesAreMissing() throws Exception { @@ -143,4 +156,4 @@ public class ExpressionRoleMappingTests extends ESTestCase { return mapping; } -} \ No newline at end of file +} diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeUserRoleMapperTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeUserRoleMapperTests.java index c35591ed353..4b253c7ee81 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeUserRoleMapperTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/NativeUserRoleMapperTests.java @@ -5,11 +5,6 @@ */ package org.elasticsearch.xpack.security.authc.support.mapper; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.client.Client; @@ -17,14 +12,21 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.security.authc.support.mapper.ExpressionRoleMapping; -import org.elasticsearch.xpack.security.SecurityLifecycleService; import org.elasticsearch.xpack.core.security.authc.RealmConfig; -import org.elasticsearch.xpack.security.authc.support.UserRoleMapper; +import org.elasticsearch.xpack.core.security.authc.support.mapper.ExpressionRoleMapping; import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression; -import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldPredicate; +import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldValue; +import org.elasticsearch.xpack.security.SecurityLifecycleService; +import org.elasticsearch.xpack.security.authc.support.UserRoleMapper; import org.hamcrest.Matchers; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.stream.Collectors; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -33,25 +35,25 @@ public class NativeUserRoleMapperTests extends ESTestCase { public void testResolveRoles() throws Exception { // Does match DN final ExpressionRoleMapping mapping1 = new ExpressionRoleMapping("dept_h", - new FieldExpression("dn", Collections.singletonList(FieldPredicate.create("*,ou=dept_h,o=forces,dc=gc,dc=ca"))), + new FieldExpression("dn", Collections.singletonList(new FieldValue("*,ou=dept_h,o=forces,dc=gc,dc=ca"))), Arrays.asList("dept_h", "defence"), Collections.emptyMap(), true); // Does not match - user is not in this group final ExpressionRoleMapping mapping2 = new ExpressionRoleMapping("admin", - new FieldExpression("groups", - Collections.singletonList(FieldPredicate.create("cn=esadmin,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca"))), + new FieldExpression("groups", Collections.singletonList( + new FieldValue(randomiseDn("cn=esadmin,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca")))), Arrays.asList("admin"), Collections.emptyMap(), true); // Does match - user is one of these groups final ExpressionRoleMapping mapping3 = new ExpressionRoleMapping("flight", new FieldExpression("groups", Arrays.asList( - FieldPredicate.create("cn=alphaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca"), - FieldPredicate.create("cn=betaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca"), - FieldPredicate.create("cn=gammaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca") + new FieldValue(randomiseDn("cn=alphaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca")), + new FieldValue(randomiseDn("cn=betaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca")), + new FieldValue(randomiseDn("cn=gammaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca")) )), Arrays.asList("flight"), Collections.emptyMap(), true); // Does not match - mapping is not enabled final ExpressionRoleMapping mapping4 = new ExpressionRoleMapping("mutants", - new FieldExpression("groups", - Collections.singletonList(FieldPredicate.create("cn=mutants,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca"))), + new FieldExpression("groups", Collections.singletonList( + new FieldValue(randomiseDn("cn=mutants,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca")))), Arrays.asList("mutants"), Collections.emptyMap(), false); final Client client = mock(Client.class); @@ -61,7 +63,9 @@ public class NativeUserRoleMapperTests extends ESTestCase { final NativeRoleMappingStore store = new NativeRoleMappingStore(Settings.EMPTY, client, lifecycleService) { @Override protected void loadMappings(ActionListener> listener) { - listener.onResponse(Arrays.asList(mapping1, mapping2, mapping3, mapping4)); + final List mappings = Arrays.asList(mapping1, mapping2, mapping3, mapping4); + logger.info("Role mappings are: [{}]", mappings); + listener.onResponse(mappings); } }; @@ -70,15 +74,38 @@ public class NativeUserRoleMapperTests extends ESTestCase { final PlainActionFuture> future = new PlainActionFuture<>(); final UserRoleMapper.UserData user = new UserRoleMapper.UserData("sasquatch", - "cn=walter.langowski,ou=people,ou=dept_h,o=forces,dc=gc,dc=ca", + randomiseDn("cn=walter.langowski,ou=people,ou=dept_h,o=forces,dc=gc,dc=ca"), Arrays.asList( - "cn=alphaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca", - "cn=mutants,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca" + randomiseDn("cn=alphaflight,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca"), + randomiseDn("cn=mutants,ou=groups,ou=dept_h,o=forces,dc=gc,dc=ca") ), Collections.emptyMap(), realm); + logger.info("UserData is [{}]", user); store.resolveRoles(user, future); final Set roles = future.get(); assertThat(roles, Matchers.containsInAnyOrder("dept_h", "defence", "flight")); } -} \ No newline at end of file + private String randomiseDn(String dn) { + // Randomly transform the dn into another valid form that is logically identical, + // but (potentially) textually different + switch (randomIntBetween(0, 3)) { + case 0: + // do nothing + return dn; + case 1: + return dn.toUpperCase(Locale.ROOT); + case 2: + // Upper case just the attribute name for each RDN + return Arrays.stream(dn.split(",")).map(s -> { + final String[] arr = s.split("="); + arr[0] = arr[0].toUpperCase(Locale.ROOT); + return String.join("=", arr); + }).collect(Collectors.joining(",")); + case 3: + return dn.replaceAll(",", ", "); + } + return dn; + } + +} diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/expressiondsl/FieldPredicateTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/expressiondsl/FieldPredicateTests.java deleted file mode 100644 index 82ce9250279..00000000000 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/expressiondsl/FieldPredicateTests.java +++ /dev/null @@ -1,96 +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.security.authc.support.mapper.expressiondsl; - -import java.math.BigInteger; - -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression.FieldPredicate; - -import static org.hamcrest.Matchers.is; - -public class FieldPredicateTests extends ESTestCase { - - public void testNullValue() throws Exception { - final FieldPredicate predicate = FieldPredicate.create(null); - assertThat(predicate.test(null), is(true)); - assertThat(predicate.test(""), is(false)); - assertThat(predicate.test(1), is(false)); - assertThat(predicate.test(true), is(false)); - } - - public void testBooleanValue() throws Exception { - final boolean matchValue = randomBoolean(); - final FieldPredicate predicate = FieldPredicate.create(matchValue); - assertThat(predicate.test(matchValue), is(true)); - assertThat(predicate.test(!matchValue), is(false)); - assertThat(predicate.test(String.valueOf(matchValue)), is(false)); - assertThat(predicate.test(""), is(false)); - assertThat(predicate.test(1), is(false)); - assertThat(predicate.test(null), is(false)); - } - - public void testLongValue() throws Exception { - final int intValue = randomInt(); - final long longValue = intValue; - final FieldPredicate predicate = FieldPredicate.create(longValue); - - assertThat(predicate.test(longValue), is(true)); - assertThat(predicate.test(intValue), is(true)); - assertThat(predicate.test(new BigInteger(String.valueOf(longValue))), is(true)); - - assertThat(predicate.test(longValue - 1), is(false)); - assertThat(predicate.test(intValue + 1), is(false)); - assertThat(predicate.test(String.valueOf(longValue)), is(false)); - assertThat(predicate.test(""), is(false)); - assertThat(predicate.test(true), is(false)); - assertThat(predicate.test(null), is(false)); - } - - public void testSimpleAutomatonValue() throws Exception { - final String prefix = randomAlphaOfLength(3); - final FieldPredicate predicate = FieldPredicate.create(prefix + "*"); - - assertThat(predicate.test(prefix), is(true)); - assertThat(predicate.test(prefix + randomAlphaOfLengthBetween(1, 5)), is(true)); - - assertThat(predicate.test("_" + prefix), is(false)); - assertThat(predicate.test(prefix.substring(0, 1)), is(false)); - - assertThat(predicate.test(""), is(false)); - assertThat(predicate.test(1), is(false)); - assertThat(predicate.test(true), is(false)); - assertThat(predicate.test(null), is(false)); - } - - public void testEmptyStringValue() throws Exception { - final FieldPredicate predicate = FieldPredicate.create(""); - - assertThat(predicate.test(""), is(true)); - - assertThat(predicate.test(randomAlphaOfLengthBetween(1, 3)), is(false)); - assertThat(predicate.test(1), is(false)); - assertThat(predicate.test(true), is(false)); - assertThat(predicate.test(null), is(false)); - } - - public void testRegexAutomatonValue() throws Exception { - final String substring = randomAlphaOfLength(5); - final FieldPredicate predicate = FieldPredicate.create("/.*" + substring + ".*/"); - - assertThat(predicate.test(substring), is(true)); - assertThat(predicate.test( - randomAlphaOfLengthBetween(2, 4) + substring + randomAlphaOfLengthBetween(1, 5)), - is(true)); - - assertThat(predicate.test(substring.substring(1, 3)), is(false)); - - assertThat(predicate.test(""), is(false)); - assertThat(predicate.test(1), is(false)); - assertThat(predicate.test(true), is(false)); - assertThat(predicate.test(null), is(false)); - } -} \ No newline at end of file diff --git a/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java b/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java index ef718d090f7..2fa376ec854 100644 --- a/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java +++ b/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java @@ -11,8 +11,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.xpack.core.ssl.CertUtils; -import org.elasticsearch.xpack.core.ssl.SSLService; -import org.junit.Before; +import org.junit.BeforeClass; import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.SSLContext; @@ -111,10 +110,11 @@ public class EllipticCurveSSLTests extends SecurityIntegTestCase { } } - @Before - public void assumeECDSACiphersSupported() { - final SSLService sslService = internalCluster().getInstance(SSLService.class); - SSLEngine sslEngine = sslService.createSSLEngine(Settings.EMPTY, Settings.EMPTY); + @BeforeClass + public static void assumeECDSACiphersSupported() throws Exception { + SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); + sslContext.init(null, null, null); + SSLEngine sslEngine = sslContext.createSSLEngine(); assumeTrue("ECDSA ciphers must be supported for this test to run. Enabled ciphers: " + Arrays.toString(sslEngine.getEnabledCipherSuites()) + ", supported ciphers: " + Arrays.toString(sslEngine.getSupportedCipherSuites()), diff --git a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java index 3e512305f30..f0fd4ba1575 100644 --- a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java +++ b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java @@ -21,11 +21,11 @@ import org.elasticsearch.common.component.LifecycleListener; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.xpack.core.upgrade.UpgradeField; import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.WatcherState; import org.elasticsearch.xpack.core.watcher.execution.TriggeredWatchStoreField; import org.elasticsearch.xpack.core.watcher.watch.Watch; -import org.elasticsearch.xpack.core.upgrade.UpgradeField; import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.xpack.watcher.watch.WatchStoreUtils; @@ -43,7 +43,6 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste private final WatcherService watcherService; private final ExecutorService executor; private AtomicReference> previousAllocationIds = new AtomicReference<>(Collections.emptyList()); - private volatile WatcherMetaData watcherMetaData; private volatile boolean shutDown = false; // indicates that the node has been shutdown and we should never start watcher after this. @@ -61,7 +60,6 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste shutDown(); } }); - watcherMetaData = new WatcherMetaData(!settings.getAsBoolean("xpack.watcher.start_immediately", true)); } public synchronized void stop(String reason) { @@ -73,7 +71,7 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste stop("shutdown initiated"); } - private synchronized void start(ClusterState state, boolean manual) { + private synchronized void start(ClusterState state) { if (shutDown) { return; } @@ -86,7 +84,8 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste // If we start from a cluster state update we need to check if previously we stopped manually // otherwise Watcher would start upon the next cluster state update while the user instructed Watcher to not run - if (!manual && watcherMetaData != null && watcherMetaData.manuallyStopped()) { + WatcherMetaData watcherMetaData = state.getMetaData().custom(WatcherMetaData.TYPE); + if (watcherMetaData != null && watcherMetaData.manuallyStopped()) { logger.debug("not starting watcher. watcher was stopped manually and therefore cannot be auto-started"); return; } @@ -99,8 +98,10 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste } if (watcherService.validate(state)) { - logger.trace("starting... (based on cluster state version [{}]) (manual [{}])", state.getVersion(), manual); + logger.trace("starting... (based on cluster state version [{}])", state.getVersion()); try { + // we need to populate the allocation ids before the next cluster state listener comes in + checkAndSetAllocationIds(state, false); watcherService.start(state); } catch (Exception e) { logger.warn("failed to start watcher. please wait for the cluster to become ready or try to start Watcher manually", e); @@ -120,68 +121,30 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste @Override public void clusterChanged(ClusterChangedEvent event) { if (event.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || shutDown) { + clearAllocationIds(); // wait until the gateway has recovered from disk, otherwise we think may not have .watches and // a .triggered_watches index, but they may not have been restored from the cluster state on disk return; } if (Strings.isNullOrEmpty(event.state().nodes().getMasterNodeId())) { + clearAllocationIds(); executor.execute(() -> this.stop("no master node")); return; } if (event.state().getBlocks().hasGlobalBlock(ClusterBlockLevel.WRITE)) { + clearAllocationIds(); executor.execute(() -> this.stop("write level cluster block")); return; } - // find out if watcher was stopped or started manually due to this cluster state change - WatcherMetaData watcherMetaData = event.state().getMetaData().custom(WatcherMetaData.TYPE); - - if (watcherMetaData != null) { - this.watcherMetaData = watcherMetaData; - } - - boolean currentWatcherStopped = watcherMetaData != null && watcherMetaData.manuallyStopped() == true; - if (currentWatcherStopped) { + if (isWatcherStoppedManually(event.state())) { + clearAllocationIds(); executor.execute(() -> this.stop("watcher manually marked to shutdown by cluster state update")); } else { if (watcherService.state() == WatcherState.STARTED && event.state().nodes().getLocalNode().isDataNode()) { - DiscoveryNode localNode = event.state().nodes().getLocalNode(); - RoutingNode routingNode = event.state().getRoutingNodes().node(localNode.getId()); - IndexMetaData watcherIndexMetaData = WatchStoreUtils.getConcreteIndex(Watch.INDEX, event.state().metaData()); - - // no watcher index, time to pause, as there are for sure no shards on this node - if (watcherIndexMetaData == null) { - if (previousAllocationIds.get().isEmpty() == false) { - previousAllocationIds.set(Collections.emptyList()); - executor.execute(() -> watcherService.pauseExecution("no watcher index found")); - } - return; - } - - String watchIndex = watcherIndexMetaData.getIndex().getName(); - List localShards = routingNode.shardsWithState(watchIndex, RELOCATING, STARTED); - - // no local shards, empty out watcher and not waste resources! - if (localShards.isEmpty()) { - if (previousAllocationIds.get().isEmpty() == false) { - executor.execute(() -> watcherService.pauseExecution("no local watcher shards")); - previousAllocationIds.set(Collections.emptyList()); - } - return; - } - - List currentAllocationIds = localShards.stream() - .map(ShardRouting::allocationId) - .map(AllocationId::getId) - .collect(Collectors.toList()); - Collections.sort(currentAllocationIds); - - if (previousAllocationIds.get().equals(currentAllocationIds) == false) { - previousAllocationIds.set(currentAllocationIds); - executor.execute(() -> watcherService.reload(event.state(), "different shards allocated on this node")); - } + checkAndSetAllocationIds(event.state(), true); } else if (watcherService.state() != WatcherState.STARTED && watcherService.state() != WatcherState.STARTING) { IndexMetaData watcherIndexMetaData = WatchStoreUtils.getConcreteIndex(Watch.INDEX, event.state().metaData()); IndexMetaData triggeredWatchesIndexMetaData = WatchStoreUtils.getConcreteIndex(TriggeredWatchStoreField.INDEX_NAME, @@ -191,7 +154,8 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste boolean isIndexInternalFormatTriggeredWatchIndex = triggeredWatchesIndexMetaData == null || UpgradeField.checkInternalIndexFormat(triggeredWatchesIndexMetaData); if (isIndexInternalFormatTriggeredWatchIndex && isIndexInternalFormatWatchIndex) { - executor.execute(() -> start(event.state(), false)); + checkAndSetAllocationIds(event.state(), false); + executor.execute(() -> start(event.state())); } else { logger.warn("not starting watcher, upgrade API run required: .watches[{}], .triggered_watches[{}]", isIndexInternalFormatWatchIndex, isIndexInternalFormatTriggeredWatchIndex); @@ -200,7 +164,75 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste } } - public WatcherMetaData watcherMetaData() { - return watcherMetaData; + /** + * check if watcher has been stopped manually via the stop API + */ + private boolean isWatcherStoppedManually(ClusterState state) { + WatcherMetaData watcherMetaData = state.getMetaData().custom(WatcherMetaData.TYPE); + return watcherMetaData != null && watcherMetaData.manuallyStopped(); + } + + /** + * check and optionally set the current allocation ids + * + * @param state the current cluster state + * @param callWatcherService should the watcher service be called for starting/stopping/reloading or should this be treated as a + * dryrun so that the caller is responsible for this + */ + private void checkAndSetAllocationIds(ClusterState state, boolean callWatcherService) { + IndexMetaData watcherIndexMetaData = WatchStoreUtils.getConcreteIndex(Watch.INDEX, state.metaData()); + if (watcherIndexMetaData == null) { + if (clearAllocationIds() && callWatcherService) { + executor.execute(() -> watcherService.pauseExecution("no watcher index found")); + } + return; + } + + DiscoveryNode localNode = state.nodes().getLocalNode(); + RoutingNode routingNode = state.getRoutingNodes().node(localNode.getId()); + // this can happen if the node does not hold any data + if (routingNode == null) { + if (clearAllocationIds() && callWatcherService) { + executor.execute(() -> watcherService.pauseExecution("no routing node for local node found, network issue?")); + } + return; + } + + String watchIndex = watcherIndexMetaData.getIndex().getName(); + List localShards = routingNode.shardsWithState(watchIndex, RELOCATING, STARTED); + // no local shards, empty out watcher and dont waste resources! + if (localShards.isEmpty()) { + if (clearAllocationIds() && callWatcherService) { + executor.execute(() -> watcherService.pauseExecution("no local watcher shards found")); + } + return; + } + + List currentAllocationIds = localShards.stream() + .map(ShardRouting::allocationId) + .map(AllocationId::getId) + .collect(Collectors.toList()); + Collections.sort(currentAllocationIds); + + if (previousAllocationIds.get().equals(currentAllocationIds) == false) { + previousAllocationIds.set(Collections.unmodifiableList(currentAllocationIds)); + if (callWatcherService) { + executor.execute(() -> watcherService.reload(state, "new local watcher shard allocation ids")); + } + } + } + + /** + * clear out current allocation ids if not already happened + * @return true, if existing allocation ids were cleaned out, false otherwise + */ + private boolean clearAllocationIds() { + List previousIds = previousAllocationIds.getAndSet(Collections.emptyList()); + return previousIds.equals(Collections.emptyList()) == false; + } + + // for testing purposes only + List allocationIds() { + return previousAllocationIds.get(); } } diff --git a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java index 5c966291cae..6d8aa29e646 100644 --- a/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java +++ b/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/stats/TransportWatcherStatsAction.java @@ -14,10 +14,10 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.watcher.WatcherMetaData; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsRequest; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsResponse; -import org.elasticsearch.xpack.watcher.WatcherLifeCycleService; import org.elasticsearch.xpack.watcher.WatcherService; import org.elasticsearch.xpack.watcher.execution.ExecutionService; import org.elasticsearch.xpack.watcher.trigger.TriggerService; @@ -33,27 +33,24 @@ public class TransportWatcherStatsAction extends TransportNodesAction nodes, List failures) { - return new WatcherStatsResponse(clusterService.getClusterName(), lifeCycleService.watcherMetaData(), nodes, failures); + return new WatcherStatsResponse(clusterService.getClusterName(), getWatcherMetaData(), nodes, failures); } @Override @@ -83,4 +80,11 @@ public class TransportWatcherStatsAction extends TransportNodesAction randomIndexPatterns() { return IntStream.range(0, between(1, 10)) .mapToObj(n -> randomAlphaOfLengthBetween(1, 100)) diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index d7e99c0c00d..1f37a8f8e8b 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -185,20 +185,10 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase timeWarp = new TimeWarp(internalCluster().getInstances(ScheduleTriggerEngineMock.class), (ClockMock)getInstanceFromMaster(Clock.class)); } - startWatcherIfNodesExist(); - createWatcherIndicesOrAliases(); - } - @After - public void _cleanup() throws Exception { - // Clear all internal watcher state for the next test method: - logger.info("[#{}]: clearing watcher state", getTestName()); - stopWatcher(); - } - - private void startWatcherIfNodesExist() throws Exception { if (internalCluster().size() > 0) { ensureLicenseEnabled(); + if (timeWarped()) { // now that the license is enabled and valid we can freeze all nodes clocks logger.info("[{}#{}]: freezing time on nodes", getTestClass().getSimpleName(), getTestName()); @@ -206,10 +196,19 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase internalCluster().setDisruptionScheme(ice); ice.startDisrupting(); } - assertAcked(watcherClient().prepareWatchService().start().get()); + + createWatcherIndicesOrAliases(); + startWatcher(); } } + @After + public void _cleanup() throws Exception { + // Clear all internal watcher state for the next test method: + logger.info("[#{}]: clearing watcher state", getTestName()); + stopWatcher(); + } + /** * In order to test, that .watches and .triggered-watches indices can also point to an alias, we will rarely create those * after starting watcher @@ -237,6 +236,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase assertAcked(response); ensureGreen(newIndex); } + logger.info("set alias for .watches index to [{}]", newIndex); } else { Settings.Builder builder = Settings.builder(); if (randomBoolean()) { @@ -270,6 +270,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase assertAcked(response); ensureGreen(newIndex); } + logger.info("set alias for .triggered-watches index to [{}]", newIndex); } else { assertAcked(client().admin().indices().prepareCreate(TriggeredWatchStoreField.INDEX_NAME)); ensureGreen(TriggeredWatchStoreField.INDEX_NAME); @@ -277,9 +278,8 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase String historyIndex = HistoryStoreField.getHistoryIndexNameForTime(DateTime.now(DateTimeZone.UTC)); assertAcked(client().admin().indices().prepareCreate(historyIndex)); + logger.info("creating watch history index [{}]", historyIndex); ensureGreen(historyIndex); - - ensureWatcherStarted(); } } @@ -364,7 +364,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase ExecutionState.EXECUTED.id()))) .get(); lastResponse.set(searchResponse); - assertThat("could not find executed watch record", searchResponse.getHits().getTotalHits(), + assertThat("could not find executed watch record for watch " + watchName, searchResponse.getHits().getTotalHits(), greaterThanOrEqualTo(minimumExpectedWatchActionsWithActionPerformed)); if (assertConditionMet) { assertThat((Integer) XContentMapValues.extractValue("result.input.payload.hits.total", @@ -508,12 +508,12 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } protected void startWatcher() throws Exception { - watcherClient().prepareWatchService().start().get(); + assertAcked(watcherClient().prepareWatchService().start().get()); ensureWatcherStarted(); } protected void stopWatcher() throws Exception { - watcherClient().prepareWatchService().stop().get(); + assertAcked(watcherClient().prepareWatchService().stop().get()); ensureWatcherStopped(); } diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java index f39e7028ed0..2615c40ad49 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.execution.TriggeredWatchStoreField; @@ -56,8 +55,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsEqual.equalTo; import static org.joda.time.DateTimeZone.UTC; -@TestLogging("org.elasticsearch.xpack.watcher:DEBUG," + - "org.elasticsearch.xpack.watcher.execution:TRACE") public class BootStrapTests extends AbstractWatcherIntegrationTestCase { @Override @@ -192,6 +189,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase { WatcherSearchTemplateRequest request = templateRequest(searchSource().query(termQuery("field", "value")), "my-index"); + ensureGreen("output", "my-index"); int numWatches = 8; for (int i = 0; i < numWatches; i++) { String watchId = "_id" + i; diff --git a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java index ef5edc7a833..1f7335aef0d 100644 --- a/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java +++ b/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; -import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; @@ -51,7 +50,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; -@TestLogging("org.elasticsearch.xpack.watcher:DEBUG,org.elasticsearch.xpack.watcher.WatcherIndexingListener:TRACE") public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCase { @Override @@ -247,5 +245,4 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1)); assertThat(response.getHits().getAt(0).getSourceAsMap().get("key4").toString(), equalTo("30")); } - } diff --git a/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/BasicRenormalizationIT.java b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/BasicRenormalizationIT.java index 36f578bf08f..76ad45c78f2 100644 --- a/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/BasicRenormalizationIT.java +++ b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/BasicRenormalizationIT.java @@ -107,19 +107,4 @@ public class BasicRenormalizationIT extends MlNativeAutodetectIntegTestCase { putJob(job); return job; } - - private static List generateData(long timestamp, TimeValue bucketSpan, int bucketCount, - Function timeToCountFunction) throws IOException { - List data = new ArrayList<>(); - long now = timestamp; - for (int bucketIndex = 0; bucketIndex < bucketCount; bucketIndex++) { - for (int count = 0; count < timeToCountFunction.apply(bucketIndex); count++) { - Map record = new HashMap<>(); - record.put("time", now); - data.add(createJsonRecord(record)); - } - now += bucketSpan.getMillis(); - } - return data; - } } diff --git a/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java index 9304f765c25..c6e2861e1fd 100644 --- a/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java +++ b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlNativeAutodetectIntegTestCase.java @@ -49,7 +49,9 @@ import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.action.OpenJobAction; +import org.elasticsearch.xpack.core.ml.action.PostCalendarEventsAction; import org.elasticsearch.xpack.core.ml.action.PostDataAction; +import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; import org.elasticsearch.xpack.core.ml.action.PutDatafeedAction; import org.elasticsearch.xpack.core.ml.action.PutFilterAction; import org.elasticsearch.xpack.core.ml.action.PutJobAction; @@ -58,6 +60,8 @@ import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction; import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction; import org.elasticsearch.xpack.core.ml.action.UpdateJobAction; import org.elasticsearch.xpack.core.ml.action.util.PageParams; +import org.elasticsearch.xpack.core.ml.calendars.Calendar; +import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; import org.elasticsearch.xpack.core.ml.job.config.Job; @@ -87,9 +91,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import static org.elasticsearch.test.XContentTestUtils.convertToMap; import static org.elasticsearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder; @@ -415,6 +421,16 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase { return response.isAcknowledged(); } + protected PutCalendarAction.Response putCalendar(String calendarId, List jobIds, String description) { + PutCalendarAction.Request request = new PutCalendarAction.Request(new Calendar(calendarId, jobIds, description)); + return client().execute(PutCalendarAction.INSTANCE, request).actionGet(); + } + + protected PostCalendarEventsAction.Response postScheduledEvents(String calendarId, List events) { + PostCalendarEventsAction.Request request = new PostCalendarEventsAction.Request(calendarId, events); + return client().execute(PostCalendarEventsAction.INSTANCE, request).actionGet(); + } + @Override protected void ensureClusterStateConsistency() throws IOException { if (cluster() != null && cluster().size() > 0) { @@ -469,6 +485,21 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase { } } + protected List generateData(long timestamp, TimeValue bucketSpan, int bucketCount, + Function timeToCountFunction) throws IOException { + List data = new ArrayList<>(); + long now = timestamp; + for (int bucketIndex = 0; bucketIndex < bucketCount; bucketIndex++) { + for (int count = 0; count < timeToCountFunction.apply(bucketIndex); count++) { + Map record = new HashMap<>(); + record.put("time", now); + data.add(createJsonRecord(record)); + } + now += bucketSpan.getMillis(); + } + return data; + } + protected static String createJsonRecord(Map keyValueMap) throws IOException { return JsonXContent.contentBuilder().map(keyValueMap).string() + "\n"; } diff --git a/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ScheduledEventsIT.java b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ScheduledEventsIT.java new file mode 100644 index 00000000000..994de5c72a1 --- /dev/null +++ b/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ScheduledEventsIT.java @@ -0,0 +1,267 @@ +/* + * 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.ml.integration; + +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.xpack.core.ml.action.GetBucketsAction; +import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; +import org.elasticsearch.xpack.core.ml.calendars.ScheduledEvent; +import org.elasticsearch.xpack.core.ml.job.config.AnalysisConfig; +import org.elasticsearch.xpack.core.ml.job.config.DataDescription; +import org.elasticsearch.xpack.core.ml.job.config.Detector; +import org.elasticsearch.xpack.core.ml.job.config.Job; +import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; +import org.elasticsearch.xpack.core.ml.job.results.Bucket; +import org.junit.After; + +import java.io.IOException; +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; + +public class ScheduledEventsIT extends MlNativeAutodetectIntegTestCase { + + @After + public void cleanUpTest() { + cleanUp(); + } + + public void testScheduledEvents() throws IOException { + + TimeValue bucketSpan = TimeValue.timeValueMinutes(30); + Job.Builder job = createJob("scheduled-events", bucketSpan); + String calendarId = "test-calendar"; + putCalendar(calendarId, Collections.singletonList(job.getId()), "testScheduledEvents calendar"); + + long startTime = 1514764800000L; + + List events = new ArrayList<>(); + long firstEventStartTime = 1514937600000L; + long firstEventEndTime = firstEventStartTime + 2 * 60 * 60 * 1000; + events.add(new ScheduledEvent.Builder().description("1st event (2hr)") + .startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(firstEventStartTime), ZoneOffset.UTC)) + .endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(firstEventEndTime), ZoneOffset.UTC)) + .calendarId(calendarId).build()); + // add 10 min event smaller than the bucket + long secondEventStartTime = 1515067200000L; + long secondEventEndTime = secondEventStartTime + 10 * 60 * 1000; + events.add(new ScheduledEvent.Builder().description("2nd event with period smaller than bucketspan") + .startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(secondEventStartTime), ZoneOffset.UTC)) + .endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(secondEventEndTime), ZoneOffset.UTC)) + .calendarId(calendarId).build()); + long thirdEventStartTime = 1515088800000L; + long thirdEventEndTime = thirdEventStartTime + 3 * 60 * 60 * 1000; + events.add(new ScheduledEvent.Builder().description("3rd event 3hr") + .startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(thirdEventStartTime), ZoneOffset.UTC)) + .endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(thirdEventEndTime), ZoneOffset.UTC)) + .calendarId(calendarId).build()); + + postScheduledEvents(calendarId, events); + + // Run 6 days of data + runJob(job, startTime, bucketSpan, 2 * 24 * 6); + + // Check tags on the buckets during the first event + GetBucketsAction.Request getBucketsRequest = new GetBucketsAction.Request(job.getId()); + getBucketsRequest.setStart(Long.toString(firstEventStartTime)); + getBucketsRequest.setEnd(Long.toString(firstEventEndTime)); + List buckets = getBuckets(getBucketsRequest); + for (Bucket bucket : buckets) { + assertEquals(1, bucket.getScheduledEvents().size()); + assertEquals("1st event (2hr)", bucket.getScheduledEvents().get(0)); + assertEquals(0.0, bucket.getAnomalyScore(), 0.00001); + } + + // Following buckets have 0 events + getBucketsRequest = new GetBucketsAction.Request(job.getId()); + getBucketsRequest.setStart(Long.toString(firstEventEndTime)); + getBucketsRequest.setEnd(Long.toString(secondEventStartTime)); + buckets = getBuckets(getBucketsRequest); + for (Bucket bucket : buckets) { + assertEquals(0, bucket.getScheduledEvents().size()); + } + + // The second event bucket + getBucketsRequest.setStart(Long.toString(secondEventStartTime)); + getBucketsRequest.setEnd(Long.toString(secondEventEndTime)); + buckets = getBuckets(getBucketsRequest); + assertEquals(1, buckets.size()); + for (Bucket bucket : buckets) { + assertEquals(1, bucket.getScheduledEvents().size()); + assertEquals("2nd event with period smaller than bucketspan", bucket.getScheduledEvents().get(0)); + assertEquals(0.0, bucket.getAnomalyScore(), 0.00001); + } + + // Following buckets have 0 events + getBucketsRequest.setStart(Long.toString(secondEventEndTime)); + getBucketsRequest.setEnd(Long.toString(thirdEventStartTime)); + buckets = getBuckets(getBucketsRequest); + for (Bucket bucket : buckets) { + assertEquals(0, bucket.getScheduledEvents().size()); + } + + // The 3rd event buckets + getBucketsRequest.setStart(Long.toString(thirdEventStartTime)); + getBucketsRequest.setEnd(Long.toString(thirdEventEndTime)); + buckets = getBuckets(getBucketsRequest); + for (Bucket bucket : buckets) { + assertEquals(1, bucket.getScheduledEvents().size()); + assertEquals("3rd event 3hr", bucket.getScheduledEvents().get(0)); + assertEquals(0.0, bucket.getAnomalyScore(), 0.00001); + } + + // Following buckets have 0 events + getBucketsRequest.setStart(Long.toString(thirdEventEndTime)); + getBucketsRequest.setEnd(null); + buckets = getBuckets(getBucketsRequest); + for (Bucket bucket : buckets) { + assertEquals(0, bucket.getScheduledEvents().size()); + } + + // It is unlikely any anomaly records have been created but + // ensure there are non present anyway + GetRecordsAction.Request getRecordsRequest = new GetRecordsAction.Request(job.getId()); + getRecordsRequest.setStart(Long.toString(firstEventStartTime)); + getRecordsRequest.setEnd(Long.toString(firstEventEndTime)); + List records = getRecords(getRecordsRequest); + assertThat(records, is(empty())); + + getRecordsRequest.setStart(Long.toString(secondEventStartTime)); + getRecordsRequest.setEnd(Long.toString(secondEventEndTime)); + records = getRecords(getRecordsRequest); + assertThat(records, is(empty())); + + getRecordsRequest.setStart(Long.toString(thirdEventStartTime)); + getRecordsRequest.setEnd(Long.toString(thirdEventEndTime)); + records = getRecords(getRecordsRequest); + assertThat(records, is(empty())); + } + + public void testScheduledEventWithInterimResults() throws IOException { + TimeValue bucketSpan = TimeValue.timeValueMinutes(30); + Job.Builder job = createJob("scheduled-events-interim-results", bucketSpan); + String calendarId = "test-calendar"; + putCalendar(calendarId, Collections.singletonList(job.getId()), "testScheduledEventWithInterimResults calendar"); + + long startTime = 1514764800000L; + + List events = new ArrayList<>(); + // The event starts 10 buckets in and lasts for 2 + int bucketCount = 10; + long firstEventStartTime = startTime + bucketSpan.millis() * bucketCount; + long firstEventEndTime = firstEventStartTime + bucketSpan.millis() * 2; + events.add(new ScheduledEvent.Builder().description("1st event 2hr") + .startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(firstEventStartTime), ZoneOffset.UTC)) + .endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(firstEventEndTime), ZoneOffset.UTC)) + .calendarId(calendarId).build()); + postScheduledEvents(calendarId, events); + + + openJob(job.getId()); + // write data up to and including the event + postData(job.getId(), generateData(startTime, bucketSpan, bucketCount + 1, bucketIndex -> randomIntBetween(100, 200)) + .stream().collect(Collectors.joining())); + + // flush the job and get the interim result during the event + flushJob(job.getId(), true); + + GetBucketsAction.Request getBucketsRequest = new GetBucketsAction.Request(job.getId()); + getBucketsRequest.setStart(Long.toString(firstEventStartTime)); + List buckets = getBuckets(getBucketsRequest); + assertEquals(1, buckets.size()); + assertTrue(buckets.get(0).isInterim()); + assertEquals(1, buckets.get(0).getScheduledEvents().size()); + assertEquals("1st event 2hr", buckets.get(0).getScheduledEvents().get(0)); + assertEquals(0.0, buckets.get(0).getAnomalyScore(), 0.00001); + } + + /** + * Test an open job picks up changes to scheduled events/calendars + */ + public void testOnlineUpdate() throws IOException, InterruptedException { + TimeValue bucketSpan = TimeValue.timeValueMinutes(30); + Job.Builder job = createJob("scheduled-events-online-update", bucketSpan); + + long startTime = 1514764800000L; + final int bucketCount = 5; + + // Open the job + openJob(job.getId()); + + // write some buckets of data + postData(job.getId(), generateData(startTime, bucketSpan, bucketCount, bucketIndex -> randomIntBetween(100, 200)) + .stream().collect(Collectors.joining())); + + // Now create a calendar and events for the job while it is open + String calendarId = "test-calendar-online-update"; + putCalendar(calendarId, Collections.singletonList(job.getId()), "testOnlineUpdate calendar"); + + List events = new ArrayList<>(); + long eventStartTime = startTime + (bucketCount + 1) * bucketSpan.millis(); + long eventEndTime = eventStartTime + (long)(1.5 * bucketSpan.millis()); + events.add(new ScheduledEvent.Builder().description("Some Event") + .startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(eventStartTime), ZoneOffset.UTC)) + .endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(eventEndTime), ZoneOffset.UTC)) + .calendarId(calendarId).build()); + + postScheduledEvents(calendarId, events); + + // The update process action is aysnc so give it chance to update + // the job with the added scheduled events + // TODO Wait for the task to finish once #3767 is implemented + Thread.sleep(1000); + + // write some more buckets of data that cover the scheduled event period + postData(job.getId(), generateData(startTime + bucketCount * bucketSpan.millis(), bucketSpan, 5, + bucketIndex -> randomIntBetween(100, 200)) + .stream().collect(Collectors.joining())); + // and close + closeJob(job.getId()); + + GetBucketsAction.Request getBucketsRequest = new GetBucketsAction.Request(job.getId()); + List buckets = getBuckets(getBucketsRequest); + + // the first buckets have no events + for (int i=0; i<=bucketCount; i++) { + assertEquals(0, buckets.get(i).getScheduledEvents().size()); + } + // 7th and 8th buckets have the event + assertEquals(1, buckets.get(6).getScheduledEvents().size()); + assertEquals("Some Event", buckets.get(6).getScheduledEvents().get(0)); + assertEquals(1, buckets.get(7).getScheduledEvents().size()); + assertEquals("Some Event", buckets.get(7).getScheduledEvents().get(0)); + assertEquals(0, buckets.get(8).getScheduledEvents().size()); + } + + private Job.Builder createJob(String jobId, TimeValue bucketSpan) { + Detector.Builder detector = new Detector.Builder("count", null); + AnalysisConfig.Builder analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(detector.build())); + analysisConfig.setBucketSpan(bucketSpan); + Job.Builder job = new Job.Builder(jobId); + job.setAnalysisConfig(analysisConfig); + DataDescription.Builder dataDescription = new DataDescription.Builder(); + job.setDataDescription(dataDescription); + putJob(job); + // register for clean up + registerJob(job); + + return job; + } + + private void runJob(Job.Builder job, long startTime, TimeValue bucketSpan, int bucketCount) throws IOException { + openJob(job.getId()); + postData(job.getId(), generateData(startTime, bucketSpan, bucketCount, bucketIndex -> randomIntBetween(100, 200)) + .stream().collect(Collectors.joining())); + closeJob(job.getId()); + } +} diff --git a/qa/saml-idp-tests/build.gradle b/qa/saml-idp-tests/build.gradle index 7632b82bae1..6c23adb68fc 100644 --- a/qa/saml-idp-tests/build.gradle +++ b/qa/saml-idp-tests/build.gradle @@ -1,8 +1,9 @@ Project idpFixtureProject = xpackProject("test:idp-fixture") evaluationDependsOn(idpFixtureProject.path) -apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.vagrantsupport' +apply plugin: 'elasticsearch.standalone-rest-test' +apply plugin: 'elasticsearch.rest-test' dependencies { testCompile project(path: xpackModule('core'), configuration: 'runtime') @@ -11,35 +12,59 @@ dependencies { testCompile 'com.google.jimfs:jimfs:1.1' } -processTestResources { - if (project.rootProject.vagrantSupported) { - dependsOn "idpFixture" - } -} - -sourceSets { - test { - resources { - srcDirs += idpFixtureProject.file("src/main/resources/provision/generated") - srcDirs += project(xpackModule('security')).file('src/test/resources') - } - } -} - task idpFixture { dependsOn "vagrantCheckVersion", "virtualboxCheckVersion", idpFixtureProject.up } +String outputDir = "generated-resources/${project.name}" +task copyIdpCertificate(type: Copy) { + dependsOn idpFixture + from idpFixtureProject.file('src/main/resources/provision/generated/ca_server.pem'); + into outputDir +} if (project.rootProject.vagrantSupported) { - test.dependsOn idpFixture - test.finalizedBy idpFixtureProject.halt + project.sourceSets.test.output.dir(outputDir, builtBy: copyIdpCertificate) + integTestCluster.dependsOn idpFixture, copyIdpCertificate + integTest.finalizedBy idpFixtureProject.halt } else { - test.enabled = false + integTest.enabled = false } -namingConventions { - // integ tests use Tests instead of IT - skipIntegTestInDisguise = true +integTestCluster { + plugin ':x-pack-elasticsearch:plugin' + + setting 'xpack.security.http.ssl.enabled', 'false' + setting 'xpack.security.authc.token.enabled', 'true' + setting 'xpack.security.authc.realms.file.type', 'file' + setting 'xpack.security.authc.realms.file.order', '0' + setting 'xpack.security.authc.realms.shibboleth.type', 'saml' + setting 'xpack.security.authc.realms.shibboleth.order', '1' + setting 'xpack.security.authc.realms.shibboleth.idp.entity_id', 'https://test.shibboleth.elastic.local/' + setting 'xpack.security.authc.realms.shibboleth.idp.metadata.path', 'idp-metadata.xml' + setting 'xpack.security.authc.realms.shibboleth.sp.entity_id', 'http://mock.http.elastic.local/' + // The port in the ACS URL is fake - the test will bind the mock webserver + // to a random port and then whenever it needs to connect to a URL on the + // mock webserver it will replace 54321 with the real port + setting 'xpack.security.authc.realms.shibboleth.sp.acs', 'http://localhost:54321/saml/acs' + setting 'xpack.security.authc.realms.shibboleth.attributes.principal', 'uid' + setting 'xpack.security.authc.realms.shibboleth.attributes.name', 'urn:oid:2.5.4.3' + setting 'xpack.ml.enabled', 'false' + + extraConfigFile 'idp-metadata.xml', idpFixtureProject.file("src/main/resources/provision/generated/idp-metadata.xml") + + setupCommand 'setupTestAdmin', + 'bin/x-pack/users', 'useradd', "test_admin", '-p', 'x-pack-test-password', '-r', "superuser" + + waitCondition = { node, ant -> + File tmpFile = new File(node.cwd, 'wait.success') + ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes=>=${numNodes}&wait_for_status=yellow", + dest: tmpFile.toString(), + username: 'test_admin', + password: 'x-pack-test-password', + ignoreerrors: true, + retries: 10) + return tmpFile.exists() + } } forbiddenPatterns { @@ -61,7 +86,3 @@ thirdPartyAudit.excludes = [ 'com.ibm.icu.lang.UCharacter' ] -test { - systemProperty 'es.set.netty.runtime.available.processors', 'false' - include '**/*Tests.class' -} diff --git a/qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIntegTests.java b/qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIT.java similarity index 80% rename from qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIntegTests.java rename to qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIT.java index 195486f8df5..433474ed6d1 100644 --- a/qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIntegTests.java +++ b/qa/saml-idp-tests/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticationIT.java @@ -43,28 +43,17 @@ import org.elasticsearch.client.Response; import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.Streams; -import org.elasticsearch.common.lease.Releasables; -import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.mocksocket.MockHttpServer; -import org.elasticsearch.test.SecurityIntegTestCase; -import org.elasticsearch.test.SecuritySettingsSourceField; +import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.common.socket.SocketAccess; -import org.elasticsearch.xpack.core.security.action.rolemapping.PutRoleMappingAction; -import org.elasticsearch.xpack.core.security.action.rolemapping.PutRoleMappingRequestBuilder; -import org.elasticsearch.xpack.core.security.action.user.ChangePasswordRequestBuilder; -import org.elasticsearch.xpack.core.security.authc.file.FileRealmSettings; -import org.elasticsearch.xpack.core.security.authc.saml.SamlRealmSettings; import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; -import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.ExpressionParser; -import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.RoleMapperExpression; import org.elasticsearch.xpack.core.ssl.CertUtils; -import org.elasticsearch.xpack.security.authc.Realms; import org.hamcrest.Matchers; import org.junit.After; import org.junit.AfterClass; @@ -97,6 +86,7 @@ import java.util.regex.Pattern; import static java.util.Collections.emptyMap; import static org.elasticsearch.common.xcontent.XContentHelper.convertToMap; +import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -109,25 +99,16 @@ import static org.hamcrest.Matchers.startsWith; * An integration test for validating SAML authentication against a real Identity Provider (Shibboleth) */ @SuppressForbidden(reason = "uses sun http server") -public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { +public class SamlAuthenticationIT extends ESRestTestCase { - public static final String SP_LOGIN_PATH = "/saml/login"; - public static final String SP_ACS_PATH = "/saml/acs"; - public static final String SAML_RESPONSE_FIELD = "SAMLResponse"; - public static final String REQUEST_ID_COOKIE = "saml-request-id"; + private static final String SP_LOGIN_PATH = "/saml/login"; + private static final String SP_ACS_PATH = "/saml/acs"; + private static final String SAML_RESPONSE_FIELD = "SAMLResponse"; + private static final String REQUEST_ID_COOKIE = "saml-request-id"; + + private static final String KIBANA_PASSWORD = "K1b@na K1b@na K1b@na"; private static HttpServer httpServer; - - @BeforeClass - public static void setupSaml() throws Exception { - SamlTestCase.setupSaml(); - } - - @AfterClass - public static void cleanupSaml() throws Exception { - SamlTestCase.restoreLocale(); - } - @BeforeClass public static void setupHttpServer() throws IOException { InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0); @@ -180,48 +161,23 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { } @Override - protected Settings nodeSettings(int nodeOrdinal) { - Settings.Builder builder = Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put(NetworkModule.HTTP_ENABLED.getKey(), true) - .put("xpack.security.http.ssl.enabled", false) - .put("xpack.security.authc.token.enabled", true) - .put("xpack.security.authc.realms.file.type", FileRealmSettings.TYPE) - .put("xpack.security.authc.realms.file.order", "0") - .put("xpack.security.authc.realms.shibboleth.type", SamlRealmSettings.TYPE) - .put("xpack.security.authc.realms.shibboleth.order", "1") - .put("xpack.security.authc.realms.shibboleth.idp.entity_id", "https://test.shibboleth.elastic.local/") - .put("xpack.security.authc.realms.shibboleth.idp.metadata.path", getDataPath("/idp-metadata.xml")) - .put("xpack.security.authc.realms.shibboleth.sp.entity_id", "http://mock.http.elastic.local/") - .put("xpack.security.authc.realms.shibboleth.sp.acs", getUrl(SP_ACS_PATH)) - .put("xpack.security.authc.realms.shibboleth.attributes.principal", "uid") - .put("xpack.security.authc.realms.shibboleth.attributes.name", "urn:oid:2.5.4.3"); - - return builder.build(); - } - - @After - public void cleanupSecurity() { - for (Realms realms : internalCluster().getInstances(Realms.class)) { - realms.stream() - .filter(SamlRealm.class::isInstance) - .map(SamlRealm.class::cast) - .forEach(r -> Releasables.closeWhileHandlingException(r)); - } - deleteSecurityIndex(); + protected Settings restAdminSettings() { + String token = basicAuthHeaderValue("test_admin", new SecureString("x-pack-test-password".toCharArray())); + return Settings.builder() + .put(ThreadContext.PREFIX + ".Authorization", token) + .build(); } /** * We perform all requests to Elasticsearch as the "kibana" user, as this is the user that will be used - * in a typical SAML deployment (where Kibana is providing the UI for the SAML Web SSO interacttions). + * in a typical SAML deployment (where Kibana is providing the UI for the SAML Web SSO interactions). * Before we can use the Kibana user, we need to set its password to something we know. */ @Before public void setKibanaPassword() throws IOException { - new ChangePasswordRequestBuilder(client()) - .username("kibana") - .password(SecuritySettingsSourceField.TEST_PASSWORD.toCharArray()) - .get(); + final HttpEntity json = new StringEntity("{ \"password\" : \"" + KIBANA_PASSWORD + "\" }", ContentType.APPLICATION_JSON); + final Response response = adminClient().performRequest("PUT", "/_xpack/security/user/kibana/_password", emptyMap(), json); + assertOK(response); } /** @@ -231,28 +187,21 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { */ @Before public void setupRoleMapping() throws IOException { - final String json = XContentBuilder.builder(XContentType.JSON.xContent()) + final StringEntity json = new StringEntity(XContentBuilder.builder(XContentType.JSON.xContent()) .startObject() + .array("roles", new String[] { "kibana_user"} ) + .field("enabled", true) + .startObject("rules") .startArray("all") - .startObject() - .startObject("field").field("username", "thor").endObject() - .endObject() - .startObject() - .startObject("field").field("realm.name", "shibboleth").endObject() - .endObject() - .endArray() - .endObject() - .string(); - final NamedXContentRegistry registry = NamedXContentRegistry.EMPTY; - try (XContentParser parser = XContentType.JSON.xContent().createParser(registry, json)) { - final RoleMapperExpression expression = ExpressionParser.parseObject(parser, "thor-kibana"); - new PutRoleMappingRequestBuilder(client(), PutRoleMappingAction.INSTANCE) - .enabled(true) - .name("thor-kibana") - .expression(expression) - .roles("kibana_user") - .get(); - } + .startObject().startObject("field").field("username", "thor").endObject().endObject() + .startObject().startObject("field").field("realm.name", "shibboleth").endObject().endObject() + .endArray() // "all" + .endObject() // "rules" + .endObject() // top-level + .string(), ContentType.APPLICATION_JSON); + + final Response response = adminClient().performRequest("PUT", "/_xpack/security/role_mapping/thor-kibana", emptyMap(), json); + assertOK(response); } /** @@ -302,8 +251,8 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { */ private void verifyElasticsearchAccessToken(String accessToken) throws IOException { final BasicHeader authorization = new BasicHeader("Authorization", "Bearer " + accessToken); - final Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate", authorization); - assertHttpOk(response); + final Response response = client().performRequest("GET", "/_xpack/security/_authenticate", authorization); + assertOK(response); final Map map = parseResponseAsMap(response.getEntity()); assertThat(map.get("username"), equalTo("thor")); assertThat(map.get("full_name"), equalTo("Thor Odinson")); @@ -323,9 +272,9 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { */ private void verifyElasticsearchRefreshToken(String refreshToken) throws IOException { final String body = "{ \"grant_type\":\"refresh_token\", \"refresh_token\":\"" + refreshToken + "\" }"; - final Response response = getRestClient().performRequest("POST", "/_xpack/security/oauth2/token", - emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON), authHeader("kibana")); - assertHttpOk(response); + final Response response = client().performRequest("POST", "/_xpack/security/oauth2/token", + emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON), kibanaAuth()); + assertOK(response); final Map result = parseResponseAsMap(response.getEntity()); final Object newRefreshToken = result.get("refresh_token"); @@ -416,7 +365,9 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { assertThat(acs.getPath(), equalTo(SP_ACS_PATH)); assertThat("SAML submission content", saml, notNullValue()); - final HttpPost form = new HttpPost(acs); + // The ACS url provided from the SP is going to be wrong because the gradle + // build doesn't know what the web server's port is, so it uses a fake one. + final HttpPost form = new HttpPost(getUrl(SP_ACS_PATH)); List params = new ArrayList<>(); params.add(new BasicNameValuePair(SAML_RESPONSE_FIELD, saml)); form.setEntity(new UrlEncodedFormEntity(params)); @@ -511,9 +462,9 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { * sends a redirect to that page. */ private void httpLogin(HttpExchange http) throws IOException { - final Response prepare = getRestClient().performRequest("POST", "/_xpack/security/saml/prepare", - emptyMap(), new StringEntity("{}", ContentType.APPLICATION_JSON), authHeader("kibana")); - assertHttpOk(prepare); + final Response prepare = client().performRequest("POST", "/_xpack/security/saml/prepare", + emptyMap(), new StringEntity("{}", ContentType.APPLICATION_JSON), kibanaAuth()); + assertOK(prepare); final Map body = parseResponseAsMap(prepare.getEntity()); logger.info("Created SAML authentication request {}", body); http.getResponseHeaders().add("Set-Cookie", REQUEST_ID_COOKIE + "=" + body.get("id")); @@ -529,7 +480,7 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { */ private void httpAcs(HttpExchange http) throws IOException { final Response saml = samlAuthenticate(http); - assertHttpOk(saml); + assertOK(saml); final byte[] content = Streams.copyToString(new InputStreamReader(saml.getEntity().getContent())).getBytes(); http.getResponseHeaders().add("Content-Type", "application/json"); http.sendResponseHeaders(200, content.length); @@ -553,8 +504,8 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { assertThat(id, notNullValue()); final String body = "{ \"content\" : \"" + saml + "\", \"ids\": [\"" + id + "\"] }"; - return getRestClient().performRequest("POST", "/_xpack/security/saml/authenticate", - emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON), authHeader("kibana")); + return client().performRequest("POST", "/_xpack/security/saml/authenticate", + emptyMap(), new StringEntity(body, ContentType.APPLICATION_JSON), kibanaAuth()); } private List parseRequestForm(HttpExchange http) throws IOException { @@ -581,10 +532,6 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { } } - private void assertHttpOk(Response response) { - assertHttpOk(response.getStatusLine()); - } - private void assertHttpOk(StatusLine status) { assertThat("Unexpected HTTP Response status: " + status, status.getStatusCode(), Matchers.equalTo(200)); } @@ -594,10 +541,9 @@ public class SamlAuthenticationIntegTests extends SecurityIntegTestCase { assertThat(((List) value), contains(expectedElement)); } - private static BasicHeader authHeader(String userName) { - return new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, - UsernamePasswordToken.basicAuthHeaderValue(userName, SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING) - ); + private static BasicHeader kibanaAuth() { + final String auth = UsernamePasswordToken.basicAuthHeaderValue("kibana", new SecureString(KIBANA_PASSWORD.toCharArray())); + return new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, auth); } private CloseableHttpClient getHttpClient() throws Exception { diff --git a/qa/tribe-tests-with-security/build.gradle b/qa/tribe-tests-with-security/build.gradle index 798adcfdc04..2c7683fc7c2 100644 --- a/qa/tribe-tests-with-security/build.gradle +++ b/qa/tribe-tests-with-security/build.gradle @@ -81,6 +81,7 @@ List cluster2Nodes = ClusterFormationTasks.setup(project, 'clusterTwo' integTestCluster { dependsOn setupClusterOne, setupClusterTwo plugin xpackProject('plugin').path + nodeStartupWaitSeconds 45 setupCommand 'setupDummyUser', 'bin/x-pack/users', 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser' setting 'xpack.monitoring.enabled', false diff --git a/qa/vagrant/src/test/resources/packaging/utils/xpack.bash b/qa/vagrant/src/test/resources/packaging/utils/xpack.bash index 6fa11e680b8..49c2aa82b77 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/xpack.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/xpack.bash @@ -23,8 +23,6 @@ verify_xpack_installation() { 'certutil.bat' 'croneval' 'croneval.bat' - 'extension' - 'extension.bat' 'migrate' 'migrate.bat' 'saml-metadata'