Write enum values in lowercase (elastic/elasticsearch#861)
Original commit: elastic/x-pack-elasticsearch@6788ad3304
This commit is contained in:
parent
e7dcab48ab
commit
9b0344cd90
|
@ -32,4 +32,9 @@ public enum DatafeedState implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class Condition extends ToXContentToBytes implements Writeable {
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
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.field(FILTER_VALUE_FIELD.getPreferredName(), filterValue);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
|
|
@ -13,18 +13,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
|
|
||||||
public enum Connective implements Writeable {
|
public enum Connective implements Writeable {
|
||||||
OR("or"),
|
OR, AND;
|
||||||
AND("and");
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Connective(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive from string method.
|
* Case-insensitive from string method.
|
||||||
|
@ -49,4 +38,9 @@ public enum Connective implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,23 +40,14 @@ public class DataDescription extends ToXContentToBytes implements Writeable {
|
||||||
* Enum of the acceptable data formats.
|
* Enum of the acceptable data formats.
|
||||||
*/
|
*/
|
||||||
public enum DataFormat implements Writeable {
|
public enum DataFormat implements Writeable {
|
||||||
JSON("json"),
|
JSON,
|
||||||
DELIMITED("delimited");
|
DELIMITED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delimited used to be called delineated. We keep supporting that for backwards
|
* Delimited used to be called delineated. We keep supporting that for backwards
|
||||||
* compatibility.
|
* compatibility.
|
||||||
*/
|
*/
|
||||||
private static final String DEPRECATED_DELINEATED = "DELINEATED";
|
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.
|
* Case-insensitive from string method.
|
||||||
|
@ -83,6 +74,11 @@ public class DataDescription extends ToXContentToBytes implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ParseField DATA_DESCRIPTION_FIELD = new ParseField("data_description");
|
private static final ParseField DATA_DESCRIPTION_FIELD = new ParseField("data_description");
|
||||||
|
|
|
@ -68,7 +68,7 @@ public final class DefaultDetectorDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detector.getExcludeFrequent() != null) {
|
if (detector.getExcludeFrequent() != null) {
|
||||||
sb.append(EXCLUDE_FREQUENT_OPTION).append(detector.getExcludeFrequent().getToken());
|
sb.append(EXCLUDE_FREQUENT_OPTION).append(detector.getExcludeFrequent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class DetectionRule extends ToXContentToBytes implements Writeable {
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(CONDITIONS_CONNECTIVE_FIELD.getPreferredName(), conditionsConnective.getName());
|
builder.field(CONDITIONS_CONNECTIVE_FIELD.getPreferredName(), conditionsConnective);
|
||||||
builder.field(RULE_CONDITIONS_FIELD.getPreferredName(), ruleConditions);
|
builder.field(RULE_CONDITIONS_FIELD.getPreferredName(), ruleConditions);
|
||||||
if (targetFieldName != null) {
|
if (targetFieldName != null) {
|
||||||
builder.field(TARGET_FIELD_NAME_FIELD.getPreferredName(), targetFieldName);
|
builder.field(TARGET_FIELD_NAME_FIELD.getPreferredName(), targetFieldName);
|
||||||
|
|
|
@ -37,20 +37,10 @@ import java.util.stream.Collectors;
|
||||||
public class Detector extends ToXContentToBytes implements Writeable {
|
public class Detector extends ToXContentToBytes implements Writeable {
|
||||||
|
|
||||||
public enum ExcludeFrequent implements Writeable {
|
public enum ExcludeFrequent implements Writeable {
|
||||||
ALL("all"),
|
ALL,
|
||||||
NONE("none"),
|
NONE,
|
||||||
BY("by"),
|
BY,
|
||||||
OVER("over");
|
OVER;
|
||||||
|
|
||||||
private final String token;
|
|
||||||
|
|
||||||
ExcludeFrequent(String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive from string method.
|
* Case-insensitive from string method.
|
||||||
|
@ -75,6 +65,11 @@ public class Detector extends ToXContentToBytes implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ParseField DETECTOR_DESCRIPTION_FIELD = new ParseField("detector_description");
|
public static final ParseField DETECTOR_DESCRIPTION_FIELD = new ParseField("detector_description");
|
||||||
|
|
|
@ -48,4 +48,9 @@ public enum IgnoreDowntime implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,9 @@ public enum JobState implements Writeable {
|
||||||
public boolean isAnyOf(JobState... candidates) {
|
public boolean isAnyOf(JobState... candidates) {
|
||||||
return Arrays.stream(candidates).anyMatch(candidate -> this == candidate);
|
return Arrays.stream(candidates).anyMatch(candidate -> this == candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,7 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable {
|
||||||
* Enum of the acceptable output destinations.
|
* Enum of the acceptable output destinations.
|
||||||
*/
|
*/
|
||||||
public enum DebugDestination implements Writeable {
|
public enum DebugDestination implements Writeable {
|
||||||
FILE("file"),
|
FILE, DATA_STORE;
|
||||||
DATA_STORE("data_store");
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
DebugDestination(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive from string method. Works with FILE, File, file,
|
* Case-insensitive from string method. Works with FILE, File, file,
|
||||||
|
@ -45,9 +34,8 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable {
|
||||||
* String representation
|
* String representation
|
||||||
* @return The output destination
|
* @return The output destination
|
||||||
*/
|
*/
|
||||||
public static DebugDestination forString(String value) {
|
public static DebugDestination fromString(String value) {
|
||||||
String valueUpperCase = value.toUpperCase(Locale.ROOT);
|
return DebugDestination.valueOf(value.toUpperCase(Locale.ROOT));
|
||||||
return DebugDestination.valueOf(valueUpperCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugDestination readFromStream(StreamInput in) throws IOException {
|
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 {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double MAX_PERCENTILE = 100.0;
|
private static final double MAX_PERCENTILE = 100.0;
|
||||||
|
@ -80,7 +73,7 @@ public class ModelDebugConfig extends ToXContentToBytes implements Writeable {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
static {
|
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);
|
ValueType.STRING);
|
||||||
PARSER.declareDouble(ConstructingObjectParser.constructorArg(), BOUNDS_PERCENTILE_FIELD);
|
PARSER.declareDouble(ConstructingObjectParser.constructorArg(), BOUNDS_PERCENTILE_FIELD);
|
||||||
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), TERMS_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 {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
if (writeTo != null) {
|
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);
|
builder.field(BOUNDS_PERCENTILE_FIELD.getPreferredName(), boundsPercentile);
|
||||||
if (terms != null) {
|
if (terms != null) {
|
||||||
|
|
|
@ -22,37 +22,37 @@ import java.util.regex.Pattern;
|
||||||
* Enum representing logical comparisons on doubles
|
* Enum representing logical comparisons on doubles
|
||||||
*/
|
*/
|
||||||
public enum Operator implements Writeable {
|
public enum Operator implements Writeable {
|
||||||
EQ("eq") {
|
EQ {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(double lhs, double rhs) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return Double.compare(lhs, rhs) == 0;
|
return Double.compare(lhs, rhs) == 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GT("gt") {
|
GT {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(double lhs, double rhs) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return Double.compare(lhs, rhs) > 0;
|
return Double.compare(lhs, rhs) > 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GTE("gte") {
|
GTE {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(double lhs, double rhs) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return Double.compare(lhs, rhs) >= 0;
|
return Double.compare(lhs, rhs) >= 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LT("lt") {
|
LT {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(double lhs, double rhs) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return Double.compare(lhs, rhs) < 0;
|
return Double.compare(lhs, rhs) < 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LTE("lte") {
|
LTE {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(double lhs, double rhs) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return Double.compare(lhs, rhs) <= 0;
|
return Double.compare(lhs, rhs) <= 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MATCH("match") {
|
MATCH {
|
||||||
@Override
|
@Override
|
||||||
public boolean match(Pattern pattern, String field) {
|
public boolean match(Pattern pattern, String field) {
|
||||||
Matcher match = pattern.matcher(field);
|
Matcher match = pattern.matcher(field);
|
||||||
|
@ -66,15 +66,6 @@ public enum Operator implements Writeable {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final ParseField OPERATOR_FIELD = new ParseField("operator");
|
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) {
|
public boolean test(double lhs, double rhs) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -89,15 +80,7 @@ public enum Operator implements Writeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operator fromString(String name) {
|
public static Operator fromString(String name) {
|
||||||
Set<Operator> all = EnumSet.allOf(Operator.class);
|
return valueOf(name.trim().toUpperCase(Locale.ROOT));
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operator readFromStream(StreamInput in) throws IOException {
|
public static Operator readFromStream(StreamInput in) throws IOException {
|
||||||
|
@ -112,4 +95,9 @@ public enum Operator implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,12 @@ public enum RuleAction {
|
||||||
* @param value String representation
|
* @param value String representation
|
||||||
* @return The rule action
|
* @return The rule action
|
||||||
*/
|
*/
|
||||||
public static RuleAction forString(String value) {
|
public static RuleAction fromString(String value) {
|
||||||
return RuleAction.valueOf(value.toUpperCase(Locale.ROOT));
|
return RuleAction.valueOf(value.toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable {
|
||||||
static {
|
static {
|
||||||
PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> {
|
PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> {
|
||||||
if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
return RuleConditionType.forString(p.text());
|
return RuleConditionType.fromString(p.text());
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]");
|
throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]");
|
||||||
}, CONDITION_TYPE_FIELD, ValueType.STRING);
|
}, CONDITION_TYPE_FIELD, ValueType.STRING);
|
||||||
|
|
|
@ -14,20 +14,10 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
|
|
||||||
public enum RuleConditionType implements Writeable {
|
public enum RuleConditionType implements Writeable {
|
||||||
CATEGORICAL("categorical"),
|
CATEGORICAL,
|
||||||
NUMERICAL_ACTUAL("numerical_actual"),
|
NUMERICAL_ACTUAL,
|
||||||
NUMERICAL_TYPICAL("numerical_typical"),
|
NUMERICAL_TYPICAL,
|
||||||
NUMERICAL_DIFF_ABS("numerical_diff_abs");
|
NUMERICAL_DIFF_ABS;
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private RuleConditionType(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive from string method.
|
* Case-insensitive from string method.
|
||||||
|
@ -36,7 +26,7 @@ public enum RuleConditionType implements Writeable {
|
||||||
* String representation
|
* String representation
|
||||||
* @return The condition type
|
* @return The condition type
|
||||||
*/
|
*/
|
||||||
public static RuleConditionType forString(String value) {
|
public static RuleConditionType fromString(String value) {
|
||||||
return RuleConditionType.valueOf(value.toUpperCase(Locale.ROOT));
|
return RuleConditionType.valueOf(value.toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,4 +42,9 @@ public enum RuleConditionType implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_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_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_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."
|
public static final String JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_INVALID_OPTION = "job.config.detectionrule.condition."
|
||||||
+ "categorical.invalid.option";
|
+ "categorical.invalid.option";
|
||||||
public static final String JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_MISSING_OPTION = "job.config.detectionrule.condition."
|
public static final String JOB_CONFIG_DETECTION_RULE_CONDITION_CATEGORICAL_MISSING_OPTION = "job.config.detectionrule.condition."
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.elasticsearch.xpack.ml.utils.time.TimeUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,25 +89,10 @@ public class ModelSizeStats extends ToXContentToBytes implements Writeable {
|
||||||
* been dropped
|
* been dropped
|
||||||
*/
|
*/
|
||||||
public enum MemoryStatus implements Writeable {
|
public enum MemoryStatus implements Writeable {
|
||||||
OK("ok"), SOFT_LIMIT("soft_limit"), HARD_LIMIT("hard_limit");
|
OK, SOFT_LIMIT, HARD_LIMIT;
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private MemoryStatus(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MemoryStatus fromString(String statusName) {
|
public static MemoryStatus fromString(String statusName) {
|
||||||
for (MemoryStatus status : values()) {
|
return valueOf(statusName.trim().toUpperCase(Locale.ROOT));
|
||||||
if (status.name.equals(statusName)) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Unknown MemoryStatus [" + statusName + "]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MemoryStatus readFromStream(StreamInput in) throws IOException {
|
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 {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String jobId;
|
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_OVER_FIELD_COUNT_FIELD.getPreferredName(), totalOverFieldCount);
|
||||||
builder.field(TOTAL_PARTITION_FIELD_COUNT_FIELD.getPreferredName(), totalPartitionFieldCount);
|
builder.field(TOTAL_PARTITION_FIELD_COUNT_FIELD.getPreferredName(), totalPartitionFieldCount);
|
||||||
builder.field(BUCKET_ALLOCATION_FAILURES_COUNT_FIELD.getPreferredName(), bucketAllocationFailuresCount);
|
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());
|
builder.field(LOG_TIME_FIELD.getPreferredName(), logTime.getTime());
|
||||||
if (timestamp != null) {
|
if (timestamp != null) {
|
||||||
builder.field(TIMESTAMP_FIELD.getPreferredName(), timestamp.getTime());
|
builder.field(TIMESTAMP_FIELD.getPreferredName(), timestamp.getTime());
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class AuditMessage extends ToXContentToBytes implements Writeable {
|
||||||
PARSER.declareString(AuditMessage::setMessage, MESSAGE);
|
PARSER.declareString(AuditMessage::setMessage, MESSAGE);
|
||||||
PARSER.declareField(AuditMessage::setLevel, p -> {
|
PARSER.declareField(AuditMessage::setLevel, p -> {
|
||||||
if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
return Level.forString(p.text());
|
return Level.fromString(p.text());
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]");
|
throw new IllegalArgumentException("Unsupported token [" + p.currentToken() + "]");
|
||||||
}, LEVEL, ValueType.STRING);
|
}, LEVEL, ValueType.STRING);
|
||||||
|
|
|
@ -13,17 +13,7 @@ import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public enum Level implements Writeable {
|
public enum Level implements Writeable {
|
||||||
INFO("info"), ACTIVITY("activity"), WARNING("warning"), ERROR("error");
|
INFO, ACTIVITY, WARNING, ERROR;
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private Level(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Case-insensitive from string method.
|
* Case-insensitive from string method.
|
||||||
|
@ -32,7 +22,7 @@ public enum Level implements Writeable {
|
||||||
* String representation
|
* String representation
|
||||||
* @return The condition type
|
* @return The condition type
|
||||||
*/
|
*/
|
||||||
public static Level forString(String value) {
|
public static Level fromString(String value) {
|
||||||
return Level.valueOf(value.toUpperCase(Locale.ROOT));
|
return Level.valueOf(value.toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,4 +38,9 @@ public enum Level implements Writeable {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(ordinal());
|
out.writeVInt(ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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.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.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.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.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}''
|
job.config.detectionrule.condition.invalid.fieldname = Invalid detector rule: field_name has to be one of {0}; actual was ''{1}''
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class StartDatafeedActionRequestTests extends AbstractStreamableXContentT
|
||||||
.build();
|
.build();
|
||||||
e = expectThrows(ElasticsearchStatusException.class,
|
e = expectThrows(ElasticsearchStatusException.class,
|
||||||
() -> StartDatafeedAction.validate("foo-datafeed", mlMetadata2));
|
() -> 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]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,13 @@ public class DatafeedStateTests extends ESTestCase {
|
||||||
assertEquals(DatafeedState.fromString("stopped"), DatafeedState.STOPPED);
|
assertEquals(DatafeedState.fromString("stopped"), DatafeedState.STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToString() {
|
||||||
|
assertEquals("started", DatafeedState.STARTED.toString());
|
||||||
|
assertEquals("stopped", DatafeedState.STOPPED.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void testValidOrdinals() {
|
public void testValidOrdinals() {
|
||||||
assertEquals(0, DatafeedState.STARTED.ordinal());
|
assertEquals(0, DatafeedState.STARTED.ordinal());
|
||||||
assertEquals(1, DatafeedState.STOPPED.ordinal());
|
assertEquals(1, DatafeedState.STOPPED.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,7 +329,7 @@ public class DatafeedJobIT extends ESRestTestCase {
|
||||||
try {
|
try {
|
||||||
Response datafeedStatsResponse = client().performRequest("get",
|
Response datafeedStatsResponse = client().performRequest("get",
|
||||||
MlPlugin.BASE_PATH + "datafeeds/" + datafeedId + "/_stats");
|
MlPlugin.BASE_PATH + "datafeeds/" + datafeedId + "/_stats");
|
||||||
assertThat(responseEntityToString(datafeedStatsResponse), containsString("\"state\":\"STOPPED\""));
|
assertThat(responseEntityToString(datafeedStatsResponse), containsString("\"state\":\"stopped\""));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class TooManyJobsIT extends ESIntegTestCase {
|
||||||
logger.warn("Unexpected cause", e);
|
logger.warn("Unexpected cause", e);
|
||||||
}
|
}
|
||||||
assertEquals(IllegalArgumentException.class, cause.getClass());
|
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);
|
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
|
// now manually clean things up and see if we can succeed to run one new job
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ConditionTests extends AbstractSerializingTestCase<Condition> {
|
||||||
condition = new Condition(op, randomAsciiOfLengthBetween(1, 20));
|
condition = new Condition(op, randomAsciiOfLengthBetween(1, 20));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError("Unknown operator selected: " + op.getName());
|
throw new AssertionError("Unknown operator selected: " + op);
|
||||||
}
|
}
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,11 @@ public class ConnectiveTests extends ESTestCase {
|
||||||
assertEquals(Connective.AND, Connective.fromString("AND"));
|
assertEquals(Connective.AND, Connective.fromString("AND"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToString() {
|
||||||
|
assertEquals("or", Connective.OR.toString());
|
||||||
|
assertEquals("and", Connective.AND.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void testValidOrdinals() {
|
public void testValidOrdinals() {
|
||||||
assertThat(Connective.OR.ordinal(), equalTo(0));
|
assertThat(Connective.OR.ordinal(), equalTo(0));
|
||||||
assertThat(Connective.AND.ordinal(), equalTo(1));
|
assertThat(Connective.AND.ordinal(), equalTo(1));
|
||||||
|
|
|
@ -17,7 +17,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class DataFormatTests extends ESTestCase {
|
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("DELINEATED"));
|
assertEquals(DataFormat.DELIMITED, DataFormat.forString("DELINEATED"));
|
||||||
assertEquals(DataFormat.DELIMITED, DataFormat.forString("delimited"));
|
assertEquals(DataFormat.DELIMITED, DataFormat.forString("delimited"));
|
||||||
|
@ -27,6 +27,11 @@ public class DataFormatTests extends ESTestCase {
|
||||||
assertEquals(DataFormat.JSON, DataFormat.forString("JSON"));
|
assertEquals(DataFormat.JSON, DataFormat.forString("JSON"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToString() {
|
||||||
|
assertEquals("delimited", DataFormat.DELIMITED.toString());
|
||||||
|
assertEquals("json", DataFormat.JSON.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void testValidOrdinals() {
|
public void testValidOrdinals() {
|
||||||
assertThat(DataFormat.JSON.ordinal(), equalTo(0));
|
assertThat(DataFormat.JSON.ordinal(), equalTo(0));
|
||||||
assertThat(DataFormat.DELIMITED.ordinal(), equalTo(1));
|
assertThat(DataFormat.DELIMITED.ordinal(), equalTo(1));
|
||||||
|
|
|
@ -9,12 +9,18 @@ import org.elasticsearch.test.ESTestCase;
|
||||||
|
|
||||||
public class IgnoreDowntimeTests extends ESTestCase {
|
public class IgnoreDowntimeTests extends ESTestCase {
|
||||||
|
|
||||||
public void testForString() {
|
public void testFromString() {
|
||||||
assertEquals(IgnoreDowntime.fromString("always"), IgnoreDowntime.ALWAYS);
|
assertEquals(IgnoreDowntime.fromString("always"), IgnoreDowntime.ALWAYS);
|
||||||
assertEquals(IgnoreDowntime.fromString("never"), IgnoreDowntime.NEVER);
|
assertEquals(IgnoreDowntime.fromString("never"), IgnoreDowntime.NEVER);
|
||||||
assertEquals(IgnoreDowntime.fromString("once"), IgnoreDowntime.ONCE);
|
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() {
|
public void testValidOrdinals() {
|
||||||
assertEquals(0, IgnoreDowntime.NEVER.ordinal());
|
assertEquals(0, IgnoreDowntime.NEVER.ordinal());
|
||||||
assertEquals(1, IgnoreDowntime.ONCE.ordinal());
|
assertEquals(1, IgnoreDowntime.ONCE.ordinal());
|
||||||
|
@ -45,7 +51,6 @@ public class IgnoreDowntimeTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFromString_GivenNonMatchingString() {
|
public void testFromString_GivenNonMatchingString() {
|
||||||
ESTestCase.expectThrows(IllegalArgumentException.class,
|
ESTestCase.expectThrows(IllegalArgumentException.class, () -> IgnoreDowntime.fromString("nope"));
|
||||||
() -> IgnoreDowntime.fromString("nope"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,19 @@ public class JobStateTests extends ESTestCase {
|
||||||
assertEquals(JobState.fromString("failed"), JobState.FAILED);
|
assertEquals(JobState.fromString("failed"), JobState.FAILED);
|
||||||
assertEquals(JobState.fromString("opening"), JobState.OPENING);
|
assertEquals(JobState.fromString("opening"), JobState.OPENING);
|
||||||
assertEquals(JobState.fromString("opened"), JobState.OPENED);
|
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() {
|
public void testValidOrdinals() {
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.ml.job.config;
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.ml.job.messages.Messages;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -18,7 +17,6 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class OperatorTests extends ESTestCase {
|
public class OperatorTests extends ESTestCase {
|
||||||
|
|
||||||
|
|
||||||
public void testFromString() {
|
public void testFromString() {
|
||||||
assertEquals(Operator.fromString("eq"), Operator.EQ);
|
assertEquals(Operator.fromString("eq"), Operator.EQ);
|
||||||
assertEquals(Operator.fromString("gt"), Operator.GT);
|
assertEquals(Operator.fromString("gt"), Operator.GT);
|
||||||
|
@ -30,9 +28,16 @@ public class OperatorTests extends ESTestCase {
|
||||||
assertEquals(Operator.fromString("EQ"), Operator.EQ);
|
assertEquals(Operator.fromString("EQ"), Operator.EQ);
|
||||||
assertEquals(Operator.fromString("GTE"), Operator.GTE);
|
assertEquals(Operator.fromString("GTE"), Operator.GTE);
|
||||||
assertEquals(Operator.fromString("Match"), Operator.MATCH);
|
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() {
|
public void testTest() {
|
||||||
assertTrue(Operator.GT.expectsANumericArgument());
|
assertTrue(Operator.GT.expectsANumericArgument());
|
||||||
|
@ -58,7 +63,6 @@ public class OperatorTests extends ESTestCase {
|
||||||
assertFalse(Operator.LTE.test(1.0, 0.0));
|
assertFalse(Operator.LTE.test(1.0, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testMatch() {
|
public void testMatch() {
|
||||||
assertFalse(Operator.MATCH.expectsANumericArgument());
|
assertFalse(Operator.MATCH.expectsANumericArgument());
|
||||||
assertFalse(Operator.MATCH.test(0.0, 1.0));
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -10,8 +10,12 @@ import org.elasticsearch.test.ESTestCase;
|
||||||
public class RuleActionTests extends ESTestCase {
|
public class RuleActionTests extends ESTestCase {
|
||||||
|
|
||||||
public void testForString() {
|
public void testForString() {
|
||||||
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("filter_results"));
|
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("filter_results"));
|
||||||
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("FILTER_RESULTS"));
|
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("FILTER_RESULTS"));
|
||||||
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.forString("fiLTer_Results"));
|
assertEquals(RuleAction.FILTER_RESULTS, RuleAction.fromString("fiLTer_Results"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testToString() {
|
||||||
|
assertEquals("filter_results", RuleAction.FILTER_RESULTS.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,14 +180,14 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
|
||||||
Condition condition = new Condition(Operator.EQ, "5");
|
Condition condition = new Condition(Operator.EQ, "5");
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, condition, null));
|
() -> 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() {
|
public void testVerify_GivenNumericalAndOperatorMatch() {
|
||||||
Condition condition = new Condition(Operator.MATCH, "aaa");
|
Condition condition = new Condition(Operator.MATCH, "aaa");
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, condition, null));
|
() -> 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() {
|
public void testVerify_GivenDetectionRuleWithInvalidCondition() {
|
||||||
|
|
|
@ -16,15 +16,22 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class RuleConditionTypeTests extends ESTestCase {
|
public class RuleConditionTypeTests extends ESTestCase {
|
||||||
|
|
||||||
public void testForString() {
|
public void testFromString() {
|
||||||
assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.forString("categorical"));
|
assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.fromString("categorical"));
|
||||||
assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.forString("CATEGORICAL"));
|
assertEquals(RuleConditionType.CATEGORICAL, RuleConditionType.fromString("CATEGORICAL"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.forString("numerical_actual"));
|
assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.fromString("numerical_actual"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.forString("NUMERICAL_ACTUAL"));
|
assertEquals(RuleConditionType.NUMERICAL_ACTUAL, RuleConditionType.fromString("NUMERICAL_ACTUAL"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.forString("numerical_typical"));
|
assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.fromString("numerical_typical"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.forString("NUMERICAL_TYPICAL"));
|
assertEquals(RuleConditionType.NUMERICAL_TYPICAL, RuleConditionType.fromString("NUMERICAL_TYPICAL"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.forString("numerical_diff_abs"));
|
assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.fromString("numerical_diff_abs"));
|
||||||
assertEquals(RuleConditionType.NUMERICAL_DIFF_ABS, RuleConditionType.forString("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() {
|
public void testValidOrdinals() {
|
||||||
|
|
|
@ -18,9 +18,18 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
public class MemoryStatusTests extends ESTestCase {
|
public class MemoryStatusTests extends ESTestCase {
|
||||||
|
|
||||||
public void testFromString() {
|
public void testFromString() {
|
||||||
assertEquals(MemoryStatus.OK, MemoryStatus.fromString(MemoryStatus.OK.getName()));
|
assertEquals(MemoryStatus.OK, MemoryStatus.fromString("ok"));
|
||||||
assertEquals(MemoryStatus.SOFT_LIMIT, MemoryStatus.fromString(MemoryStatus.SOFT_LIMIT.getName()));
|
assertEquals(MemoryStatus.SOFT_LIMIT, MemoryStatus.fromString("soft_limit"));
|
||||||
assertEquals(MemoryStatus.HARD_LIMIT, MemoryStatus.fromString(MemoryStatus.HARD_LIMIT.getName()));
|
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() {
|
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 + "]"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class ModelDebugConfigWriterTests extends ESTestCase {
|
||||||
|
|
||||||
writer.write();
|
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 {
|
public void testWrite_GivenFullConfig() throws IOException {
|
||||||
|
@ -46,7 +46,7 @@ public class ModelDebugConfigWriterTests extends ESTestCase {
|
||||||
|
|
||||||
writer.write();
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,22 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class LevelTests extends ESTestCase {
|
public class LevelTests extends ESTestCase {
|
||||||
|
|
||||||
public void testForString() {
|
public void testFromString() {
|
||||||
assertEquals(Level.INFO, Level.forString("info"));
|
assertEquals(Level.INFO, Level.fromString("info"));
|
||||||
assertEquals(Level.INFO, Level.forString("INFO"));
|
assertEquals(Level.INFO, Level.fromString("INFO"));
|
||||||
assertEquals(Level.ACTIVITY, Level.forString("activity"));
|
assertEquals(Level.ACTIVITY, Level.fromString("activity"));
|
||||||
assertEquals(Level.ACTIVITY, Level.forString("ACTIVITY"));
|
assertEquals(Level.ACTIVITY, Level.fromString("ACTIVITY"));
|
||||||
assertEquals(Level.WARNING, Level.forString("warning"));
|
assertEquals(Level.WARNING, Level.fromString("warning"));
|
||||||
assertEquals(Level.WARNING, Level.forString("WARNING"));
|
assertEquals(Level.WARNING, Level.fromString("WARNING"));
|
||||||
assertEquals(Level.ERROR, Level.forString("error"));
|
assertEquals(Level.ERROR, Level.fromString("error"));
|
||||||
assertEquals(Level.ERROR, Level.forString("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() {
|
public void testValidOrdinals() {
|
||||||
|
|
|
@ -66,13 +66,13 @@ setup:
|
||||||
xpack.ml.get_datafeed_stats:
|
xpack.ml.get_datafeed_stats:
|
||||||
datafeed_id: datafeed-1
|
datafeed_id: datafeed-1
|
||||||
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
|
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
|
||||||
- match: { datafeeds.0.state: "STOPPED"}
|
- match: { datafeeds.0.state: "stopped"}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_datafeed_stats:
|
xpack.ml.get_datafeed_stats:
|
||||||
datafeed_id: datafeed-2
|
datafeed_id: datafeed-2
|
||||||
- match: { datafeeds.0.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":
|
"Test explicit get all datafeed stats":
|
||||||
|
@ -82,9 +82,9 @@ setup:
|
||||||
datafeed_id: _all
|
datafeed_id: _all
|
||||||
- match: { count: 2 }
|
- match: { count: 2 }
|
||||||
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
|
- 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.datafeed_id: "datafeed-2"}
|
||||||
- match: { datafeeds.1.state: "STOPPED"}
|
- match: { datafeeds.1.state: "stopped"}
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test implicit get all datafeed stats":
|
"Test implicit get all datafeed stats":
|
||||||
|
@ -93,6 +93,6 @@ setup:
|
||||||
xpack.ml.get_datafeed_stats: {}
|
xpack.ml.get_datafeed_stats: {}
|
||||||
- match: { count: 2 }
|
- match: { count: 2 }
|
||||||
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
|
- 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.datafeed_id: "datafeed-2"}
|
||||||
- match: { datafeeds.1.state: "STOPPED"}
|
- match: { datafeeds.1.state: "stopped"}
|
||||||
|
|
|
@ -76,7 +76,7 @@ setup:
|
||||||
- match: { jobs.0.data_counts.processed_field_count: 4}
|
- match: { jobs.0.data_counts.processed_field_count: 4}
|
||||||
- match: { jobs.0.data_counts.input_field_count: 4 }
|
- match: { jobs.0.data_counts.input_field_count: 4 }
|
||||||
- match: { jobs.0.model_size_stats.model_bytes: 0 }
|
- 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":
|
"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.processed_field_count: 4}
|
||||||
- match: { jobs.0.data_counts.input_field_count: 4 }
|
- match: { jobs.0.data_counts.input_field_count: 4 }
|
||||||
- gt: { jobs.0.model_size_stats.model_bytes: 0 }
|
- 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":
|
"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.job_id : datafeed-job }
|
||||||
- match: { jobs.0.data_counts.processed_record_count: 0 }
|
- match: { jobs.0.data_counts.processed_record_count: 0 }
|
||||||
- match: { jobs.0.model_size_stats.model_bytes : 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":
|
"Test get all job stats explicitly":
|
||||||
|
|
|
@ -68,7 +68,7 @@ setup:
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_job_stats:
|
xpack.ml.get_job_stats:
|
||||||
job_id: farequote
|
job_id: farequote
|
||||||
- match: { jobs.0.state: "CLOSED" }
|
- match: { jobs.0.state: "closed" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
get:
|
get:
|
||||||
|
@ -101,7 +101,7 @@ setup:
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_job_stats:
|
xpack.ml.get_job_stats:
|
||||||
job_id: farequote
|
job_id: farequote
|
||||||
- match: { jobs.0.state: "CLOSED" }
|
- match: { jobs.0.state: "closed" }
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test POST data with invalid parameters":
|
"Test POST data with invalid parameters":
|
||||||
|
|
|
@ -47,14 +47,14 @@ setup:
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_datafeed_stats:
|
xpack.ml.get_datafeed_stats:
|
||||||
datafeed_id: "datafeed-1"
|
datafeed_id: "datafeed-1"
|
||||||
- match: { datafeeds.0.state: STARTED }
|
- match: { datafeeds.0.state: started }
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.stop_datafeed:
|
xpack.ml.stop_datafeed:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_datafeed_stats:
|
xpack.ml.get_datafeed_stats:
|
||||||
datafeed_id: "datafeed-1"
|
datafeed_id: "datafeed-1"
|
||||||
- match: { datafeeds.0.state: STOPPED }
|
- match: { datafeeds.0.state: stopped }
|
||||||
---
|
---
|
||||||
"Test start non existing datafeed":
|
"Test start non existing datafeed":
|
||||||
- do:
|
- do:
|
||||||
|
@ -71,7 +71,7 @@ setup:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
"start": 0
|
"start": 0
|
||||||
- do:
|
- 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:
|
xpack.ml.start_datafeed:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
"start": 0
|
"start": 0
|
||||||
|
@ -92,7 +92,7 @@ setup:
|
||||||
"start": 0
|
"start": 0
|
||||||
|
|
||||||
- do:
|
- 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:
|
xpack.ml.start_datafeed:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
"start": 0
|
"start": 0
|
||||||
|
@ -111,6 +111,6 @@ setup:
|
||||||
xpack.ml.stop_datafeed:
|
xpack.ml.stop_datafeed:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
- do:
|
- 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:
|
xpack.ml.stop_datafeed:
|
||||||
"datafeed_id": "datafeed-1"
|
"datafeed_id": "datafeed-1"
|
||||||
|
|
Loading…
Reference in New Issue