Part of the endpoint rename Sophie and Steve agreed with Clint

Relates elastic/elasticsearch#630

Original commit: elastic/x-pack-elasticsearch@6ded117849
This commit is contained in:
David Roberts 2017-01-24 10:01:24 +00:00 committed by GitHub
parent a7d1918461
commit 215410e93f
40 changed files with 419 additions and 422 deletions

View File

@ -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),

View File

@ -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<DeleteListAction.Request, DeleteListAction.Response, DeleteListAction.RequestBuilder> {
public class DeleteFilterAction extends Action<DeleteFilterAction.Request, DeleteFilterAction.Response, DeleteFilterAction.RequestBuilder> {
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<DeleteListAction.Request, DeleteLis
public static class Request extends AcknowledgedRequest<Request> {
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<DeleteListAction.Request, DeleteLis
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
listId = in.readString();
filterId = in.readString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(listId);
out.writeString(filterId);
}
@Override
public int hashCode() {
return Objects.hash(listId);
return Objects.hash(filterId);
}
@Override
@ -109,13 +109,13 @@ public class DeleteListAction extends Action<DeleteListAction.Request, DeleteLis
return false;
}
Request other = (Request) obj;
return Objects.equals(listId, other.listId);
return Objects.equals(filterId, other.filterId);
}
}
public static class RequestBuilder extends MasterNodeOperationRequestBuilder<Request, Response, RequestBuilder> {
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<DeleteListAction.Request, DeleteLis
ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
TransportDeleteAction transportAction) {
super(settings, DeleteListAction.NAME, transportService, clusterService, threadPool, actionFilters,
super(settings, DeleteFilterAction.NAME, transportService, clusterService, threadPool, actionFilters,
indexNameExpressionResolver, Request::new);
this.transportAction = transportAction;
}
@ -171,30 +171,30 @@ public class DeleteListAction extends Action<DeleteListAction.Request, DeleteLis
@Override
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> listener) throws Exception {
final String listId = request.getListId();
final String filterId = request.getFilterId();
MlMetadata currentMlMetadata = state.metaData().custom(MlMetadata.TYPE);
Map<String, Job> jobs = currentMlMetadata.getJobs();
List<String> currentlyUsedBy = new ArrayList<>();
for (Job job : jobs.values()) {
List<Detector> 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<DeleteResponse>() {
@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<DeleteListAction.Request, DeleteLis
@Override
public void onFailure(Exception e) {
logger.error("Could not delete list with ID [" + listId + "]", e);
listener.onFailure(new IllegalStateException("Could not delete list with ID [" + listId + "]", e));
logger.error("Could not delete filter with ID [" + filterId + "]", e);
listener.onFailure(new IllegalStateException("Could not delete filter with ID [" + filterId + "]", e));
}
});
}

View File

