diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java index 58e69bfab13..7197189d69f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/MlPlugin.java @@ -35,7 +35,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.ml.action.CloseJobAction; import org.elasticsearch.xpack.ml.action.DeleteJobAction; -import org.elasticsearch.xpack.ml.action.DeleteListAction; +import org.elasticsearch.xpack.ml.action.DeleteFilterAction; import org.elasticsearch.xpack.ml.action.DeleteModelSnapshotAction; import org.elasticsearch.xpack.ml.action.DeleteDatafeedAction; import org.elasticsearch.xpack.ml.action.FlushJobAction; @@ -44,7 +44,7 @@ import org.elasticsearch.xpack.ml.action.GetCategoriesAction; import org.elasticsearch.xpack.ml.action.GetInfluencersAction; import org.elasticsearch.xpack.ml.action.GetJobsAction; import org.elasticsearch.xpack.ml.action.GetJobsStatsAction; -import org.elasticsearch.xpack.ml.action.GetListAction; +import org.elasticsearch.xpack.ml.action.GetFiltersAction; import org.elasticsearch.xpack.ml.action.GetModelSnapshotsAction; import org.elasticsearch.xpack.ml.action.GetRecordsAction; import org.elasticsearch.xpack.ml.action.GetDatafeedsAction; @@ -54,7 +54,7 @@ import org.elasticsearch.xpack.ml.action.InternalOpenJobAction; import org.elasticsearch.xpack.ml.action.OpenJobAction; import org.elasticsearch.xpack.ml.action.PostDataAction; import org.elasticsearch.xpack.ml.action.PutJobAction; -import org.elasticsearch.xpack.ml.action.PutListAction; +import org.elasticsearch.xpack.ml.action.PutFilterAction; import org.elasticsearch.xpack.ml.action.PutDatafeedAction; import org.elasticsearch.xpack.ml.action.RevertModelSnapshotAction; import org.elasticsearch.xpack.ml.action.StartDatafeedAction; @@ -85,6 +85,9 @@ import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerFactory; import org.elasticsearch.xpack.ml.job.process.normalizer.NormalizerProcessFactory; import org.elasticsearch.xpack.ml.job.process.DataCountsReporter; import org.elasticsearch.xpack.ml.job.usage.UsageReporter; +import org.elasticsearch.xpack.ml.rest.filter.RestDeleteFilterAction; +import org.elasticsearch.xpack.ml.rest.filter.RestGetFiltersAction; +import org.elasticsearch.xpack.ml.rest.filter.RestPutFilterAction; import org.elasticsearch.xpack.ml.rest.job.RestCloseJobAction; import org.elasticsearch.xpack.ml.rest.job.RestDeleteJobAction; import org.elasticsearch.xpack.ml.rest.job.RestFlushJobAction; @@ -93,9 +96,6 @@ import org.elasticsearch.xpack.ml.rest.job.RestGetJobStatsAction; import org.elasticsearch.xpack.ml.rest.job.RestOpenJobAction; import org.elasticsearch.xpack.ml.rest.job.RestPostDataAction; import org.elasticsearch.xpack.ml.rest.job.RestPutJobAction; -import org.elasticsearch.xpack.ml.rest.list.RestDeleteListAction; -import org.elasticsearch.xpack.ml.rest.list.RestGetListAction; -import org.elasticsearch.xpack.ml.rest.list.RestPutListAction; import org.elasticsearch.xpack.ml.rest.modelsnapshots.RestDeleteModelSnapshotAction; import org.elasticsearch.xpack.ml.rest.modelsnapshots.RestGetModelSnapshotsAction; import org.elasticsearch.xpack.ml.rest.modelsnapshots.RestRevertModelSnapshotAction; @@ -195,7 +195,7 @@ public class MlPlugin extends Plugin implements ActionPlugin { throw new ElasticsearchException("Failed to create native process factories", e); } } else { - autodetectProcessFactory = (jobDetails, modelSnapshot, quantiles, lists, ignoreDowntime, executorService) -> + autodetectProcessFactory = (jobDetails, modelSnapshot, quantiles, filters, ignoreDowntime, executorService) -> new BlackHoleAutodetectProcess(); // factor of 1.0 makes renormalization a no-op normalizerProcessFactory = (jobId, quantilesState, bucketSpan, perPartitionNormalization, @@ -231,9 +231,9 @@ public class MlPlugin extends Plugin implements ActionPlugin { new RestPutJobAction(settings, restController), new RestDeleteJobAction(settings, restController), new RestOpenJobAction(settings, restController), - new RestGetListAction(settings, restController), - new RestPutListAction(settings, restController), - new RestDeleteListAction(settings, restController), + new RestGetFiltersAction(settings, restController), + new RestPutFilterAction(settings, restController), + new RestDeleteFilterAction(settings, restController), new RestGetInfluencersAction(settings, restController), new RestGetRecordsAction(settings, restController), new RestGetBucketsAction(settings, restController), @@ -268,9 +268,9 @@ public class MlPlugin extends Plugin implements ActionPlugin { new ActionHandler<>(InternalOpenJobAction.INSTANCE, InternalOpenJobAction.TransportAction.class), new ActionHandler<>(UpdateJobStatusAction.INSTANCE, UpdateJobStatusAction.TransportAction.class), new ActionHandler<>(UpdateDatafeedStatusAction.INSTANCE, UpdateDatafeedStatusAction.TransportAction.class), - new ActionHandler<>(GetListAction.INSTANCE, GetListAction.TransportAction.class), - new ActionHandler<>(PutListAction.INSTANCE, PutListAction.TransportAction.class), - new ActionHandler<>(DeleteListAction.INSTANCE, DeleteListAction.TransportAction.class), + new ActionHandler<>(GetFiltersAction.INSTANCE, GetFiltersAction.TransportAction.class), + new ActionHandler<>(PutFilterAction.INSTANCE, PutFilterAction.TransportAction.class), + new ActionHandler<>(DeleteFilterAction.INSTANCE, DeleteFilterAction.TransportAction.class), new ActionHandler<>(GetBucketsAction.INSTANCE, GetBucketsAction.TransportAction.class), new ActionHandler<>(GetInfluencersAction.INSTANCE, GetInfluencersAction.TransportAction.class), new ActionHandler<>(GetRecordsAction.INSTANCE, GetRecordsAction.TransportAction.class), diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteListAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteFilterAction.java similarity index 82% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteListAction.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteFilterAction.java index 2abe972b917..ae07393c0b5 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteListAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/DeleteFilterAction.java @@ -34,7 +34,7 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.ml.job.config.Detector; import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.metadata.MlMetadata; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.utils.ExceptionsHelper; import java.io.IOException; @@ -44,12 +44,12 @@ import java.util.Map; import java.util.Objects; -public class DeleteListAction extends Action { +public class DeleteFilterAction extends Action { - public static final DeleteListAction INSTANCE = new DeleteListAction(); - public static final String NAME = "cluster:admin/ml/list/delete"; + public static final DeleteFilterAction INSTANCE = new DeleteFilterAction(); + public static final String NAME = "cluster:admin/ml/filter/delete"; - private DeleteListAction() { + private DeleteFilterAction() { super(NAME); } @@ -65,20 +65,20 @@ public class DeleteListAction extends Action { - public static final ParseField LIST_ID = new ParseField("list_id"); + public static final ParseField FILTER_ID = new ParseField("filter_id"); - private String listId; + private String filterId; Request() { } - public Request(String listId) { - this.listId = ExceptionsHelper.requireNonNull(listId, LIST_ID.getPreferredName()); + public Request(String filterId) { + this.filterId = ExceptionsHelper.requireNonNull(filterId, FILTER_ID.getPreferredName()); } - public String getListId() { - return listId; + public String getFilterId() { + return filterId; } @Override @@ -89,18 +89,18 @@ public class DeleteListAction extends Action { - public RequestBuilder(ElasticsearchClient client, DeleteListAction action) { + public RequestBuilder(ElasticsearchClient client, DeleteFilterAction action) { super(client, action, new Request()); } } @@ -153,7 +153,7 @@ public class DeleteListAction extends Action listener) throws Exception { - final String listId = request.getListId(); + final String filterId = request.getFilterId(); MlMetadata currentMlMetadata = state.metaData().custom(MlMetadata.TYPE); Map jobs = currentMlMetadata.getJobs(); List currentlyUsedBy = new ArrayList<>(); for (Job job : jobs.values()) { List detectors = job.getAnalysisConfig().getDetectors(); for (Detector detector : detectors) { - if (detector.extractReferencedLists().contains(listId)) { + if (detector.extractReferencedFilters().contains(filterId)) { currentlyUsedBy.add(job.getId()); break; } } } if (!currentlyUsedBy.isEmpty()) { - throw ExceptionsHelper.conflictStatusException("Cannot delete List, currently used by jobs: " + throw ExceptionsHelper.conflictStatusException("Cannot delete filter, currently used by jobs: " + currentlyUsedBy); } - DeleteRequest deleteRequest = new DeleteRequest(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), listId); + DeleteRequest deleteRequest = new DeleteRequest(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), filterId); transportAction.execute(deleteRequest, new ActionListener() { @Override public void onResponse(DeleteResponse deleteResponse) { if (deleteResponse.status().equals(RestStatus.NOT_FOUND)) { - listener.onFailure(new ResourceNotFoundException("Could not delete list with ID [" + listId + listener.onFailure(new ResourceNotFoundException("Could not delete filter with ID [" + filterId + "] because it does not exist")); } else { listener.onResponse(new Response(true)); @@ -203,8 +203,8 @@ public class DeleteListAction extends Action { +public class GetFiltersAction extends Action { - public static final GetListAction INSTANCE = new GetListAction(); - public static final String NAME = "cluster:admin/ml/list/get"; + public static final GetFiltersAction INSTANCE = new GetFiltersAction(); + public static final String NAME = "cluster:admin/ml/filters/get"; - private GetListAction() { + private GetFiltersAction() { super(NAME); } @@ -75,22 +75,22 @@ public class GetListAction extends Action { - private String listId; + private String filterId; private PageParams pageParams; public Request() { } - public void setListId(String listId) { + public void setFilterId(String filterId) { if (pageParams != null) { - throw new IllegalArgumentException("Param [" + ListDocument.ID.getPreferredName() + "] is incompatible with [" + throw new IllegalArgumentException("Param [" + MlFilter.ID.getPreferredName() + "] is incompatible with [" + PageParams.FROM.getPreferredName()+ ", " + PageParams.SIZE.getPreferredName() + "]."); } - this.listId = listId; + this.filterId = filterId; } - public String getListId() { - return listId; + public String getFilterId() { + return filterId; } public PageParams getPageParams() { @@ -98,10 +98,10 @@ public class GetListAction extends Action { - public RequestBuilder(ElasticsearchClient client, GetListAction action) { + public RequestBuilder(ElasticsearchClient client, GetFiltersAction action) { super(client, action, new Request()); } } public static class Response extends ActionResponse implements StatusToXContentObject { - private QueryPage lists; + private QueryPage filters; - public Response(QueryPage lists) { - this.lists = lists; + public Response(QueryPage filters) { + this.filters = filters; } Response() { } - public QueryPage getLists() { - return lists; + public QueryPage getFilters() { + return filters; } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - lists = new QueryPage<>(in, ListDocument::new); + filters = new QueryPage<>(in, MlFilter::new); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - lists.writeTo(out); + filters.writeTo(out); } @Override @@ -189,14 +189,14 @@ public class GetListAction extends Action listener) throws Exception { - final String listId = request.getListId(); - if (!Strings.isNullOrEmpty(listId)) { - getList(listId, listener); + final String filterId = request.getFilterId(); + if (!Strings.isNullOrEmpty(filterId)) { + getFilter(filterId, listener); } else if (request.getPageParams() != null) { - getLists(request.getPageParams(), listener); + getFilters(request.getPageParams(), listener); } else { - throw new IllegalStateException("Both listId and pageParams are null"); + throw new IllegalStateException("Both filterId and pageParams are null"); } } @@ -273,25 +273,25 @@ public class GetListAction extends Action listener) { - GetRequest getRequest = new GetRequest(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), listId); + private void getFilter(String filterId, ActionListener listener) { + GetRequest getRequest = new GetRequest(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), filterId); transportGetAction.execute(getRequest, new ActionListener() { @Override public void onResponse(GetResponse getDocResponse) { try { - QueryPage responseBody; + QueryPage responseBody; if (getDocResponse.isExists()) { BytesReference docSource = getDocResponse.getSourceAsBytesRef(); XContentParser parser = XContentFactory.xContent(docSource).createParser(NamedXContentRegistry.EMPTY, docSource); - ListDocument listDocument = ListDocument.PARSER.apply(parser, null); - responseBody = new QueryPage<>(Collections.singletonList(listDocument), 1, ListDocument.RESULTS_FIELD); + MlFilter filter = MlFilter.PARSER.apply(parser, null); + responseBody = new QueryPage<>(Collections.singletonList(filter), 1, MlFilter.RESULTS_FIELD); - Response listResponse = new Response(responseBody); - listener.onResponse(listResponse); + Response filterResponse = new Response(responseBody); + listener.onResponse(filterResponse); } else { - this.onFailure(QueryPage.emptyQueryPage(ListDocument.RESULTS_FIELD)); + this.onFailure(QueryPage.emptyQueryPage(MlFilter.RESULTS_FIELD)); } } catch (Exception e) { @@ -306,29 +306,29 @@ public class GetListAction extends Action listener) { + private void getFilters(PageParams pageParams, ActionListener listener) { SearchSourceBuilder sourceBuilder = new SearchSourceBuilder() .from(pageParams.getFrom()) .size(pageParams.getSize()); SearchRequest searchRequest = new SearchRequest(new String[]{ML_INFO_INDEX}, sourceBuilder) - .types(ListDocument.TYPE.getPreferredName()); + .types(MlFilter.TYPE.getPreferredName()); transportSearchAction.execute(searchRequest, new ActionListener() { @Override public void onResponse(SearchResponse response) { try { - List docs = new ArrayList<>(); + List docs = new ArrayList<>(); for (SearchHit hit : response.getHits().getHits()) { BytesReference docSource = hit.sourceRef(); XContentParser parser = XContentFactory.xContent(docSource).createParser(NamedXContentRegistry.EMPTY, docSource); - docs.add(ListDocument.PARSER.apply(parser, null)); + docs.add(MlFilter.PARSER.apply(parser, null)); } - Response listResponse = new Response(new QueryPage<>(docs, docs.size(), ListDocument.RESULTS_FIELD)); - listener.onResponse(listResponse); + Response filterResponse = new Response(new QueryPage<>(docs, docs.size(), MlFilter.RESULTS_FIELD)); + listener.onResponse(filterResponse); } catch (Exception e) { this.onFailure(e); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutListAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java similarity index 79% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutListAction.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java index c8060e56046..f551b993214 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutListAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java @@ -33,19 +33,19 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.utils.ExceptionsHelper; import java.io.IOException; import java.util.Objects; -public class PutListAction extends Action { +public class PutFilterAction extends Action { - public static final PutListAction INSTANCE = new PutListAction(); - public static final String NAME = "cluster:admin/ml/list/put"; + public static final PutFilterAction INSTANCE = new PutFilterAction(); + public static final String NAME = "cluster:admin/ml/filter/put"; - private PutListAction() { + private PutFilterAction() { super(NAME); } @@ -62,22 +62,22 @@ public class PutListAction extends Action implements ToXContent { public static Request parseRequest(XContentParser parser) { - ListDocument listDocument = ListDocument.PARSER.apply(parser, null); - return new Request(listDocument); + MlFilter filter = MlFilter.PARSER.apply(parser, null); + return new Request(filter); } - private ListDocument listDocument; + private MlFilter filter; Request() { } - public Request(ListDocument listDocument) { - this.listDocument = ExceptionsHelper.requireNonNull(listDocument, "list_document"); + public Request(MlFilter filter) { + this.filter = ExceptionsHelper.requireNonNull(filter, "filter"); } - public ListDocument getListDocument() { - return this.listDocument; + public MlFilter getFilter() { + return this.filter; } @Override @@ -88,24 +88,24 @@ public class PutListAction extends Action { - public RequestBuilder(ElasticsearchClient client, PutListAction action) { + public RequestBuilder(ElasticsearchClient client, PutFilterAction action) { super(client, action, new Request()); } } @@ -160,7 +160,7 @@ public class PutListAction extends Action listener) throws Exception { - ListDocument listDocument = request.getListDocument(); - final String listId = listDocument.getId(); - IndexRequest indexRequest = new IndexRequest(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), listId); + MlFilter filter = request.getFilter(); + final String filterId = filter.getId(); + IndexRequest indexRequest = new IndexRequest(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), filterId); XContentBuilder builder = XContentFactory.jsonBuilder(); - indexRequest.source(listDocument.toXContent(builder, ToXContent.EMPTY_PARAMS)); + indexRequest.source(filter.toXContent(builder, ToXContent.EMPTY_PARAMS)); transportIndexAction.execute(indexRequest, new ActionListener() { @Override public void onResponse(IndexResponse indexResponse) { @@ -190,8 +190,8 @@ public class PutListAction extends Action extractReferencedLists() { - return detectors.stream().map(Detector::extractReferencedLists) + public Set extractReferencedFilters() { + return detectors.stream().map(Detector::extractReferencedFilters) .flatMap(Set::stream).collect(Collectors.toSet()); } 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 2895bd8da22..817f46cfb87 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 @@ -141,8 +141,8 @@ public class DetectionRule extends ToXContentToBytes implements Writeable { return ruleConditions; } - public Set extractReferencedLists() { - return ruleConditions.stream().map(RuleCondition::getValueList).filter(Objects::nonNull).collect(Collectors.toSet()); + public Set extractReferencedFilters() { + return ruleConditions.stream().map(RuleCondition::getValueFilter).filter(Objects::nonNull).collect(Collectors.toSet()); } @Override 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 b01f2b983e6..9b01535ddee 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 @@ -473,9 +473,9 @@ public class Detector extends ToXContentToBytes implements Writeable { return analysisFields.stream().filter(item -> item != null).collect(Collectors.toList()); } - public Set extractReferencedLists() { + public Set extractReferencedFilters() { return detectorRules == null ? Collections.emptySet() - : detectorRules.stream().map(DetectionRule::extractReferencedLists) + : detectorRules.stream().map(DetectionRule::extractReferencedFilters) .flatMap(Set::stream).collect(Collectors.toSet()); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ListDocument.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/MlFilter.java similarity index 81% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ListDocument.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/MlFilter.java index 480df79d60e..fca5bda18b8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/ListDocument.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/config/MlFilter.java @@ -19,17 +19,17 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -public class ListDocument extends ToXContentToBytes implements Writeable { - public static final ParseField TYPE = new ParseField("list"); +public class MlFilter extends ToXContentToBytes implements Writeable { + public static final ParseField TYPE = new ParseField("filter"); public static final ParseField ID = new ParseField("id"); public static final ParseField ITEMS = new ParseField("items"); // For QueryPage - public static final ParseField RESULTS_FIELD = new ParseField("lists"); + public static final ParseField RESULTS_FIELD = new ParseField("filters"); @SuppressWarnings("unchecked") - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - TYPE.getPreferredName(), a -> new ListDocument((String) a[0], (List) a[1])); + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + TYPE.getPreferredName(), a -> new MlFilter((String) a[0], (List) a[1])); static { PARSER.declareString(ConstructingObjectParser.constructorArg(), ID); @@ -39,12 +39,12 @@ public class ListDocument extends ToXContentToBytes implements Writeable { private final String id; private final List items; - public ListDocument(String id, List items) { + public MlFilter(String id, List items) { this.id = Objects.requireNonNull(id, ID.getPreferredName() + " must not be null"); this.items = Objects.requireNonNull(items, ITEMS.getPreferredName() + " must not be null"); } - public ListDocument(StreamInput in) throws IOException { + public MlFilter(StreamInput in) throws IOException { id = in.readString(); items = Arrays.asList(in.readStringArray()); } @@ -78,11 +78,11 @@ public class ListDocument extends ToXContentToBytes implements Writeable { return true; } - if (!(obj instanceof ListDocument)) { + if (!(obj instanceof MlFilter)) { return false; } - ListDocument other = (ListDocument) obj; + MlFilter other = (MlFilter) obj; return id.equals(other.id) && items.equals(other.items); } 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 ec501004769..44d9e292e06 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 @@ -26,7 +26,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { public static final ParseField RULE_CONDITION_FIELD = new ParseField("rule_condition"); public static final ParseField FIELD_NAME_FIELD = new ParseField("field_name"); public static final ParseField FIELD_VALUE_FIELD = new ParseField("field_value"); - public static final ParseField VALUE_LIST_FIELD = new ParseField("value_list"); + public static final ParseField VALUE_FILTER_FIELD = new ParseField("value_filter"); public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(RULE_CONDITION_FIELD.getPreferredName(), @@ -42,21 +42,21 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), FIELD_NAME_FIELD); PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), FIELD_VALUE_FIELD); PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), Condition.PARSER, Condition.CONDITION_FIELD); - PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), VALUE_LIST_FIELD); + PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), VALUE_FILTER_FIELD); } private final RuleConditionType conditionType; private final String fieldName; private final String fieldValue; private final Condition condition; - private final String valueList; + private final String valueFilter; public RuleCondition(StreamInput in) throws IOException { conditionType = RuleConditionType.readFromStream(in); condition = in.readOptionalWriteable(Condition::new); fieldName = in.readOptionalString(); fieldValue = in.readOptionalString(); - valueList = in.readOptionalString(); + valueFilter = in.readOptionalString(); } @Override @@ -65,15 +65,15 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { out.writeOptionalWriteable(condition); out.writeOptionalString(fieldName); out.writeOptionalString(fieldValue); - out.writeOptionalString(valueList); + out.writeOptionalString(valueFilter); } - public RuleCondition(RuleConditionType conditionType, String fieldName, String fieldValue, Condition condition, String valueList) { + public RuleCondition(RuleConditionType conditionType, String fieldName, String fieldValue, Condition condition, String valueFilter) { this.conditionType = conditionType; this.fieldName = fieldName; this.fieldValue = fieldValue; this.condition = condition; - this.valueList = valueList; + this.valueFilter = valueFilter; verifyFieldsBoundToType(this); verifyFieldValueRequiresFieldName(this); @@ -84,7 +84,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { this.fieldName = ruleCondition.fieldName; this.fieldValue = ruleCondition.fieldValue; this.condition = ruleCondition.condition; - this.valueList = ruleCondition.valueList; + this.valueFilter = ruleCondition.valueFilter; } @Override @@ -100,8 +100,8 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { if (fieldValue != null) { builder.field(FIELD_VALUE_FIELD.getPreferredName(), fieldValue); } - if (valueList != null) { - builder.field(VALUE_LIST_FIELD.getPreferredName(), valueList); + if (valueFilter != null) { + builder.field(VALUE_FILTER_FIELD.getPreferredName(), valueFilter); } builder.endObject(); return builder; @@ -134,11 +134,11 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { } /** - * The unique identifier of a list. Required when the rule type is + * The unique identifier of a filter. Required when the rule type is * categorical. Should be null for all other types. */ - public String getValueList() { - return valueList; + public String getValueFilter() { + return valueFilter; } @Override @@ -154,16 +154,16 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { RuleCondition other = (RuleCondition) obj; return Objects.equals(conditionType, other.conditionType) && Objects.equals(fieldName, other.fieldName) && Objects.equals(fieldValue, other.fieldValue) && Objects.equals(condition, other.condition) - && Objects.equals(valueList, other.valueList); + && Objects.equals(valueFilter, other.valueFilter); } @Override public int hashCode() { - return Objects.hash(conditionType, fieldName, fieldValue, condition, valueList); + return Objects.hash(conditionType, fieldName, fieldValue, condition, valueFilter); } - public static RuleCondition createCategorical(String fieldName, String valueList) { - return new RuleCondition(RuleConditionType.CATEGORICAL, fieldName, null, null, valueList); + public static RuleCondition createCategorical(String fieldName, String valueFilter) { + return new RuleCondition(RuleConditionType.CATEGORICAL, fieldName, null, null, valueFilter); } private static void verifyFieldsBoundToType(RuleCondition ruleCondition) throws ElasticsearchParseException { @@ -184,7 +184,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { private static void verifyCategorical(RuleCondition ruleCondition) throws ElasticsearchParseException { checkCategoricalHasNoField(Condition.CONDITION_FIELD.getPreferredName(), ruleCondition.getCondition()); checkCategoricalHasNoField(RuleCondition.FIELD_VALUE_FIELD.getPreferredName(), ruleCondition.getFieldValue()); - checkCategoricalHasField(RuleCondition.VALUE_LIST_FIELD.getPreferredName(), ruleCondition.getValueList()); + checkCategoricalHasField(RuleCondition.VALUE_FILTER_FIELD.getPreferredName(), ruleCondition.getValueFilter()); } private static void checkCategoricalHasNoField(String fieldName, Object fieldValue) throws ElasticsearchParseException { @@ -202,7 +202,7 @@ public class RuleCondition extends ToXContentToBytes implements Writeable { } private static void verifyNumerical(RuleCondition ruleCondition) throws ElasticsearchParseException { - checkNumericalHasNoField(RuleCondition.VALUE_LIST_FIELD.getPreferredName(), ruleCondition.getValueList()); + checkNumericalHasNoField(RuleCondition.VALUE_FILTER_FIELD.getPreferredName(), ruleCondition.getValueFilter()); checkNumericalHasField(Condition.CONDITION_FIELD.getPreferredName(), ruleCondition.getCondition()); if (ruleCondition.getFieldName() != null && ruleCondition.getFieldValue() == null) { String msg = Messages.getMessage(Messages.JOB_CONFIG_DETECTION_RULE_CONDITION_NUMERICAL_WITH_FIELD_NAME_REQUIRES_FIELD_VALUE); 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 1eb3c5bdfec..5ece4ea2518 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 @@ -207,9 +207,6 @@ public final class Messages { public static final String JSON_DETECTOR_CONFIG_MAPPING = "json.detector.config.mapping.error"; public static final String JSON_DETECTOR_CONFIG_PARSE = "json.detector.config.parse.error"; - public static final String JSON_LIST_DOCUMENT_MAPPING_ERROR = "json.list.document.mapping.error"; - public static final String JSON_LIST_DOCUMENT_PARSE_ERROR = "json.list.document.parse.error"; - public static final String JSON_TRANSFORM_CONFIG_MAPPING = "json.transform.config.mapping.error"; public static final String JSON_TRANSFORM_CONFIG_PARSE = "json.transform.config.parse.error"; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java index e52ec6202a3..4e3c9565636 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java @@ -69,7 +69,7 @@ import org.elasticsearch.xpack.ml.job.results.ModelDebugOutput; import org.elasticsearch.xpack.ml.job.results.PerPartitionMaxProbabilities; import org.elasticsearch.xpack.ml.job.results.Result; import org.elasticsearch.xpack.ml.job.usage.Usage; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.utils.ExceptionsHelper; import java.io.IOException; @@ -1057,12 +1057,12 @@ public class JobProvider { } /** - * Retrieves the list with the given {@code listId} from the datastore. + * Retrieves the filter with the given {@code filterId} from the datastore. * - * @param ids the id of the requested list + * @param ids the id of the requested filter */ - public void getLists(Consumer> handler, Consumer errorHandler, String... ids) { - mget(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), ids, handler, errorHandler, ListDocument.PARSER); + public void getFilters(Consumer> handler, Consumer errorHandler, String... ids) { + mget(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), ids, handler, errorHandler, MlFilter.PARSER); } /** diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java index afbf55ee33a..d47c277a38f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java @@ -18,7 +18,7 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.writer.AnalysisLimitsWr import org.elasticsearch.xpack.ml.job.process.autodetect.writer.FieldConfigWriter; import org.elasticsearch.xpack.ml.job.process.autodetect.writer.ModelDebugConfigWriter; import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import java.io.IOException; import java.io.OutputStreamWriter; @@ -44,7 +44,7 @@ public class AutodetectBuilder { private List filesToDelete; private Logger logger; private boolean ignoreDowntime; - private Set referencedLists; + private Set referencedFilters; private Quantiles quantiles; private Environment env; private Settings settings; @@ -69,7 +69,7 @@ public class AutodetectBuilder { this.filesToDelete = Objects.requireNonNull(filesToDelete); this.logger = Objects.requireNonNull(logger); ignoreDowntime = false; - referencedLists = new HashSet<>(); + referencedFilters = new HashSet<>(); } /** @@ -83,8 +83,8 @@ public class AutodetectBuilder { return this; } - public AutodetectBuilder referencedLists(Set lists) { - referencedLists = lists; + public AutodetectBuilder referencedFilters(Set filters) { + referencedFilters = filters; return this; } @@ -174,7 +174,7 @@ public class AutodetectBuilder { try (OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream(fieldConfigFile), StandardCharsets.UTF_8)) { - new FieldConfigWriter(job.getAnalysisConfig(), referencedLists, osw, logger).write(); + new FieldConfigWriter(job.getAnalysisConfig(), referencedFilters, osw, logger).write(); } String fieldConfig = FIELD_CONFIG_ARG + fieldConfigFile.toString(); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java index 755cb95009e..37d08506acb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessFactory.java @@ -8,7 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect; import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSnapshot; import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -24,11 +24,11 @@ public interface AutodetectProcessFactory { * @param job Job configuration for the analysis process * @param modelSnapshot The model snapshot to restore from * @param quantiles The quantiles to push to the native process - * @param list The lists to push to the native process + * @param filters The filters to push to the native process * @param ignoreDowntime Should gaps in data be treated as anomalous or as a maintenance window after a job re-start * @param executorService Executor service used to start the async tasks a job needs to operate the analytical process * @return The process */ - AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set list, + AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set filters, boolean ignoreDowntime, ExecutorService executorService); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java index 003a10ca4cd..13838361f6b 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java @@ -19,7 +19,7 @@ import org.elasticsearch.xpack.ml.action.UpdateJobStatusAction; import org.elasticsearch.xpack.ml.job.JobManager; import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.config.JobStatus; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.job.metadata.Allocation; import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister; import org.elasticsearch.xpack.ml.job.persistence.JobProvider; @@ -189,9 +189,9 @@ public class AutodetectProcessManager extends AbstractComponent { } public void openJob(String jobId, boolean ignoreDowntime, Consumer handler) { - gatherRequiredInformation(jobId, (modelSnapshot, quantiles, lists) -> { + gatherRequiredInformation(jobId, (modelSnapshot, quantiles, filters) -> { autoDetectCommunicatorByJob.computeIfAbsent(jobId, id -> { - AutodetectCommunicator communicator = create(id, modelSnapshot, quantiles, lists, ignoreDowntime, handler); + AutodetectCommunicator communicator = create(id, modelSnapshot, quantiles, filters, ignoreDowntime, handler); try { communicator.writeJobInputHeader(); } catch (IOException ioe) { @@ -210,19 +210,19 @@ public class AutodetectProcessManager extends AbstractComponent { jobProvider.modelSnapshots(jobId, 0, 1, page -> { ModelSnapshot modelSnapshot = page.results().isEmpty() ? null : page.results().get(1); jobProvider.getQuantiles(jobId, quantiles -> { - String[] ids = job.getAnalysisConfig().extractReferencedLists().toArray(new String[0]); - jobProvider.getLists(listDocument -> handler.accept(modelSnapshot, quantiles, listDocument), errorHandler, ids); + String[] ids = job.getAnalysisConfig().extractReferencedFilters().toArray(new String[0]); + jobProvider.getFilters(filterDocument -> handler.accept(modelSnapshot, quantiles, filterDocument), errorHandler, ids); }, errorHandler); }, errorHandler); } interface TriConsumer { - void accept(ModelSnapshot modelSnapshot, Quantiles quantiles, Set lists); + void accept(ModelSnapshot modelSnapshot, Quantiles quantiles, Set filters); } - AutodetectCommunicator create(String jobId, ModelSnapshot modelSnapshot, Quantiles quantiles, Set lists, + AutodetectCommunicator create(String jobId, ModelSnapshot modelSnapshot, Quantiles quantiles, Set filters, boolean ignoreDowntime, Consumer handler) { if (autoDetectCommunicatorByJob.size() == maxAllowedRunningJobs) { throw new ElasticsearchStatusException("max running job capacity [" + maxAllowedRunningJobs + "] reached", @@ -245,7 +245,7 @@ public class AutodetectProcessManager extends AbstractComponent { AutodetectProcess process = null; try { - process = autodetectProcessFactory.createAutodetectProcess(job, modelSnapshot, quantiles, lists, + process = autodetectProcessFactory.createAutodetectProcess(job, modelSnapshot, quantiles, filters, ignoreDowntime, executorService); return new AutodetectCommunicator(executorService, job, process, dataCountsReporter, processor, stateProcessor, handler); } catch (Exception e) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java index 7151800a950..14683504036 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java @@ -18,7 +18,7 @@ import org.elasticsearch.xpack.ml.job.process.NativeController; import org.elasticsearch.xpack.ml.job.process.ProcessCtrl; import org.elasticsearch.xpack.ml.job.process.ProcessPipes; import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.utils.ExceptionsHelper; import org.elasticsearch.xpack.ml.utils.NamedPipeHelper; @@ -52,12 +52,12 @@ public class NativeAutodetectProcessFactory implements AutodetectProcessFactory } @Override - public AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set list, + public AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set filters, boolean ignoreDowntime, ExecutorService executorService) { List filesToDelete = new ArrayList<>(); ProcessPipes processPipes = new ProcessPipes(env, NAMED_PIPE_HELPER, ProcessCtrl.AUTODETECT, job.getId(), true, false, true, true, modelSnapshot != null, !ProcessCtrl.DONT_PERSIST_MODEL_STATE_SETTING.get(settings)); - createNativeProcess(job, quantiles, list, processPipes, ignoreDowntime, filesToDelete); + createNativeProcess(job, quantiles, filters, processPipes, ignoreDowntime, filesToDelete); int numberOfAnalysisFields = job.getAnalysisConfig().analysisFields().size(); NativeAutodetectProcess autodetect = null; @@ -87,13 +87,13 @@ public class NativeAutodetectProcessFactory implements AutodetectProcessFactory } } - private void createNativeProcess(Job job, Quantiles quantiles, Set lists, ProcessPipes processPipes, + private void createNativeProcess(Job job, Quantiles quantiles, Set filters, ProcessPipes processPipes, boolean ignoreDowntime, List filesToDelete) { try { AutodetectBuilder autodetectBuilder = new AutodetectBuilder(job, filesToDelete, LOGGER, env, settings, nativeController, processPipes) .ignoreDowntime(ignoreDowntime) - .referencedLists(lists); + .referencedFilters(filters); // if state is null or empty it will be ignored // else it is used to restore the quantiles diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java index 6fc771ec5c3..13dd9125dc6 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java @@ -22,7 +22,7 @@ import org.elasticsearch.xpack.ml.job.config.AnalysisConfig; import org.elasticsearch.xpack.ml.job.config.Detector; import org.elasticsearch.xpack.ml.job.config.DefaultDetectorDescription; import org.elasticsearch.xpack.ml.job.config.DetectionRule; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.utils.MlStrings; public class FieldConfigWriter { @@ -32,7 +32,7 @@ public class FieldConfigWriter { private static final String INFLUENCER_PREFIX = "influencer."; private static final String CATEGORIZATION_FIELD_OPTION = " categorizationfield="; private static final String CATEGORIZATION_FILTER_PREFIX = "categorizationfilter."; - private static final String LIST_PREFIX = "list."; + private static final String FILTER_PREFIX = "filter."; // Note: for the Engine API summarycountfield is currently passed as a // command line option to autodetect rather than in the field config file @@ -40,14 +40,14 @@ public class FieldConfigWriter { private static final char NEW_LINE = '\n'; private final AnalysisConfig config; - private final Set lists; + private final Set filters; private final OutputStreamWriter writer; private final Logger logger; - public FieldConfigWriter(AnalysisConfig config, Set lists, + public FieldConfigWriter(AnalysisConfig config, Set filters, OutputStreamWriter writer, Logger logger) { this.config = Objects.requireNonNull(config); - this.lists = Objects.requireNonNull(lists); + this.filters = Objects.requireNonNull(filters); this.writer = Objects.requireNonNull(writer); this.logger = Objects.requireNonNull(logger); } @@ -59,7 +59,7 @@ public class FieldConfigWriter { StringBuilder contents = new StringBuilder(); writeDetectors(contents); - writeLists(contents); + writeFilters(contents); writeAsEnumeratedSettings(CATEGORIZATION_FILTER_PREFIX, config.getCategorizationFilters(), contents, true); @@ -119,24 +119,24 @@ public class FieldConfigWriter { contents.append(NEW_LINE); } - private void writeLists(StringBuilder buffer) throws IOException { - for (ListDocument list : lists) { + private void writeFilters(StringBuilder buffer) throws IOException { + for (MlFilter filter : filters) { - StringBuilder listAsJson = new StringBuilder(); - listAsJson.append('['); + StringBuilder filterAsJson = new StringBuilder(); + filterAsJson.append('['); boolean first = true; - for (String item : list.getItems()) { + for (String item : filter.getItems()) { if (first) { first = false; } else { - listAsJson.append(','); + filterAsJson.append(','); } - listAsJson.append('"'); - listAsJson.append(item); - listAsJson.append('"'); + filterAsJson.append('"'); + filterAsJson.append(item); + filterAsJson.append('"'); } - listAsJson.append(']'); - buffer.append(LIST_PREFIX).append(list.getId()).append(EQUALS).append(listAsJson) + filterAsJson.append(']'); + buffer.append(FILTER_PREFIX).append(filter.getId()).append(EQUALS).append(filterAsJson) .append(NEW_LINE); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestDeleteListAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java similarity index 61% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestDeleteListAction.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java index b588e9309cd..7760016b1b9 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestDeleteListAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.ml.rest.list; +package org.elasticsearch.xpack.ml.rest.filter; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; @@ -12,23 +12,23 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.AcknowledgedRestListener; import org.elasticsearch.xpack.ml.MlPlugin; -import org.elasticsearch.xpack.ml.action.DeleteListAction; -import org.elasticsearch.xpack.ml.action.DeleteListAction.Request; +import org.elasticsearch.xpack.ml.action.DeleteFilterAction; +import org.elasticsearch.xpack.ml.action.DeleteFilterAction.Request; import java.io.IOException; -public class RestDeleteListAction extends BaseRestHandler { +public class RestDeleteFilterAction extends BaseRestHandler { - public RestDeleteListAction(Settings settings, RestController controller) { + public RestDeleteFilterAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(RestRequest.Method.DELETE, - MlPlugin.BASE_PATH + "lists/{" + Request.LIST_ID.getPreferredName() + "}", this); + MlPlugin.BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", this); } @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { - Request request = new Request(restRequest.param(Request.LIST_ID.getPreferredName())); - return channel -> client.execute(DeleteListAction.INSTANCE, request, new AcknowledgedRestListener<>(channel)); + Request request = new Request(restRequest.param(Request.FILTER_ID.getPreferredName())); + return channel -> client.execute(DeleteFilterAction.INSTANCE, request, new AcknowledgedRestListener<>(channel)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestGetListAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java similarity index 63% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestGetListAction.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java index 9695d90eede..e6b2c5c33db 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestGetListAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.ml.rest.list; +package org.elasticsearch.xpack.ml.rest.filter; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; @@ -13,35 +13,35 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.ml.MlPlugin; -import org.elasticsearch.xpack.ml.action.GetListAction; +import org.elasticsearch.xpack.ml.action.GetFiltersAction; import org.elasticsearch.xpack.ml.action.util.PageParams; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import java.io.IOException; -public class RestGetListAction extends BaseRestHandler { +public class RestGetFiltersAction extends BaseRestHandler { - public RestGetListAction(Settings settings, RestController controller) { + public RestGetFiltersAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "lists/{" + ListDocument.ID.getPreferredName() + "}", + controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", this); - controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "lists/", this); + controller.registerHandler(RestRequest.Method.GET, MlPlugin.BASE_PATH + "filters/", this); } @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { - GetListAction.Request getListRequest = new GetListAction.Request(); - String listId = restRequest.param(ListDocument.ID.getPreferredName()); - if (!Strings.isNullOrEmpty(listId)) { - getListRequest.setListId(listId); + GetFiltersAction.Request getListRequest = new GetFiltersAction.Request(); + String filterId = restRequest.param(MlFilter.ID.getPreferredName()); + if (!Strings.isNullOrEmpty(filterId)) { + getListRequest.setFilterId(filterId); } if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName()) - || Strings.isNullOrEmpty(listId)) { + || Strings.isNullOrEmpty(filterId)) { getListRequest.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE))); } - return channel -> client.execute(GetListAction.INSTANCE, getListRequest, new RestStatusToXContentListener<>(channel)); + return channel -> client.execute(GetFiltersAction.INSTANCE, getListRequest, new RestStatusToXContentListener<>(channel)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestPutListAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java similarity index 66% rename from elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestPutListAction.java rename to elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java index c348c110cb5..08c24257f65 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/list/RestPutListAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.ml.rest.list; +package org.elasticsearch.xpack.ml.rest.filter; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; @@ -13,22 +13,22 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.AcknowledgedRestListener; import org.elasticsearch.xpack.ml.MlPlugin; -import org.elasticsearch.xpack.ml.action.PutListAction; +import org.elasticsearch.xpack.ml.action.PutFilterAction; import java.io.IOException; -public class RestPutListAction extends BaseRestHandler { +public class RestPutFilterAction extends BaseRestHandler { - public RestPutListAction(Settings settings, RestController controller) { + public RestPutFilterAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(RestRequest.Method.PUT, MlPlugin.BASE_PATH + "lists", this); + controller.registerHandler(RestRequest.Method.PUT, MlPlugin.BASE_PATH + "filters", this); } @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { XContentParser parser = restRequest.contentOrSourceParamParser(); - PutListAction.Request putListRequest = PutListAction.Request.parseRequest(parser); - return channel -> client.execute(PutListAction.INSTANCE, putListRequest, new AcknowledgedRestListener<>(channel)); + PutFilterAction.Request putListRequest = PutFilterAction.Request.parseRequest(parser); + return channel -> client.execute(PutFilterAction.INSTANCE, putListRequest, new AcknowledgedRestListener<>(channel)); } } 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 e2096160220..5fc22a8bcc5 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 @@ -164,9 +164,6 @@ json.job.config.parse.error = JSON parse error reading the job configuration json.detector.config.mapping.error = JSON mapping error reading the detector configuration json.detector.config.parse.error = JSON parse error reading the detector configuration -json.list.document.mapping.error = JSON mapping error reading the list -json.list.document.parse.error = JSON parse error reading the list - json.transform.config.mapping.error = JSON mapping error reading the transform configuration json.transform.config.parse.error = JSON parse error reading the transform configuration diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateListActionRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateFilterActionRequestTests.java similarity index 64% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateListActionRequestTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateFilterActionRequestTests.java index b2803476ec7..6ba252ddf83 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateListActionRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/CreateFilterActionRequestTests.java @@ -6,14 +6,14 @@ package org.elasticsearch.xpack.ml.action; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.ml.action.PutListAction.Request; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.action.PutFilterAction.Request; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.support.AbstractStreamableXContentTestCase; import java.util.ArrayList; import java.util.List; -public class CreateListActionRequestTests extends AbstractStreamableXContentTestCase { +public class CreateFilterActionRequestTests extends AbstractStreamableXContentTestCase { @Override protected Request createTestInstance() { @@ -22,18 +22,18 @@ public class CreateListActionRequestTests extends AbstractStreamableXContentTest for (int i = 0; i < size; i++) { items.add(randomAsciiOfLengthBetween(1, 20)); } - ListDocument listDocument = new ListDocument(randomAsciiOfLengthBetween(1, 20), items); - return new PutListAction.Request(listDocument); + MlFilter filter = new MlFilter(randomAsciiOfLengthBetween(1, 20), items); + return new PutFilterAction.Request(filter); } @Override protected Request createBlankInstance() { - return new PutListAction.Request(); + return new PutFilterAction.Request(); } @Override protected Request parseInstance(XContentParser parser) { - return PutListAction.Request.parseRequest(parser); + return PutFilterAction.Request.parseRequest(parser); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java similarity index 80% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionRequestTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java index 4f872a81092..28bfa96178f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionRequestTests.java @@ -5,18 +5,18 @@ */ package org.elasticsearch.xpack.ml.action; -import org.elasticsearch.xpack.ml.action.GetListAction.Request; +import org.elasticsearch.xpack.ml.action.GetFiltersAction.Request; import org.elasticsearch.xpack.ml.action.util.PageParams; import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase; -public class GetListActionRequestTests extends AbstractStreamableTestCase { +public class GetFiltersActionRequestTests extends AbstractStreamableTestCase { @Override protected Request createTestInstance() { Request request = new Request(); if (randomBoolean()) { - request.setListId(randomAsciiOfLengthBetween(1, 20)); + request.setFilterId(randomAsciiOfLengthBetween(1, 20)); } else { if (randomBoolean()) { int from = randomInt(PageParams.MAX_FROM_SIZE_SUM); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionResponseTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java similarity index 70% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionResponseTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java index 4bce01f0dda..c40d5985d16 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetListActionResponseTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/action/GetFiltersActionResponseTests.java @@ -5,22 +5,22 @@ */ package org.elasticsearch.xpack.ml.action; -import org.elasticsearch.xpack.ml.action.GetListAction.Response; +import org.elasticsearch.xpack.ml.action.GetFiltersAction.Response; import org.elasticsearch.xpack.ml.action.util.QueryPage; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase; import java.util.Collections; -public class GetListActionResponseTests extends AbstractStreamableTestCase { +public class GetFiltersActionResponseTests extends AbstractStreamableTestCase { @Override protected Response createTestInstance() { - final QueryPage result; + final QueryPage result; - ListDocument doc = new ListDocument( + MlFilter doc = new MlFilter( randomAsciiOfLengthBetween(1, 20), Collections.singletonList(randomAsciiOfLengthBetween(1, 20))); - result = new QueryPage<>(Collections.singletonList(doc), 1, ListDocument.RESULTS_FIELD); + result = new QueryPage<>(Collections.singletonList(doc), 1, MlFilter.RESULTS_FIELD); return new Response(result); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfigTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfigTests.java index d31572368ba..6e09ea2995e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfigTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/AnalysisConfigTests.java @@ -398,8 +398,10 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase(Arrays.asList("list1", "list2")), config.extractReferencedLists()); + assertEquals(new HashSet<>(Arrays.asList("filter1", "filter2")), config.extractReferencedFilters()); } private static AnalysisConfig createFullyPopulatedConfig() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectionRuleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectionRuleTests.java index 87529db613e..e210cd23620 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectionRuleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectionRuleTests.java @@ -22,11 +22,11 @@ public class DetectionRuleTests extends AbstractSerializingTestCase conditions = Arrays.asList( numericalCondition, - RuleCondition.createCategorical("foo", "list1"), - RuleCondition.createCategorical("bar", "list2")); + RuleCondition.createCategorical("foo", "filter1"), + RuleCondition.createCategorical("bar", "filter2")); DetectionRule rule = new DetectionRule(null, null, Connective.OR, conditions); - assertEquals(new HashSet<>(Arrays.asList("list1", "list2")), rule.extractReferencedLists()); + assertEquals(new HashSet<>(Arrays.asList("filter1", "filter2")), rule.extractReferencedFilters()); } public void testEqualsGivenSameObject() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectorTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectorTests.java index ad5be037555..070174c5fab 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectorTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/DetectorTests.java @@ -111,7 +111,7 @@ public class DetectorTests extends AbstractSerializingTestCase { new DetectionRule(null, null, Connective.OR, Arrays.asList(RuleCondition.createCategorical("by", "list2"))))); Detector detector = builder.build(); - assertEquals(new HashSet<>(Arrays.asList("list1", "list2")), detector.extractReferencedLists()); + assertEquals(new HashSet<>(Arrays.asList("list1", "list2")), detector.extractReferencedFilters()); } private Detector.Builder createDetector() { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ListDocumentTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java similarity index 53% rename from elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ListDocumentTests.java rename to elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java index 2df88249457..62b7f0ec080 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/ListDocumentTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/config/MlFilterTests.java @@ -13,36 +13,37 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class ListDocumentTests extends AbstractSerializingTestCase { +public class MlFilterTests extends AbstractSerializingTestCase { @Override - protected ListDocument createTestInstance() { + protected MlFilter createTestInstance() { int size = randomInt(10); List items = new ArrayList<>(size); for (int i = 0; i < size; i++) { items.add(randomAsciiOfLengthBetween(1, 20)); } - return new ListDocument(randomAsciiOfLengthBetween(1, 20), items); + return new MlFilter(randomAsciiOfLengthBetween(1, 20), items); } @Override - protected Reader instanceReader() { - return ListDocument::new; + protected Reader instanceReader() { + return MlFilter::new; } @Override - protected ListDocument parseInstance(XContentParser parser) { - return ListDocument.PARSER.apply(parser, null); + protected MlFilter parseInstance(XContentParser parser) { + return MlFilter.PARSER.apply(parser, null); } public void testNullId() { - NullPointerException ex = expectThrows(NullPointerException.class, () -> new ListDocument(null, Collections.emptyList())); - assertEquals(ListDocument.ID.getPreferredName() + " must not be null", ex.getMessage()); + NullPointerException ex = expectThrows(NullPointerException.class, () -> new MlFilter(null, Collections.emptyList())); + assertEquals(MlFilter.ID.getPreferredName() + " must not be null", ex.getMessage()); } public void testNullItems() { - NullPointerException ex = expectThrows(NullPointerException.class, () -> new ListDocument(randomAsciiOfLengthBetween(1, 20), null)); - assertEquals(ListDocument.ITEMS.getPreferredName() + " must not be null", ex.getMessage()); + NullPointerException ex = + expectThrows(NullPointerException.class, () -> new MlFilter(randomAsciiOfLengthBetween(1, 20), null)); + assertEquals(MlFilter.ITEMS.getPreferredName() + " must not be null", ex.getMessage()); } } 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 c57d182a682..baceb71377b 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 @@ -16,12 +16,12 @@ public class RuleConditionTests extends AbstractSerializingTestCase new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, null)); - assertEquals("Invalid detector rule: a categorical rule_condition requires value_list to be set", e.getMessage()); + assertEquals("Invalid detector rule: a categorical rule_condition requires value_filter to be set", e.getMessage()); } - public void testVerify_GivenNumericalActualWithValueList() { + public void testVerify_GivenNumericalActualWithValueFilter() { IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, null, "myList")); - assertEquals("Invalid detector rule: a numerical rule_condition does not support value_list", e.getMessage()); + () -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, null, "myFilter")); + assertEquals("Invalid detector rule: a numerical rule_condition does not support value_filter", e.getMessage()); } public void testVerify_GivenNumericalActualWithoutCondition() { @@ -145,10 +145,10 @@ public class RuleConditionTests extends AbstractSerializingTestCase new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, null, "myList")); - assertEquals("Invalid detector rule: a numerical rule_condition does not support value_list", e.getMessage()); + () -> new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, null, null, null, "myFilter")); + assertEquals("Invalid detector rule: a numerical rule_condition does not support value_filter", e.getMessage()); } public void testVerify_GivenNumericalTypicalWithoutCondition() { @@ -157,10 +157,10 @@ public class RuleConditionTests extends AbstractSerializingTestCase new RuleCondition(RuleConditionType.NUMERICAL_DIFF_ABS, null, null, null, "myList")); - assertEquals("Invalid detector rule: a numerical rule_condition does not support value_list", e.getMessage()); + () -> new RuleCondition(RuleConditionType.NUMERICAL_DIFF_ABS, null, null, null, "myFilter")); + assertEquals("Invalid detector rule: a numerical rule_condition does not support value_filter", e.getMessage()); } public void testVerify_GivenNumericalDiffAbsWithoutCondition() { @@ -199,7 +199,7 @@ public class RuleConditionTests extends AbstractSerializingTestCase autodetectProcess; + AutodetectProcessFactory autodetectProcessFactory = (j, modelSnapshot, quantiles, filters, i, e) -> autodetectProcess; Settings.Builder settings = Settings.builder(); settings.put(AutodetectProcessManager.MAX_RUNNING_JOBS_PER_NODE.getKey(), 3); AutodetectProcessManager manager = spy(new AutodetectProcessManager(settings.build(), client, threadPool, jobManager, jobProvider, @@ -148,10 +148,10 @@ public class AutodetectProcessManagerTests extends ESTestCase { ModelSnapshot modelSnapshot = new ModelSnapshot("foo"); Quantiles quantiles = new Quantiles("foo", new Date(), "state"); - Set lists = new HashSet<>(); + Set filters = new HashSet<>(); doAnswer(invocationOnMock -> { AutodetectProcessManager.TriConsumer consumer = (AutodetectProcessManager.TriConsumer) invocationOnMock.getArguments()[1]; - consumer.accept(modelSnapshot, quantiles, lists); + consumer.accept(modelSnapshot, quantiles, filters); return null; }).when(manager).gatherRequiredInformation(any(), any(), any()); @@ -298,20 +298,20 @@ public class AutodetectProcessManagerTests extends ESTestCase { AutodetectResultsParser parser = mock(AutodetectResultsParser.class); AutodetectProcess autodetectProcess = mock(AutodetectProcess.class); - AutodetectProcessFactory autodetectProcessFactory = (j, modelSnapshot, quantiles, lists, i, e) -> autodetectProcess; + AutodetectProcessFactory autodetectProcessFactory = (j, modelSnapshot, quantiles, filters, i, e) -> autodetectProcess; AutodetectProcessManager manager = spy(new AutodetectProcessManager(Settings.EMPTY, client, threadPool, jobManager, jobProvider, jobResultsPersister, jobRenormalizedResultsPersister, jobDataCountsPersister, parser, autodetectProcessFactory, normalizerFactory)); ModelSnapshot modelSnapshot = new ModelSnapshot("foo"); Quantiles quantiles = new Quantiles("foo", new Date(), "state"); - Set lists = new HashSet<>(); + Set filters = new HashSet<>(); doAnswer(invocationOnMock -> { AutodetectProcessManager.TriConsumer consumer = (AutodetectProcessManager.TriConsumer) invocationOnMock.getArguments()[1]; - consumer.accept(modelSnapshot, quantiles, lists); + consumer.accept(modelSnapshot, quantiles, filters); return null; }).when(manager).gatherRequiredInformation(any(), any(), any()); - expectThrows(EsRejectedExecutionException.class, () -> manager.create("my_id", modelSnapshot, quantiles, lists, false, e -> {})); + expectThrows(EsRejectedExecutionException.class, () -> manager.create("my_id", modelSnapshot, quantiles, filters, false, e -> {})); verify(autodetectProcess, times(1)).close(); } @@ -336,13 +336,13 @@ public class AutodetectProcessManagerTests extends ESTestCase { manager = spy(manager); ModelSnapshot modelSnapshot = new ModelSnapshot("foo"); Quantiles quantiles = new Quantiles("foo", new Date(), "state"); - Set lists = new HashSet<>(); + Set filters = new HashSet<>(); doAnswer(invocationOnMock -> { AutodetectProcessManager.TriConsumer consumer = (AutodetectProcessManager.TriConsumer) invocationOnMock.getArguments()[1]; - consumer.accept(modelSnapshot, quantiles, lists); + consumer.accept(modelSnapshot, quantiles, filters); return null; }).when(manager).gatherRequiredInformation(any(), any(), any()); - doReturn(communicator).when(manager).create(any(), eq(modelSnapshot), eq(quantiles), eq(lists), anyBoolean(), any()); + doReturn(communicator).when(manager).create(any(), eq(modelSnapshot), eq(quantiles), eq(filters), anyBoolean(), any()); return manager; } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java index 8177f3eaf02..29ac535d97e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java @@ -39,18 +39,18 @@ import org.elasticsearch.xpack.ml.job.config.Operator; import org.elasticsearch.xpack.ml.job.config.DetectionRule; import org.elasticsearch.xpack.ml.job.config.RuleCondition; import org.elasticsearch.xpack.ml.job.config.RuleConditionType; -import org.elasticsearch.xpack.ml.job.config.ListDocument; +import org.elasticsearch.xpack.ml.job.config.MlFilter; public class FieldConfigWriterTests extends ESTestCase { private AnalysisConfig analysisConfig; - private Set lists; + private Set filters; private OutputStreamWriter writer; @Before public void setUpDeps() { analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(new Detector.Builder("count", null).build())).build(); - lists = new LinkedHashSet<>(); + filters = new LinkedHashSet<>(); } public void testMultipleDetectorsToConfFile() @@ -202,25 +202,25 @@ public class FieldConfigWriterTests extends ESTestCase { assertEquals("[" + rule.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string() + "]\n", rulesJson); } - public void testWrite_GivenLists() throws IOException { + public void testWrite_GivenFilters() throws IOException { Detector d = new Detector.Builder("count", null).build(); AnalysisConfig.Builder builder = new AnalysisConfig.Builder(Arrays.asList(d)); analysisConfig = builder.build(); - lists.add(new ListDocument("list_1", Arrays.asList("a", "b"))); - lists.add(new ListDocument("list_2", Arrays.asList("c", "d"))); + filters.add(new MlFilter("filter_1", Arrays.asList("a", "b"))); + filters.add(new MlFilter("filter_2", Arrays.asList("c", "d"))); writer = mock(OutputStreamWriter.class); createFieldConfigWriter().write(); verify(writer).write("detector.0.clause = count\n" + - "list.list_1 = [\"a\",\"b\"]\n" + - "list.list_2 = [\"c\",\"d\"]\n"); + "filter.filter_1 = [\"a\",\"b\"]\n" + + "filter.filter_2 = [\"c\",\"d\"]\n"); verifyNoMoreInteractions(writer); } private FieldConfigWriter createFieldConfigWriter() { - return new FieldConfigWriter(analysisConfig, lists, writer, mock(Logger.class)); + return new FieldConfigWriter(analysisConfig, filters, writer, mock(Logger.class)); } } diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_filter.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_filter.json new file mode 100644 index 00000000000..6c120fc243f --- /dev/null +++ b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_filter.json @@ -0,0 +1,17 @@ +{ + "xpack.ml.delete_filter": { + "methods": [ "DELETE" ], + "url": { + "path": "/_xpack/ml/filters/{filter_id}", + "paths": [ "/_xpack/ml/filters/{filter_id}" ], + "parts": { + "filter_id": { + "type" : "string", + "required" : true, + "description" : "The ID of the filter to delete" + } + } + }, + "body": null + } +} diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_list.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_list.json deleted file mode 100644 index 1afbe595728..00000000000 --- a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.delete_list.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "xpack.ml.delete_list": { - "methods": [ "DELETE" ], - "url": { - "path": "/_xpack/ml/lists/{list_id}", - "paths": [ "/_xpack/ml/lists/{list_id}" ], - "parts": { - "list_id": { - "type" : "string", - "required" : true, - "description" : "The ID of the list to delete" - } - } - }, - "body": null - } -} diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_filters.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_filters.json new file mode 100644 index 00000000000..828f6c6e530 --- /dev/null +++ b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_filters.json @@ -0,0 +1,26 @@ +{ + "xpack.ml.get_filters": { + "methods": [ "GET" ], + "url": { + "path": "/_xpack/ml/filters/{filter_id}", + "paths": [ "/_xpack/ml/filters/", "/_xpack/ml/filters/{filter_id}" ], + "parts": { + "filter_id": { + "type" : "string", + "description" : "The ID of the filter to fetch" + } + }, + "params": { + "from": { + "type": "int", + "description": "skips a number of filters" + }, + "size": { + "type": "int", + "description": "specifies a max number of filters to get" + } + } + }, + "body": null + } +} diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_lists.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_lists.json deleted file mode 100644 index 9ee2754dda5..00000000000 --- a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.get_lists.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "xpack.ml.get_lists": { - "methods": [ "GET" ], - "url": { - "path": "/_xpack/ml/lists/{list_id}", - "paths": [ "/_xpack/ml/lists/", "/_xpack/ml/lists/{list_id}" ], - "parts": { - "list_id": { - "type" : "string", - "description" : "The ID of the list to fetch" - } - }, - "params": { - "from": { - "type": "int", - "description": "skips a number of lists" - }, - "size": { - "type": "int", - "description": "specifies a max number of lists to get" - } - } - }, - "body": null - } -} diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_filter.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_filter.json new file mode 100644 index 00000000000..1ae4e9f1fbf --- /dev/null +++ b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_filter.json @@ -0,0 +1,14 @@ +{ + "xpack.ml.put_filter": { + "methods": [ "PUT" ], + "url": { + "path": "/_xpack/ml/filters", + "paths": [ "/_xpack/ml/filters" ], + "params": {} + }, + "body": { + "description" : "The filter details", + "required" : true + } + } +} diff --git a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_list.json b/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_list.json deleted file mode 100644 index fb5bd40af33..00000000000 --- a/elasticsearch/src/test/resources/rest-api-spec/api/xpack.ml.put_list.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "xpack.ml.put_list": { - "methods": [ "PUT" ], - "url": { - "path": "/_xpack/ml/lists", - "paths": [ "/_xpack/ml/lists" ], - "params": {} - }, - "body": { - "description" : "The list details", - "required" : true - } - } -} diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/list_crud.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/filter_crud.yaml similarity index 66% rename from elasticsearch/src/test/resources/rest-api-spec/test/list_crud.yaml rename to elasticsearch/src/test/resources/rest-api-spec/test/filter_crud.yaml index 76996ddd6ce..31aef1f8c08 100644 --- a/elasticsearch/src/test/resources/rest-api-spec/test/list_crud.yaml +++ b/elasticsearch/src/test/resources/rest-api-spec/test/filter_crud.yaml @@ -1,7 +1,7 @@ --- setup: - do: - xpack.ml.put_list: + xpack.ml.put_filter: body: > { "id": "foo", @@ -9,7 +9,7 @@ setup: } - do: - xpack.ml.put_list: + xpack.ml.put_filter: body: > { "id": "foo2", @@ -20,45 +20,45 @@ setup: indices.refresh: {} --- -"Test get list API with bad ID": +"Test get filter API with bad ID": - do: catch: missing - xpack.ml.get_lists: - list_id: "do_not_exist" + xpack.ml.get_filters: + filter_id: "do_not_exist" --- -"Test get list API": +"Test get filter API": - do: - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" - match: { count: 1 } - match: - lists.0: + filters.0: id: "foo" items: ["abc", "xyz"] --- -"Test get lists API": +"Test get filters API": - do: - xpack.ml.get_lists: {} + xpack.ml.get_filters: {} - match: { count: 2 } - match: - lists.0: + filters.0: id: "foo" items: ["abc", "xyz"] - match: - lists.1: + filters.1: id: "foo2" items: ["123", "lmnop"] - do: - xpack.ml.get_lists: + xpack.ml.get_filters: from: 1 size: 1 @@ -69,26 +69,26 @@ setup: - do: catch: request - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" from: 0 - do: catch: request - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" size: 1 - do: catch: request - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" from: 0 size: 1 --- -"Test create list api": +"Test create filter api": - do: - xpack.ml.put_list: + xpack.ml.put_filter: body: > { "id": "foo2", @@ -98,27 +98,27 @@ setup: - match: { acknowledged: true } - do: - xpack.ml.get_lists: - list_id: "foo2" + xpack.ml.get_filters: + filter_id: "foo2" - match: { count: 1 } - match: - lists.0: + filters.0: id: "foo2" items: ["abc", "xyz"] --- -"Test create list api without ID": +"Test create filter api without ID": - do: catch: /illegal_argument_exception/ - xpack.ml.put_list: + xpack.ml.put_filter: body: > { "items": ["abc", "xyz"] } --- -"Test delete in-use list": +"Test delete in-use filter": - do: xpack.ml.put_job: job_id: farequote2 @@ -134,7 +134,7 @@ setup: "rule_conditions": [ { "condition_type": "categorical", - "value_list": "foo" + "value_filter": "foo" } ] } @@ -148,34 +148,34 @@ setup: } - do: catch: conflict - xpack.ml.delete_list: - list_id: "foo" + xpack.ml.delete_filter: + filter_id: "foo" --- -"Test non-existing list": +"Test non-existing filter": - do: catch: missing - xpack.ml.delete_list: - list_id: "does_not_exist" + xpack.ml.delete_filter: + filter_id: "does_not_exist" --- -"Test valid delete list": +"Test valid delete filter": - do: - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" - match: { count: 1 } - match: - lists.0: + filters.0: id: "foo" items: ["abc", "xyz"] - do: - xpack.ml.delete_list: - list_id: "foo" + xpack.ml.delete_filter: + filter_id: "foo" - do: catch: missing - xpack.ml.get_lists: - list_id: "foo" + xpack.ml.get_filters: + filter_id: "foo" diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_filters.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_filters.yaml new file mode 100644 index 00000000000..81cafc3f5e6 --- /dev/null +++ b/elasticsearch/src/test/resources/rest-api-spec/test/get_filters.yaml @@ -0,0 +1,19 @@ +--- +"Test get all filter given no filter exists": + + - do: + xpack.ml.put_filter: + body: > + { + "id": "foo", + "items": ["abc", "xyz"] + } + + - do: + xpack.ml.delete_filter: + filter_id: "foo" + + - do: + xpack.ml.get_filters: {} + - match: { count: 0 } + - match: { filters: [] } diff --git a/elasticsearch/src/test/resources/rest-api-spec/test/get_lists.yaml b/elasticsearch/src/test/resources/rest-api-spec/test/get_lists.yaml deleted file mode 100644 index e599ad7798a..00000000000 --- a/elasticsearch/src/test/resources/rest-api-spec/test/get_lists.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -"Test get all lists given no list exists": - - - do: - xpack.ml.put_list: - body: > - { - "id": "foo", - "items": ["abc", "xyz"] - } - - - do: - xpack.ml.delete_list: - list_id: "foo" - - - do: - xpack.ml.get_lists: {} - - match: { count: 0 } - - match: { lists: [] }