From 9b0344cd90f02cbcfa86962a450a514e07c479dd Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Fri, 3 Feb 2017 15:10:11 +0000 Subject: [PATCH] Write enum values in lowercase (elastic/elasticsearch#861) Original commit: elastic/x-pack-elasticsearch@6788ad3304a90876c394253d827b8fe322fa2e26 --- .../xpack/ml/datafeed/DatafeedState.java | 5 +++ .../xpack/ml/job/config/Condition.java | 2 +- .../xpack/ml/job/config/Connective.java | 18 ++++------ .../xpack/ml/job/config/DataDescription.java | 18 ++++------ .../config/DefaultDetectorDescription.java | 2 +- .../xpack/ml/job/config/DetectionRule.java | 2 +- .../xpack/ml/job/config/Detector.java | 23 +++++------- .../xpack/ml/job/config/IgnoreDowntime.java | 5 +++ .../xpack/ml/job/config/JobState.java | 5 +++ .../xpack/ml/job/config/ModelDebugConfig.java | 27 ++++++-------- .../xpack/ml/job/config/Operator.java | 36 +++++++------------ .../xpack/ml/job/config/RuleAction.java | 7 +++- .../xpack/ml/job/config/RuleCondition.java | 2 +- .../ml/job/config/RuleConditionType.java | 25 ++++++------- .../xpack/ml/job/messages/Messages.java | 1 - .../autodetect/state/ModelSizeStats.java | 27 +++++--------- .../xpack/ml/notifications/AuditMessage.java | 2 +- .../xpack/ml/notifications/Level.java | 19 ++++------ .../ml/job/messages/ml_messages.properties | 1 - .../StartDatafeedActionRequestTests.java | 2 +- .../xpack/ml/datafeed/DatafeedStateTests.java | 6 +++- .../xpack/ml/integration/DatafeedJobIT.java | 2 +- .../xpack/ml/integration/TooManyJobsIT.java | 2 +- .../xpack/ml/job/config/ConditionTests.java | 2 +- .../xpack/ml/job/config/ConnectiveTests.java | 5 +++ .../xpack/ml/job/config/DataFormatTests.java | 7 +++- .../ml/job/config/IgnoreDowntimeTests.java | 11 ++++-- .../xpack/ml/job/config/JobStateTests.java | 13 +++++++ .../xpack/ml/job/config/OperatorTests.java | 17 +++++---- .../xpack/ml/job/config/RuleActionTests.java | 10 ++++-- .../ml/job/config/RuleConditionTests.java | 4 +-- .../ml/job/config/RuleConditionTypeTests.java | 25 ++++++++----- .../autodetect/state/MemoryStatusTests.java | 23 ++++++------ .../writer/ModelDebugConfigWriterTests.java | 4 +-- .../xpack/ml/notifications/LevelTests.java | 25 ++++++++----- .../test/get_datafeed_stats.yaml | 12 +++---- .../rest-api-spec/test/jobs_get_stats.yaml | 6 ++-- .../rest-api-spec/test/post_data.yaml | 4 +-- .../test/start_stop_datafeed.yaml | 10 +++--- 39 files changed, 216 insertions(+), 201 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedState.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedState.java index b54d5e58a28..75bb3346e81 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedState.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedState.java @@ -32,4 +32,9 @@ public enum DatafeedState implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Condition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Condition.java index ae53f20f8bc..6a6c67a29df 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Condition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Condition.java @@ -100,7 +100,7 @@ public class Condition extends ToXContentToBytes implements Writeable { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(Operator.OPERATOR_FIELD.getPreferredName(), op.getName()); + builder.field(Operator.OPERATOR_FIELD.getPreferredName(), op); builder.field(FILTER_VALUE_FIELD.getPreferredName(), filterValue); builder.endObject(); return builder; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Connective.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Connective.java index 01705c4334e..d99bc72d85b 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Connective.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Connective.java @@ -13,18 +13,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; public enum Connective implements Writeable { - OR("or"), - AND("and"); - - private String name; - - private Connective(String name) { - this.name = name; - } - - public String getName() { - return name; - } + OR, AND; /** * Case-insensitive from string method. @@ -49,4 +38,9 @@ public enum Connective implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DataDescription.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DataDescription.java index f27fa1be68c..d2b60825f07 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DataDescription.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DataDescription.java @@ -40,23 +40,14 @@ public class DataDescription extends ToXContentToBytes implements Writeable { * Enum of the acceptable data formats. */ public enum DataFormat implements Writeable { - JSON("json"), - DELIMITED("delimited"); + JSON, + DELIMITED; /** * Delimited used to be called delineated. We keep supporting that for backwards * compatibility. */ private static final String DEPRECATED_DELINEATED = "DELINEATED"; - private String name; - - private DataFormat(String name) { - this.name = name; - } - - public String getName() { - return name; - } /** * Case-insensitive from string method. @@ -83,6 +74,11 @@ public class DataDescription extends ToXContentToBytes implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } private static final ParseField DATA_DESCRIPTION_FIELD = new ParseField("data_description"); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DefaultDetectorDescription.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DefaultDetectorDescription.java index 6fafd89b20f..89179e0df88 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DefaultDetectorDescription.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DefaultDetectorDescription.java @@ -68,7 +68,7 @@ public final class DefaultDetectorDescription { } if (detector.getExcludeFrequent() != null) { - sb.append(EXCLUDE_FREQUENT_OPTION).append(detector.getExcludeFrequent().getToken()); + sb.append(EXCLUDE_FREQUENT_OPTION).append(detector.getExcludeFrequent()); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DetectionRule.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DetectionRule.java index e61f4c16032..fb261d2c832 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DetectionRule.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/DetectionRule.java @@ -84,7 +84,7 @@ public class DetectionRule extends ToXContentToBytes implements Writeable { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(CONDITIONS_CONNECTIVE_FIELD.getPreferredName(), conditionsConnective.getName()); + builder.field(CONDITIONS_CONNECTIVE_FIELD.getPreferredName(), conditionsConnective); builder.field(RULE_CONDITIONS_FIELD.getPreferredName(), ruleConditions); if (targetFieldName != null) { builder.field(TARGET_FIELD_NAME_FIELD.getPreferredName(), targetFieldName); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Detector.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Detector.java index b2c2555fdc8..c6f3f108771 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Detector.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Detector.java @@ -37,20 +37,10 @@ import java.util.stream.Collectors; public class Detector extends ToXContentToBytes implements Writeable { public enum ExcludeFrequent implements Writeable { - ALL("all"), - NONE("none"), - BY("by"), - OVER("over"); - - private final String token; - - ExcludeFrequent(String token) { - this.token = token; - } - - public String getToken() { - return token; - } + ALL, + NONE, + BY, + OVER; /** * Case-insensitive from string method. @@ -75,6 +65,11 @@ public class Detector extends ToXContentToBytes implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } public static final ParseField DETECTOR_DESCRIPTION_FIELD = new ParseField("detector_description"); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntime.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntime.java index 7b88d9866e0..2106ccc8a04 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntime.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntime.java @@ -48,4 +48,9 @@ public enum IgnoreDowntime implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/JobState.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/JobState.java index 64aaede20fc..afaa03292eb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/JobState.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/JobState.java @@ -45,4 +45,9 @@ public enum JobState implements Writeable { public boolean isAnyOf(JobState... candidates) { return Arrays.stream(candidates).anyMatch(candidate -> this == candidate); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ModelDebugConfig.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ModelDebugConfig.java index 03b9b7189bd..0dfa7ed0b96 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ModelDebugConfig.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ModelDebugConfig.java @@ -24,18 +24,7 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable { * Enum of the acceptable output destinations. */ public enum DebugDestination implements Writeable { - FILE("file"), - DATA_STORE("data_store"); - - private String name; - - DebugDestination(String name) { - this.name = name; - } - - public String getName() { - return name; - } + FILE, DATA_STORE; /** * Case-insensitive from string method. Works with FILE, File, file, @@ -45,9 +34,8 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable { * String representation * @return The output destination */ - public static DebugDestination forString(String value) { - String valueUpperCase = value.toUpperCase(Locale.ROOT); - return DebugDestination.valueOf(valueUpperCase); + public static DebugDestination fromString(String value) { + return DebugDestination.valueOf(value.toUpperCase(Locale.ROOT)); } public static DebugDestination readFromStream(StreamInput in) throws IOException { @@ -62,6 +50,11 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } private static final double MAX_PERCENTILE = 100.0; @@ -80,7 +73,7 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable { } }); static { - PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> DebugDestination.forString(p.text()), WRITE_TO_FIELD, + PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> DebugDestination.fromString(p.text()), WRITE_TO_FIELD, ValueType.STRING); PARSER.declareDouble(ConstructingObjectParser.constructorArg(), BOUNDS_PERCENTILE_FIELD); PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), TERMS_FIELD); @@ -121,7 +114,7 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (writeTo != null) { - builder.field(WRITE_TO_FIELD.getPreferredName(), writeTo.getName()); + builder.field(WRITE_TO_FIELD.getPreferredName(), writeTo); } builder.field(BOUNDS_PERCENTILE_FIELD.getPreferredName(), boundsPercentile); if (terms != null) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Operator.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Operator.java index cb7a9e2a6f3..f6b4d72f2f9 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Operator.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/Operator.java @@ -22,37 +22,37 @@ import java.util.regex.Pattern; * Enum representing logical comparisons on doubles */ public enum Operator implements Writeable { - EQ("eq") { + EQ { @Override public boolean test(double lhs, double rhs) { return Double.compare(lhs, rhs) == 0; } }, - GT("gt") { + GT { @Override public boolean test(double lhs, double rhs) { return Double.compare(lhs, rhs) > 0; } }, - GTE("gte") { + GTE { @Override public boolean test(double lhs, double rhs) { return Double.compare(lhs, rhs) >= 0; } }, - LT("lt") { + LT { @Override public boolean test(double lhs, double rhs) { return Double.compare(lhs, rhs) < 0; } }, - LTE("lte") { + LTE { @Override public boolean test(double lhs, double rhs) { return Double.compare(lhs, rhs) <= 0; } }, - MATCH("match") { + MATCH { @Override public boolean match(Pattern pattern, String field) { Matcher match = pattern.matcher(field); @@ -66,15 +66,6 @@ public enum Operator implements Writeable { }; public static final ParseField OPERATOR_FIELD = new ParseField("operator"); - private final String name; - - private Operator(String name) { - this.name = name; - } - - public String getName() { - return name; - } public boolean test(double lhs, double rhs) { return false; @@ -89,15 +80,7 @@ public enum Operator implements Writeable { } public static Operator fromString(String name) { - Set all = EnumSet.allOf(Operator.class); - - String ucName = name.toUpperCase(Locale.ROOT); - for (Operator type : all) { - if (type.toString().equals(ucName)) { - return type; - } - } - throw new IllegalArgumentException(Messages.getMessage(Messages.JOB_CONFIG_CONDITION_UNKNOWN_OPERATOR, name)); + return valueOf(name.trim().toUpperCase(Locale.ROOT)); } public static Operator readFromStream(StreamInput in) throws IOException { @@ -112,4 +95,9 @@ public enum Operator implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleAction.java index f70625d7b30..073f150611a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleAction.java @@ -16,7 +16,12 @@ public enum RuleAction { * @param value String representation * @return The rule action */ - public static RuleAction forString(String value) { + public static RuleAction fromString(String value) { return RuleAction.valueOf(value.toUpperCase(Locale.ROOT)); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleCondition.java index 44d9e292e06..a0c16d57f5e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleCondition.java @@ -35,7 +35,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { static { PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> { if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return RuleConditionType.forString(p.text()); + return RuleConditionType.fromString(p.text()); } throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]"); }, CONDITION_TYPE_FIELD, ValueType.STRING); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleConditionType.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleConditionType.java index ed305daf623..b13418d9188 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleConditionType.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/RuleConditionType.java @@ -14,20 +14,10 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; public enum RuleConditionType implements Writeable { - CATEGORICAL("categorical"), - NUMERICAL_ACTUAL("numerical_actual"), - NUMERICAL_TYPICAL("numerical_typical"), - NUMERICAL_DIFF_ABS("numerical_diff_abs"); - - private String name; - - private RuleConditionType(String name) { - this.name = name; - } - - public String getName() { - return name; - } + CATEGORICAL, + NUMERICAL_ACTUAL, + NUMERICAL_TYPICAL, + NUMERICAL_DIFF_ABS; /** * Case-insensitive from string method. @@ -36,7 +26,7 @@ public enum RuleConditionType implements Writeable { * String representation * @return The condition type */ - public static RuleConditionType forString(String value) { + public static RuleConditionType fromString(String value) { return RuleConditionType.valueOf(value.toUpperCase(Locale.ROOT)); } @@ -52,4 +42,9 @@ public enum RuleConditionType implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/messages/Messages.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/messages/Messages.java index 58d9ae83845..2313962610d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/messages/Messages.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/messages/Messages.java @@ -75,7 +75,6 @@ public final class Messages { public static final String JOB_CONFIG_CONDITION_INVALID_VALUE_NULL = "job.config.condition.invalid.value.null"; public static final String JOB_CONFIG_CONDITION_INVALID_VALUE_NUMBER = "job.config.condition.invalid.value.numeric"; public static final String JOB_CONFIG_CONDITION_INVALID_VALUE_REGEX = "job.config.condition.invalid.value.regex"; - public static final String JOB_CONFIG_CONDITION_UNKNOWN_OPERATOR = "job.config.condition.unknown.operator"; public static final String JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_INVALID_OPTION = "job.config.detectionrule.condition." + "categorical.invalid.option"; public static final String JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_MISSING_OPTION = "job.config.detectionrule.condition." diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStats.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStats.java index 104245e3897..6ce95838814 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStats.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/ModelSizeStats.java @@ -20,6 +20,7 @@ import org.elasticsearch.xpack.ml.utils.time.TimeUtils; import java.io.IOException; import java.util.Date; +import java.util.Locale; import java.util.Objects; /** @@ -88,25 +89,10 @@ public class ModelSizeStats extends ToXContentToBytes implements Writeable { * been dropped */ public enum MemoryStatus implements Writeable { - OK("ok"), SOFT_LIMIT("soft_limit"), HARD_LIMIT("hard_limit"); - - private String name; - - private MemoryStatus(String name) { - this.name = name; - } - - public String getName() { - return name; - } + OK, SOFT_LIMIT, HARD_LIMIT; public static MemoryStatus fromString(String statusName) { - for (MemoryStatus status : values()) { - if (status.name.equals(statusName)) { - return status; - } - } - throw new IllegalArgumentException("Unknown MemoryStatus [" + statusName + "]"); + return valueOf(statusName.trim().toUpperCase(Locale.ROOT)); } public static MemoryStatus readFromStream(StreamInput in) throws IOException { @@ -121,6 +107,11 @@ public class ModelSizeStats extends ToXContentToBytes implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } private final String jobId; @@ -192,7 +183,7 @@ public class ModelSizeStats extends ToXContentToBytes implements Writeable { builder.field(TOTAL_OVER_FIELD_COUNT_FIELD.getPreferredName(), totalOverFieldCount); builder.field(TOTAL_PARTITION_FIELD_COUNT_FIELD.getPreferredName(), totalPartitionFieldCount); builder.field(BUCKET_ALLOCATION_FAILURES_COUNT_FIELD.getPreferredName(), bucketAllocationFailuresCount); - builder.field(MEMORY_STATUS_FIELD.getPreferredName(), memoryStatus.getName()); + builder.field(MEMORY_STATUS_FIELD.getPreferredName(), memoryStatus); builder.field(LOG_TIME_FIELD.getPreferredName(), logTime.getTime()); if (timestamp != null) { builder.field(TIMESTAMP_FIELD.getPreferredName(), timestamp.getTime()); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/AuditMessage.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/AuditMessage.java index 4c11fcca771..4e4af11af5d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/AuditMessage.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/AuditMessage.java @@ -37,7 +37,7 @@ public class AuditMessage extends ToXContentToBytes implements Writeable { PARSER.declareString(AuditMessage::setMessage, MESSAGE); PARSER.declareField(AuditMessage::setLevel, p -> { if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return Level.forString(p.text()); + return Level.fromString(p.text()); } throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]"); }, LEVEL, ValueType.STRING); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/Level.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/Level.java index 629326c8e9a..a283a253040 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/Level.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/notifications/Level.java @@ -13,17 +13,7 @@ import java.io.IOException; import java.util.Locale; public enum Level implements Writeable { - INFO("info"), ACTIVITY("activity"), WARNING("warning"), ERROR("error"); - - private String name; - - private Level(String name) { - this.name = name; - } - - public String getName() { - return name; - } + INFO, ACTIVITY, WARNING, ERROR; /** * Case-insensitive from string method. @@ -32,7 +22,7 @@ public enum Level implements Writeable { * String representation * @return The condition type */ - public static Level forString(String value) { + public static Level fromString(String value) { return Level.valueOf(value.toUpperCase(Locale.ROOT)); } @@ -48,4 +38,9 @@ public enum Level implements Writeable { public void writeTo(StreamOutput out) throws IOException { out.writeVInt(ordinal()); } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/elasticsearch/src/main/resources/org/elasticsearch/xpack/ml/job/messages/ml_messages.properties b/elasticsearch/src/main/resources/org/elasticsearch/xpack/ml/job/messages/ml_messages.properties index ed00e5f399b..17f9cce2ce0 100644 --- a/elasticsearch/src/main/resources/org/elasticsearch/xpack/ml/job/messages/ml_messages.properties +++ b/elasticsearch/src/main/resources/org/elasticsearch/xpack/ml/job/messages/ml_messages.properties @@ -55,7 +55,6 @@ job.config.condition.invalid.operator = Invalid operator for condition job.config.condition.invalid.value.null = Invalid condition: the value field cannot be null job.config.condition.invalid.value.numeric = Invalid condition value: cannot parse a double from string ''{0}'' job.config.condition.invalid.value.regex = Invalid condition value: ''{0}'' is not a valid regular expression -job.config.condition.unknown.operator = Unknown condition operator ''{0}'' job.config.detectionrule.condition.categorical.invalid.option = Invalid detector rule: a categorical rule_condition does not support {0} job.config.detectionrule.condition.categorical.missing.option = Invalid detector rule: a categorical rule_condition requires {0} to be set job.config.detectionrule.condition.invalid.fieldname = Invalid detector rule: field_name has to be one of {0}; actual was ''{1}'' diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java index b71d136ffc5..d1b6fdd95c9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java @@ -53,7 +53,7 @@ public class StartDatafeedActionRequestTests extends AbstractStreamableXContentT .build(); e = expectThrows(ElasticsearchStatusException.class, () -> StartDatafeedAction.validate("foo-datafeed", mlMetadata2)); - assertThat(e.getMessage(), equalTo("cannot start datafeed, expected job state [OPENED], but got [CLOSED]")); + assertThat(e.getMessage(), equalTo("cannot start datafeed, expected job state [opened], but got [closed]")); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedStateTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedStateTests.java index 721489f42d2..ca538ba2d57 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedStateTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedStateTests.java @@ -14,9 +14,13 @@ public class DatafeedStateTests extends ESTestCase { assertEquals(DatafeedState.fromString("stopped"), DatafeedState.STOPPED); } + public void testToString() { + assertEquals("started", DatafeedState.STARTED.toString()); + assertEquals("stopped", DatafeedState.STOPPED.toString()); + } + public void testValidOrdinals() { assertEquals(0, DatafeedState.STARTED.ordinal()); assertEquals(1, DatafeedState.STOPPED.ordinal()); } - } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobIT.java index 978c01bdd77..51824ecf06b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobIT.java @@ -329,7 +329,7 @@ public class DatafeedJobIT extends ESRestTestCase { try { Response datafeedStatsResponse = client().performRequest("get", MlPlugin.BASE_PATH + "datafeeds/" + datafeedId + "/_stats"); - assertThat(responseEntityToString(datafeedStatsResponse), containsString("\"state\":\"STOPPED\"")); + assertThat(responseEntityToString(datafeedStatsResponse), containsString("\"state\":\"stopped\"")); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/TooManyJobsIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/TooManyJobsIT.java index 35d9a608935..862200a1a79 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/TooManyJobsIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/integration/TooManyJobsIT.java @@ -84,7 +84,7 @@ public class TooManyJobsIT extends ESIntegTestCase { logger.warn("Unexpected cause", e); } assertEquals(IllegalArgumentException.class, cause.getClass()); - assertEquals("Timeout expired while waiting for job state to change to [OPENED]", cause.getMessage()); + assertEquals("Timeout expired while waiting for job state to change to [opened]", cause.getMessage()); logger.info("good news everybody --> reached maximum number of allowed opened jobs, after trying to open the {}th job", i); // now manually clean things up and see if we can succeed to run one new job diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConditionTests.java index 3bc340b398e..526869ed233 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConditionTests.java @@ -52,7 +52,7 @@ public class ConditionTests extends AbstractSerializingTestCase { condition = new Condition(op, randomAsciiOfLengthBetween(1, 20)); break; default: - throw new AssertionError("Unknown operator selected: " + op.getName()); + throw new AssertionError("Unknown operator selected: " + op); } return condition; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConnectiveTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConnectiveTests.java index 183ae417c5c..0b34d489512 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConnectiveTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ConnectiveTests.java @@ -23,6 +23,11 @@ public class ConnectiveTests extends ESTestCase { assertEquals(Connective.AND, Connective.fromString("AND")); } + public void testToString() { + assertEquals("or", Connective.OR.toString()); + assertEquals("and", Connective.AND.toString()); + } + public void testValidOrdinals() { assertThat(Connective.OR.ordinal(), equalTo(0)); assertThat(Connective.AND.ordinal(), equalTo(1)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DataFormatTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DataFormatTests.java index 373b2498102..5a53f177e9b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DataFormatTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DataFormatTests.java @@ -17,7 +17,7 @@ import static org.hamcrest.Matchers.equalTo; public class DataFormatTests extends ESTestCase { - public void testDataFormatForString() { + public void testFromString() { assertEquals(DataFormat.DELIMITED, DataFormat.forString("delineated")); assertEquals(DataFormat.DELIMITED, DataFormat.forString("DELINEATED")); assertEquals(DataFormat.DELIMITED, DataFormat.forString("delimited")); @@ -27,6 +27,11 @@ public class DataFormatTests extends ESTestCase { assertEquals(DataFormat.JSON, DataFormat.forString("JSON")); } + public void testToString() { + assertEquals("delimited", DataFormat.DELIMITED.toString()); + assertEquals("json", DataFormat.JSON.toString()); + } + public void testValidOrdinals() { assertThat(DataFormat.JSON.ordinal(), equalTo(0)); assertThat(DataFormat.DELIMITED.ordinal(), equalTo(1)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntimeTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntimeTests.java index 25f41c8361d..3e9fd3eac52 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntimeTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/IgnoreDowntimeTests.java @@ -9,12 +9,18 @@ import org.elasticsearch.test.ESTestCase; public class IgnoreDowntimeTests extends ESTestCase { - public void testForString() { + public void testFromString() { assertEquals(IgnoreDowntime.fromString("always"), IgnoreDowntime.ALWAYS); assertEquals(IgnoreDowntime.fromString("never"), IgnoreDowntime.NEVER); assertEquals(IgnoreDowntime.fromString("once"), IgnoreDowntime.ONCE); } + public void testToString() { + assertEquals("always", IgnoreDowntime.ALWAYS.toString()); + assertEquals("never", IgnoreDowntime.NEVER.toString()); + assertEquals("once", IgnoreDowntime.ONCE.toString()); + } + public void testValidOrdinals() { assertEquals(0, IgnoreDowntime.NEVER.ordinal()); assertEquals(1, IgnoreDowntime.ONCE.ordinal()); @@ -45,7 +51,6 @@ public class IgnoreDowntimeTests extends ESTestCase { } public void testFromString_GivenNonMatchingString() { - ESTestCase.expectThrows(IllegalArgumentException.class, - () -> IgnoreDowntime.fromString("nope")); + ESTestCase.expectThrows(IllegalArgumentException.class, () -> IgnoreDowntime.fromString("nope")); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/JobStateTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/JobStateTests.java index 233cf63470c..e6d9b4b4975 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/JobStateTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/JobStateTests.java @@ -15,6 +15,19 @@ public class JobStateTests extends ESTestCase { assertEquals(JobState.fromString("failed"), JobState.FAILED); assertEquals(JobState.fromString("opening"), JobState.OPENING); assertEquals(JobState.fromString("opened"), JobState.OPENED); + assertEquals(JobState.fromString("CLOSED"), JobState.CLOSED); + assertEquals(JobState.fromString("CLOSING"), JobState.CLOSING); + assertEquals(JobState.fromString("FAILED"), JobState.FAILED); + assertEquals(JobState.fromString("OPENING"), JobState.OPENING); + assertEquals(JobState.fromString("OPENED"), JobState.OPENED); + } + + public void testToString() { + assertEquals("closed", JobState.CLOSED.toString()); + assertEquals("closing", JobState.CLOSING.toString()); + assertEquals("failed", JobState.FAILED.toString()); + assertEquals("opening", JobState.OPENING.toString()); + assertEquals("opened", JobState.OPENED.toString()); } public void testValidOrdinals() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/OperatorTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/OperatorTests.java index 6e45e21e0ea..695d7eea087 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/OperatorTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/OperatorTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.ml.job.config; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.ml.job.messages.Messages; import java.io.IOException; import java.util.regex.Pattern; @@ -18,7 +17,6 @@ import static org.hamcrest.Matchers.equalTo; public class OperatorTests extends ESTestCase { - public void testFromString() { assertEquals(Operator.fromString("eq"), Operator.EQ); assertEquals(Operator.fromString("gt"), Operator.GT); @@ -30,9 +28,16 @@ public class OperatorTests extends ESTestCase { assertEquals(Operator.fromString("EQ"), Operator.EQ); assertEquals(Operator.fromString("GTE"), Operator.GTE); assertEquals(Operator.fromString("Match"), Operator.MATCH); - } + public void testToString() { + assertEquals("eq", Operator.EQ.toString()); + assertEquals("gt", Operator.GT.toString()); + assertEquals("gte", Operator.GTE.toString()); + assertEquals("lte", Operator.LTE.toString()); + assertEquals("lt", Operator.LT.toString()); + assertEquals("match", Operator.MATCH.toString()); + } public void testTest() { assertTrue(Operator.GT.expectsANumericArgument()); @@ -58,7 +63,6 @@ public class OperatorTests extends ESTestCase { assertFalse(Operator.LTE.test(1.0, 0.0)); } - public void testMatch() { assertFalse(Operator.MATCH.expectsANumericArgument()); assertFalse(Operator.MATCH.test(0.0, 1.0)); @@ -172,9 +176,4 @@ public class OperatorTests extends ESTestCase { } } } - - public void testVerify_unknownOp() { - IllegalArgumentException e = ESTestCase.expectThrows(IllegalArgumentException.class, () -> Operator.fromString("bad_op")); - assertEquals(Messages.getMessage(Messages.JOB_CONFIG_CONDITION_UNKNOWN_OPERATOR, "bad_op"), e.getMessage()); - } } \ No newline at end of file diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleActionTests.java index 748ff8b6ea3..28312c01135 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleActionTests.java @@ -10,8 +10,12 @@ import org.elasticsearch.test.ESTestCase; public class RuleActionTests extends ESTestCase { public void testForString() { - assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("filter_results")); - assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("FILTER_RESULTS")); - assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("fiLTer_Results")); + assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("filter_results")); + assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("FILTER_RESULTS")); + assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("fiLTer_Results")); + } + + public void testToString() { + assertEquals("filter_results", RuleAction.FILTER_RESULTS.toString()); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTests.java index baceb71377b..029bf08e8c6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTests.java @@ -180,14 +180,14 @@ public class RuleConditionTests extends AbstractSerializingTestCase new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, condition, null)); - assertEquals("Invalid detector rule: operator 'EQ' is not allowed", e.getMessage()); + assertEquals("Invalid detector rule: operator 'eq' is not allowed", e.getMessage()); } public void testVerify_GivenNumericalAndOperatorMatch() { Condition condition = new Condition(Operator.MATCH, "aaa"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, condition, null)); - assertEquals("Invalid detector rule: operator 'MATCH' is not allowed", e.getMessage()); + assertEquals("Invalid detector rule: operator 'match' is not allowed", e.getMessage()); } public void testVerify_GivenDetectionRuleWithInvalidCondition() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTypeTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTypeTests.java index 665c2b8963c..288fd85c8f9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTypeTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/RuleConditionTypeTests.java @@ -16,15 +16,22 @@ import static org.hamcrest.Matchers.equalTo; public class RuleConditionTypeTests extends ESTestCase { - public void testForString() { - assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.forString("categorical")); - assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.forString("CATEGORICAL")); - assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.forString("numerical_actual")); - assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.forString("NUMERICAL_ACTUAL")); - assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.forString("numerical_typical")); - assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.forString("NUMERICAL_TYPICAL")); - assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.forString("numerical_diff_abs")); - assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.forString("NUMERICAL_DIFF_ABS")); + public void testFromString() { + assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.fromString("categorical")); + assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.fromString("CATEGORICAL")); + assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.fromString("numerical_actual")); + assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.fromString("NUMERICAL_ACTUAL")); + assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.fromString("numerical_typical")); + assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.fromString("NUMERICAL_TYPICAL")); + assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.fromString("numerical_diff_abs")); + assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.fromString("NUMERICAL_DIFF_ABS")); + } + + public void testToString() { + assertEquals("categorical", RuleConditionType.CATEGORICAL.toString()); + assertEquals("numerical_actual", RuleConditionType.NUMERICAL_ACTUAL.toString()); + assertEquals("numerical_typical", RuleConditionType.NUMERICAL_TYPICAL.toString()); + assertEquals("numerical_diff_abs", RuleConditionType.NUMERICAL_DIFF_ABS.toString()); } public void testValidOrdinals() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/MemoryStatusTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/MemoryStatusTests.java index 98e773e99c7..321468117e9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/MemoryStatusTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/state/MemoryStatusTests.java @@ -18,9 +18,18 @@ import static org.hamcrest.Matchers.equalTo; public class MemoryStatusTests extends ESTestCase { public void testFromString() { - assertEquals(MemoryStatus.OK, MemoryStatus.fromString(MemoryStatus.OK.getName())); - assertEquals(MemoryStatus.SOFT_LIMIT, MemoryStatus.fromString(MemoryStatus.SOFT_LIMIT.getName())); - assertEquals(MemoryStatus.HARD_LIMIT, MemoryStatus.fromString(MemoryStatus.HARD_LIMIT.getName())); + assertEquals(MemoryStatus.OK, MemoryStatus.fromString("ok")); + assertEquals(MemoryStatus.SOFT_LIMIT, MemoryStatus.fromString("soft_limit")); + assertEquals(MemoryStatus.HARD_LIMIT, MemoryStatus.fromString("hard_limit")); + assertEquals(MemoryStatus.OK, MemoryStatus.fromString("OK")); + assertEquals(MemoryStatus.SOFT_LIMIT, MemoryStatus.fromString("SOFT_LIMIT")); + assertEquals(MemoryStatus.HARD_LIMIT, MemoryStatus.fromString("HARD_LIMIT")); + } + + public void testToString() { + assertEquals("ok", MemoryStatus.OK.toString()); + assertEquals("soft_limit", MemoryStatus.SOFT_LIMIT.toString()); + assertEquals("hard_limit", MemoryStatus.HARD_LIMIT.toString()); } public void testValidOrdinals() { @@ -84,12 +93,4 @@ public class MemoryStatusTests extends ESTestCase { } } } - - public void testInvalidFromString() { - String statusName = randomAsciiOfLengthBetween(11, 20); - IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> { - MemoryStatus.fromString(statusName); - }); - assertThat(ex.getMessage(), containsString("Unknown MemoryStatus [" + statusName + "]")); - } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ModelDebugConfigWriterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ModelDebugConfigWriterTests.java index 3d3504b02e1..833146c334b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ModelDebugConfigWriterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ModelDebugConfigWriterTests.java @@ -37,7 +37,7 @@ public class ModelDebugConfigWriterTests extends ESTestCase { writer.write(); - verify(this.writer).write("writeto = FILE\nboundspercentile = 65.0\nterms = foo,bar\n"); + verify(this.writer).write("writeto = file\nboundspercentile = 65.0\nterms = foo,bar\n"); } public void testWrite_GivenFullConfig() throws IOException { @@ -46,7 +46,7 @@ public class ModelDebugConfigWriterTests extends ESTestCase { writer.write(); - verify(this.writer).write("writeto = DATA_STORE\nboundspercentile = 65.0\nterms = foo,bar\n"); + verify(this.writer).write("writeto = data_store\nboundspercentile = 65.0\nterms = foo,bar\n"); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/notifications/LevelTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/notifications/LevelTests.java index d8019848a60..40a61e087f8 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/notifications/LevelTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/notifications/LevelTests.java @@ -15,15 +15,22 @@ import static org.hamcrest.Matchers.equalTo; public class LevelTests extends ESTestCase { - public void testForString() { - assertEquals(Level.INFO, Level.forString("info")); - assertEquals(Level.INFO, Level.forString("INFO")); - assertEquals(Level.ACTIVITY, Level.forString("activity")); - assertEquals(Level.ACTIVITY, Level.forString("ACTIVITY")); - assertEquals(Level.WARNING, Level.forString("warning")); - assertEquals(Level.WARNING, Level.forString("WARNING")); - assertEquals(Level.ERROR, Level.forString("error")); - assertEquals(Level.ERROR, Level.forString("ERROR")); + public void testFromString() { + assertEquals(Level.INFO, Level.fromString("info")); + assertEquals(Level.INFO, Level.fromString("INFO")); + assertEquals(Level.ACTIVITY, Level.fromString("activity")); + assertEquals(Level.ACTIVITY, Level.fromString("ACTIVITY")); + assertEquals(Level.WARNING, Level.fromString("warning")); + assertEquals(Level.WARNING, Level.fromString("WARNING")); + assertEquals(Level.ERROR, Level.fromString("error")); + assertEquals(Level.ERROR, Level.fromString("ERROR")); + } + + public void testToString() { + assertEquals("info", Level.INFO.toString()); + assertEquals("activity", Level.ACTIVITY.toString()); + assertEquals("warning", Level.WARNING.toString()); + assertEquals("error", Level.ERROR.toString()); } public void testValidOrdinals() { diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml index 679ed076dcb..1bc4bca04d5 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/get_datafeed_stats.yaml @@ -66,13 +66,13 @@ setup: xpack.ml.get_datafeed_stats: datafeed_id: datafeed-1 - match: { datafeeds.0.datafeed_id: "datafeed-1"} - - match: { datafeeds.0.state: "STOPPED"} + - match: { datafeeds.0.state: "stopped"} - do: xpack.ml.get_datafeed_stats: datafeed_id: datafeed-2 - match: { datafeeds.0.datafeed_id: "datafeed-2"} - - match: { datafeeds.0.state: "STOPPED"} + - match: { datafeeds.0.state: "stopped"} --- "Test explicit get all datafeed stats": @@ -82,9 +82,9 @@ setup: datafeed_id: _all - match: { count: 2 } - match: { datafeeds.0.datafeed_id: "datafeed-1"} - - match: { datafeeds.0.state: "STOPPED"} + - match: { datafeeds.0.state: "stopped"} - match: { datafeeds.1.datafeed_id: "datafeed-2"} - - match: { datafeeds.1.state: "STOPPED"} + - match: { datafeeds.1.state: "stopped"} --- "Test implicit get all datafeed stats": @@ -93,6 +93,6 @@ setup: xpack.ml.get_datafeed_stats: {} - match: { count: 2 } - match: { datafeeds.0.datafeed_id: "datafeed-1"} - - match: { datafeeds.0.state: "STOPPED"} + - match: { datafeeds.0.state: "stopped"} - match: { datafeeds.1.datafeed_id: "datafeed-2"} - - match: { datafeeds.1.state: "STOPPED"} + - match: { datafeeds.1.state: "stopped"} diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml index 09c242443de..8e4a114dd4a 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/jobs_get_stats.yaml @@ -76,7 +76,7 @@ setup: - match: { jobs.0.data_counts.processed_field_count: 4} - match: { jobs.0.data_counts.input_field_count: 4 } - match: { jobs.0.model_size_stats.model_bytes: 0 } - - match: { jobs.0.state: OPENED } + - match: { jobs.0.state: opened } --- "Test get job stats for closed job": @@ -101,7 +101,7 @@ setup: - match: { jobs.0.data_counts.processed_field_count: 4} - match: { jobs.0.data_counts.input_field_count: 4 } - gt: { jobs.0.model_size_stats.model_bytes: 0 } - - match: { jobs.0.state: CLOSED } + - match: { jobs.0.state: closed } --- "Test get job stats of datafeed job that has not received and data": @@ -112,7 +112,7 @@ setup: - match: { jobs.0.job_id : datafeed-job } - match: { jobs.0.data_counts.processed_record_count: 0 } - match: { jobs.0.model_size_stats.model_bytes : 0 } - - match: { jobs.0.state: OPENED } + - match: { jobs.0.state: opened } --- "Test get all job stats explicitly": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml index 6aafbb7fd78..791fc6269d7 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/post_data.yaml @@ -68,7 +68,7 @@ setup: - do: xpack.ml.get_job_stats: job_id: farequote - - match: { jobs.0.state: "CLOSED" } + - match: { jobs.0.state: "closed" } - do: get: @@ -101,7 +101,7 @@ setup: - do: xpack.ml.get_job_stats: job_id: farequote - - match: { jobs.0.state: "CLOSED" } + - match: { jobs.0.state: "closed" } --- "Test POST data with invalid parameters": diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml index 6bf713012c7..03d86a30e26 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/start_stop_datafeed.yaml @@ -47,14 +47,14 @@ setup: - do: xpack.ml.get_datafeed_stats: datafeed_id: "datafeed-1" - - match: { datafeeds.0.state: STARTED } + - match: { datafeeds.0.state: started } - do: xpack.ml.stop_datafeed: "datafeed_id": "datafeed-1" - do: xpack.ml.get_datafeed_stats: datafeed_id: "datafeed-1" - - match: { datafeeds.0.state: STOPPED } + - match: { datafeeds.0.state: stopped } --- "Test start non existing datafeed": - do: @@ -71,7 +71,7 @@ setup: "datafeed_id": "datafeed-1" "start": 0 - do: - catch: /cannot start datafeed, expected job state \[OPENED\], but got \[CLOSED\]/ + catch: /cannot start datafeed, expected job state \[opened\], but got \[closed\]/ xpack.ml.start_datafeed: "datafeed_id": "datafeed-1" "start": 0 @@ -92,7 +92,7 @@ setup: "start": 0 - do: - catch: /datafeed already started, expected datafeed state \[STOPPED\], but got \[STARTED\]/ + catch: /datafeed already started, expected datafeed state \[stopped\], but got \[started\]/ xpack.ml.start_datafeed: "datafeed_id": "datafeed-1" "start": 0 @@ -111,6 +111,6 @@ setup: xpack.ml.stop_datafeed: "datafeed_id": "datafeed-1" - do: - catch: /datafeed already stopped, expected datafeed state \[STARTED\], but got \[STOPPED\]/ + catch: /datafeed already stopped, expected datafeed state \[started\], but got \[stopped\]/ xpack.ml.stop_datafeed: "datafeed_id": "datafeed-1"