@ -43,7 +43,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
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;
import java.util.ArrayList;
@ -54,12 +54,12 @@ import java.util.Objects;
import static org.elasticsearch.action.ValidateActions.addValidationError;
public class GetListAction extends Action<GetListAction.Request, GetListAction.Response, GetListAction.RequestBuilder> {
public class GetFiltersAction extends Action<GetFiltersAction.Request, GetFiltersAction.Response, GetFiltersAction.RequestBuilder> {
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<GetListAction.Request, GetListAction.R
public static class Request extends MasterNodeReadRequest<Request> {
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<GetListAction.Request, GetListAction.R
}
public void setPageParams(PageParams pageParams) {
if (listId != null) {
if (filterId != null) {
throw new IllegalArgumentException("Param [" + PageParams.FROM.getPreferredName()
+ ", " + PageParams.SIZE.getPreferredName() + "] is incompatible with ["
+ ListDocument.ID.getPreferredName() + "].");
+ MlFilter.ID.getPreferredName() + "].");
}
this.pageParams = pageParams;
}
@ -109,8 +109,8 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (pageParams == null && listId == null) {
validationException = addValidationError("Both [" + ListDocument.ID.getPreferredName() + "] and ["
if (pageParams == null && filterId == null) {
validationException = addValidationError("Both [" + MlFilter.ID.getPreferredName() + "] and ["
+ PageParams.FROM.getPreferredName() + ", " + PageParams.SIZE.getPreferredName() + "] "
+ "cannot be null" , validationException);
}
@ -120,18 +120,18 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
listId = in.readOptionalString();
filterId = in.readOptionalString();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(listId);
out.writeOptionalString(filterId);
}
@Override
public int hashCode() {
return Objects.hash(listId);
return Objects.hash(filterId);
}
@Override
@ -143,42 +143,42 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
return false;
}
Request other = (Request) obj;
return Objects.equals(listId, other.listId);
return Objects.equals(filterId, other.filterId);
}
}
public static class RequestBuilder extends MasterNodeReadOperationRequestBuilder<Request, Response, RequestBuilder> {
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<ListDocument> lists;
private QueryPage<MlFilter> filters;
public Response(QueryPage<ListDocument> lists) {
this.lists = lists;
public Response(QueryPage<MlFilter> filters) {
this.filters = filters;
}
Response() {
}
public QueryPage<ListDocument> getLists() {
return lists;
public QueryPage<MlFilter> 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<GetListAction.Request, GetListAction.R
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
lists.doXContentBody(builder, params);
filters.doXContentBody(builder, params);
builder.endObject();
return builder;
}
@Override
public int hashCode() {
return Objects.hash(lists);
return Objects.hash(filters);
}
@Override
@ -208,7 +208,7 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
return false;
}
Response other = (Response) obj;
return Objects.equals(lists, other.lists);
return Objects.equals(filters, other.filters);
}
@SuppressWarnings("deprecation")
@ -240,7 +240,7 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
TransportGetAction transportGetAction, TransportSearchAction transportSearchAction) {
super(settings, GetListAction.NAME, transportService, clusterService, threadPool, actionFilters,
super(settings, GetFiltersAction.NAME, transportService, clusterService, threadPool, actionFilters,
indexNameExpressionResolver, Request::new);
this.transportGetAction = transportGetAction;
this.transportSearchAction = transportSearchAction;
@ -258,13 +258,13 @@ public class GetListAction extends Action<GetListAction.Request, GetListAction.R
@Override
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> 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<GetListAction.Request, GetListAction.R
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}
private void getList(String listId, ActionListener<Response> listener) {
GetRequest getRequest = new GetRequest(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), listId);
private void getFilter(String filterId, ActionListener<Response> listener) {
GetRequest getRequest = new GetRequest(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), filterId);
transportGetAction.execute(getRequest, new ActionListener<GetResponse>() {
@Override
public void onResponse(GetResponse getDocResponse) {
try {
QueryPage<ListDocument> responseBody;
QueryPage<MlFilter> 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<GetListAction.Request, GetListAction.R
});
}
private void getLists(PageParams pageParams, ActionListener<Response> listener) {
private void getFilters(PageParams pageParams, ActionListener<Response> 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<SearchResponse>() {
@Override
public void onResponse(SearchResponse response) {
try {
List<ListDocument> docs = new ArrayList<>();
List<MlFilter> 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);

View File

@ -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<PutListAction.Request, PutListAction.Response, PutListAction.RequestBuilder> {
public class PutFilterAction extends Action<PutFilterAction.Request, PutFilterAction.Response, PutFilterAction.RequestBuilder> {
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<PutListAction.Request, PutListAction.R
public static class Request extends MasterNodeReadRequest<Request> 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<PutListAction.Request, PutListAction.R
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
listDocument = new ListDocument(in);
filter = new MlFilter(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
listDocument.writeTo(out);
filter.writeTo(out);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
listDocument.toXContent(builder, params);
filter.toXContent(builder, params);
return builder;
}
@Override
public int hashCode() {
return Objects.hash(listDocument);
return Objects.hash(filter);
}
@Override
@ -117,13 +117,13 @@ public class PutListAction extends Action<PutListAction.Request, PutListAction.R
return false;
}
Request other = (Request) obj;
return Objects.equals(listDocument, other.listDocument);
return Objects.equals(filter, other.filter);
}
}
public static class RequestBuilder extends MasterNodeOperationRequestBuilder<Request, Response, RequestBuilder> {
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<PutListAction.Request, PutListAction.R
ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
TransportIndexAction transportIndexAction) {
super(settings, PutListAction.NAME, transportService, clusterService, threadPool, actionFilters,
super(settings, PutFilterAction.NAME, transportService, clusterService, threadPool, actionFilters,
indexNameExpressionResolver, Request::new);
this.transportIndexAction = transportIndexAction;
}
@ -177,11 +177,11 @@ public class PutListAction extends Action<PutListAction.Request, PutListAction.R
@Override
protected void masterOperation(Request request, ClusterState state, ActionListener<Response> 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<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
@ -190,8 +190,8 @@ public class PutListAction extends Action<PutListAction.Request, PutListAction.R
@Override
public void onFailure(Exception e) {
logger.error("Could not create list with ID [" + listId + "]", e);
throw new ResourceNotFoundException("Could not create list with ID [" + listId + "]", e);
logger.error("Could not create filter with ID [" + filterId + "]", e);
throw new ResourceNotFoundException("Could not create filter with ID [" + filterId + "]", e);
}
});
}

View File

@ -279,8 +279,8 @@ public class AnalysisConfig extends ToXContentToBytes implements Writeable {
return termFields;
}
public Set<String> extractReferencedLists() {
return detectors.stream().map(Detector::extractReferencedLists)
public Set<String> extractReferencedFilters() {
return detectors.stream().map(Detector::extractReferencedFilters)
.flatMap(Set::stream).collect(Collectors.toSet());
}

View File

@ -141,8 +141,8 @@ public class DetectionRule extends ToXContentToBytes implements Writeable {
return ruleConditions;
}
public Set<String> extractReferencedLists() {
return ruleConditions.stream().map(RuleCondition::getValueList).filter(Objects::nonNull).collect(Collectors.toSet());
public Set<String> extractReferencedFilters() {
return ruleConditions.stream().map(RuleCondition::getValueFilter).filter(Objects::nonNull).collect(Collectors.toSet());
}
@Override

View File

@ -473,9 +473,9 @@ public class Detector extends ToXContentToBytes implements Writeable {
return analysisFields.stream().filter(item -> item != null).collect(Collectors.toList());
}
public Set<String> extractReferencedLists() {
public Set<String> extractReferencedFilters() {
return detectorRules == null ? Collections.emptySet()
: detectorRules.stream().map(DetectionRule::extractReferencedLists)
: detectorRules.stream().map(DetectionRule::extractReferencedFilters)
.flatMap(Set::stream).collect(Collectors.toSet());
}

View File

@ -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<ListDocument, Void> PARSER = new ConstructingObjectParser<>(
TYPE.getPreferredName(), a -> new ListDocument((String) a[0], (List<String>) a[1]));
public static final ConstructingObjectParser<MlFilter, Void> PARSER = new ConstructingObjectParser<>(
TYPE.getPreferredName(), a -> new MlFilter((String) a[0], (List<String>) 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<String> items;
public ListDocument(String id, List<String> items) {
public MlFilter(String id, List<String> 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);
}

View File

@ -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<RuleCondition, Void> 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);

View File

@ -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";

View File

@ -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<Set<ListDocument>> handler, Consumer<Exception> errorHandler, String... ids) {
mget(ML_INFO_INDEX, ListDocument.TYPE.getPreferredName(), ids, handler, errorHandler, ListDocument.PARSER);
public void getFilters(Consumer<Set<MlFilter>> handler, Consumer<Exception> errorHandler, String... ids) {
mget(ML_INFO_INDEX, MlFilter.TYPE.getPreferredName(), ids, handler, errorHandler, MlFilter.PARSER);
}
/**

View File

@ -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<Path> filesToDelete;
private Logger logger;
private boolean ignoreDowntime;
private Set<ListDocument> referencedLists;
private Set<MlFilter> 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<ListDocument> lists) {
referencedLists = lists;
public AutodetectBuilder referencedFilters(Set<MlFilter> 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();

View File

@ -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<ListDocument> list,
AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set<MlFilter> filters,
boolean ignoreDowntime, ExecutorService executorService);
}

View File

@ -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<Exception> 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<ListDocument> lists);
void accept(ModelSnapshot modelSnapshot, Quantiles quantiles, Set<MlFilter> filters);
}
AutodetectCommunicator create(String jobId, ModelSnapshot modelSnapshot, Quantiles quantiles, Set<ListDocument> lists,
AutodetectCommunicator create(String jobId, ModelSnapshot modelSnapshot, Quantiles quantiles, Set<MlFilter> filters,
boolean ignoreDowntime, Consumer<Exception> 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) {

View File

@ -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<ListDocument> list,
public AutodetectProcess createAutodetectProcess(Job job, ModelSnapshot modelSnapshot, Quantiles quantiles, Set<MlFilter> filters,
boolean ignoreDowntime, ExecutorService executorService) {
List<Path> 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<ListDocument> lists, ProcessPipes processPipes,
private void createNativeProcess(Job job, Quantiles quantiles, Set<MlFilter> filters, ProcessPipes processPipes,
boolean ignoreDowntime, List<Path> 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

View File

@ -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<ListDocument> lists;
private final Set<MlFilter> filters;
private final OutputStreamWriter writer;
private final Logger logger;
public FieldConfigWriter(AnalysisConfig config, Set<ListDocument> lists,
public FieldConfigWriter(AnalysisConfig config, Set<MlFilter> 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);
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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

View File

@ -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<PutListAction.Request> {
public class CreateFilterActionRequestTests extends AbstractStreamableXContentTestCase<PutFilterAction.Request> {
@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);
}
}

View File

@ -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<GetListAction.Request> {
public class GetFiltersActionRequestTests extends AbstractStreamableTestCase<GetFiltersAction.Request> {
@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);

View File

@ -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<GetListAction.Response> {
public class GetFiltersActionResponseTests extends AbstractStreamableTestCase<GetFiltersAction.Response> {
@Override
protected Response createTestInstance() {
final QueryPage<ListDocument> result;
final QueryPage<MlFilter> 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);
}

View File

@ -398,8 +398,10 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
}
public void testExtractReferencedLists() {
DetectionRule rule1 = new DetectionRule(null, null, Connective.OR, Arrays.asList(RuleCondition.createCategorical("foo", "list1")));
DetectionRule rule2 = new DetectionRule(null, null, Connective.OR, Arrays.asList(RuleCondition.createCategorical("foo", "list2")));
DetectionRule rule1 =
new DetectionRule(null, null, Connective.OR, Arrays.asList(RuleCondition.createCategorical("foo", "filter1")));
DetectionRule rule2 =
new DetectionRule(null, null, Connective.OR, Arrays.asList(RuleCondition.createCategorical("foo", "filter2")));
Detector.Builder detector1 = new Detector.Builder("count", null);
detector1.setByFieldName("foo");
detector1.setDetectorRules(Arrays.asList(rule1));
@ -409,7 +411,7 @@ public class AnalysisConfigTests extends AbstractSerializingTestCase<AnalysisCon
AnalysisConfig config = new AnalysisConfig.Builder(
Arrays.asList(detector1.build(), detector2.build(), new Detector.Builder("count", null).build())).build();
assertEquals(new HashSet<>(Arrays.asList("list1", "list2")), config.extractReferencedLists());
assertEquals(new HashSet<>(Arrays.asList("filter1", "filter2")), config.extractReferencedFilters());
}
private static AnalysisConfig createFullyPopulatedConfig() {

View File

@ -22,11 +22,11 @@ public class DetectionRuleTests extends AbstractSerializingTestCase<DetectionRul
new RuleCondition(RuleConditionType.NUMERICAL_ACTUAL, "field", "value", new Condition(Operator.GT, "5"), null);
List<RuleCondition> 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() {

View File

@ -111,7 +111,7 @@ public class DetectorTests extends AbstractSerializingTestCase<Detector> {
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() {

View File

@ -13,36 +13,37 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ListDocumentTests extends AbstractSerializingTestCase<ListDocument> {
public class MlFilterTests extends AbstractSerializingTestCase<MlFilter> {
@Override
protected ListDocument createTestInstance() {
protected MlFilter createTestInstance() {
int size = randomInt(10);
List<String> 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<ListDocument> instanceReader() {
return ListDocument::new;
protected Reader<MlFilter> 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());
}
}

View File

@ -16,12 +16,12 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
protected RuleCondition createTestInstance() {
Condition condition = null;
String fieldName = null;
String valueList = null;
String valueFilter = null;
String fieldValue = null;
RuleConditionType r = randomFrom(RuleConditionType.values());
switch (r) {
case CATEGORICAL:
valueList = randomAsciiOfLengthBetween(1, 20);
valueFilter = randomAsciiOfLengthBetween(1, 20);
if (randomBoolean()) {
fieldName = randomAsciiOfLengthBetween(1, 20);
}
@ -36,7 +36,7 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
}
break;
}
return new RuleCondition(r, fieldName, fieldValue, condition, valueList);
return new RuleCondition(r, fieldName, fieldValue, condition, valueFilter);
}
@Override
@ -50,7 +50,7 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
}
public void testConstructor() {
RuleCondition condition = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueList");
RuleCondition condition = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueFilter");
assertEquals(RuleConditionType.CATEGORICAL, condition.getConditionType());
assertNull(condition.getFieldName());
assertNull(condition.getFieldValue());
@ -58,17 +58,17 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
}
public void testEqualsGivenSameObject() {
RuleCondition condition = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueList");
RuleCondition condition = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueFilter");
assertTrue(condition.equals(condition));
}
public void testEqualsGivenString() {
assertFalse(new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "list").equals("a string"));
assertFalse(new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "filter").equals("a string"));
}
public void testEqualsGivenDifferentType() {
RuleCondition condition1 = createFullyPopulated();
RuleCondition condition2 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueList");
RuleCondition condition2 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "valueFilter");
assertFalse(condition1.equals(condition2));
assertFalse(condition2.equals(condition1));
}
@ -97,9 +97,9 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
assertFalse(condition2.equals(condition1));
}
public void testEqualsGivenDifferentValueList() {
RuleCondition condition1 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "myList");
RuleCondition condition2 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "myListaaa");
public void testEqualsGivenDifferentValueFilter() {
RuleCondition condition1 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "myFilter");
RuleCondition condition2 = new RuleCondition(RuleConditionType.CATEGORICAL, null, null, null, "myFilteraaa");
assertFalse(condition1.equals(condition2));
assertFalse(condition2.equals(condition1));
}
@ -121,16 +121,16 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
assertEquals("Invalid detector rule: a categorical rule_condition does not support field_value", e.getMessage());
}
public void testVerify_GivenCategoricalWithoutValueList() {
public void testVerify_GivenCategoricalWithoutValueFilter() {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> 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<RuleConditio
assertEquals("Invalid detector rule: a numerical rule_condition with field_name requires that field_value is set", e.getMessage());
}
public void testVerify_GivenNumericalTypicalWithValueList() {
public void testVerify_GivenNumericalTypicalWithValueFilter() {
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_GivenNumericalTypicalWithoutCondition() {
@ -157,10 +157,10 @@ public class RuleConditionTests extends AbstractSerializingTestCase<RuleConditio
assertEquals("Invalid detector rule: a numerical rule_condition requires condition to be set", e.getMessage());
}
public void testVerify_GivenNumericalDiffAbsWithValueList() {
public void testVerify_GivenNumericalDiffAbsWithValueFilter() {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> 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<RuleConditio
public void testVerify_GivenValidCategorical() {
// no validation error:
new RuleCondition(RuleConditionType.CATEGORICAL, "metric", null, null, "myList");
new RuleCondition(RuleConditionType.CATEGORICAL, "metric", null, null, "myFilter");
}
public void testVerify_GivenValidNumericalActual() {

View File

@ -21,7 +21,7 @@ import org.elasticsearch.xpack.ml.job.results.CategoryDefinition;
import org.elasticsearch.xpack.ml.job.results.ReservedFieldNames;
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 com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
@ -84,7 +84,7 @@ public class ElasticsearchMappingsTests extends ESTestCase {
overridden.add(CategorizerState.TYPE);
overridden.add(CategoryDefinition.TYPE.getPreferredName());
overridden.add(Job.TYPE);
overridden.add(ListDocument.TYPE.getPreferredName());
overridden.add(MlFilter.TYPE.getPreferredName());
overridden.add(ModelState.TYPE.getPreferredName());
overridden.add(ModelSizeStats.RESULT_TYPE_FIELD.getPreferredName());
overridden.add(ModelSnapshot.TYPE.getPreferredName());
@ -93,8 +93,8 @@ public class ElasticsearchMappingsTests extends ESTestCase {
// These are not reserved because they're in the ml-int index
// not the job indices
overridden.add(ListDocument.ID.getPreferredName());
overridden.add(ListDocument.ITEMS.getPreferredName());
overridden.add(MlFilter.ID.getPreferredName());
overridden.add(MlFilter.ITEMS.getPreferredName());
// These are not reserved because they're analyzed strings, i.e. the
// same type as user-specified fields

View File

@ -20,7 +20,7 @@ import org.elasticsearch.xpack.ml.job.config.DataDescription;
import org.elasticsearch.xpack.ml.job.config.Detector;
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;
@ -139,7 +139,7 @@ public class AutodetectProcessManagerTests extends ESTestCase {
AutodetectProcess autodetectProcess = mock(AutodetectProcess.class);
when(autodetectProcess.isProcessAlive()).thenReturn(true);
when(autodetectProcess.getPersistStream()).thenReturn(new ByteArrayInputStream(new byte[0]));
AutodetectProcessFactory autodetectProcessFactory = (j, modelSnapshot, quantiles, lists, i, e) -> 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<ListDocument> lists = new HashSet<>();
Set<MlFilter> 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<ListDocument> lists = new HashSet<>();
Set<MlFilter> 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<ListDocument> lists = new HashSet<>();
Set<MlFilter> 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;
}

View File

@ -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<ListDocument> lists;
private Set<MlFilter> 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));
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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"

View File

@ -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: [] }

View File

@ -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: [] }