[ML] Rename SpecialEvents -> ScheduledEvents (elastic/x-pack-elasticsearch#3485)
* Rename SpecialEvents -> ScheduledEvents Original commit: elastic/x-pack-elasticsearch@4bfc52c435
This commit is contained in:
parent
f508e14e06
commit
2eb3f02e40
|
@ -7,7 +7,7 @@ package org.elasticsearch.xpack.ml;
|
||||||
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.ElasticsearchMappings;
|
import org.elasticsearch.xpack.ml.job.persistence.ElasticsearchMappings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -39,10 +39,10 @@ public final class MlMetaIndex {
|
||||||
.startObject(Calendar.JOB_IDS.getPreferredName())
|
.startObject(Calendar.JOB_IDS.getPreferredName())
|
||||||
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.KEYWORD)
|
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.KEYWORD)
|
||||||
.endObject()
|
.endObject()
|
||||||
.startObject(SpecialEvent.START_TIME.getPreferredName())
|
.startObject(ScheduledEvent.START_TIME.getPreferredName())
|
||||||
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
|
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
|
||||||
.endObject()
|
.endObject()
|
||||||
.startObject(SpecialEvent.END_TIME.getPreferredName())
|
.startObject(ScheduledEvent.END_TIME.getPreferredName())
|
||||||
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
|
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
|
|
|
@ -6,38 +6,27 @@
|
||||||
package org.elasticsearch.xpack.ml.action;
|
package org.elasticsearch.xpack.ml.action;
|
||||||
|
|
||||||
import org.elasticsearch.action.Action;
|
import org.elasticsearch.action.Action;
|
||||||
import org.elasticsearch.action.ActionListener;
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.ActionResponse;
|
import org.elasticsearch.action.ActionResponse;
|
||||||
import org.elasticsearch.action.ValidateActions;
|
import org.elasticsearch.action.ValidateActions;
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
|
||||||
import org.elasticsearch.action.support.HandledTransportAction;
|
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
|
||||||
import org.elasticsearch.transport.TransportService;
|
|
||||||
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
import org.elasticsearch.xpack.ml.action.util.PageParams;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.SpecialEventsQueryBuilder;
|
|
||||||
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Request, GetCalendarEventsAction.Response,
|
public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Request, GetCalendarEventsAction.Response,
|
||||||
|
@ -213,36 +202,36 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
||||||
|
|
||||||
public static class Response extends ActionResponse implements ToXContentObject {
|
public static class Response extends ActionResponse implements ToXContentObject {
|
||||||
|
|
||||||
private QueryPage<SpecialEvent> specialEvents;
|
private QueryPage<ScheduledEvent> scheduledEvents;
|
||||||
|
|
||||||
Response() {
|
Response() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response(QueryPage<SpecialEvent> specialEvents) {
|
public Response(QueryPage<ScheduledEvent> scheduledEvents) {
|
||||||
this.specialEvents = specialEvents;
|
this.scheduledEvents = scheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
specialEvents = new QueryPage<>(in, SpecialEvent::new);
|
scheduledEvents = new QueryPage<>(in, ScheduledEvent::new);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
specialEvents.writeTo(out);
|
scheduledEvents.writeTo(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
return specialEvents.toXContent(builder, params);
|
return scheduledEvents.toXContent(builder, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(specialEvents);
|
return Objects.hash(scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -254,7 +243,7 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Response other = (Response) obj;
|
Response other = (Response) obj;
|
||||||
return Objects.equals(specialEvents, other.specialEvents);
|
return Objects.equals(scheduledEvents, other.scheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,53 +6,33 @@
|
||||||
package org.elasticsearch.xpack.ml.action;
|
package org.elasticsearch.xpack.ml.action;
|
||||||
|
|
||||||
import org.elasticsearch.action.Action;
|
import org.elasticsearch.action.Action;
|
||||||
import org.elasticsearch.action.ActionListener;
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionRequestBuilder;
|
import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.bulk.BulkAction;
|
|
||||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
|
||||||
import org.elasticsearch.action.bulk.BulkResponse;
|
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
|
||||||
import org.elasticsearch.action.support.ActionFilters;
|
|
||||||
import org.elasticsearch.action.support.HandledTransportAction;
|
|
||||||
import org.elasticsearch.action.support.WriteRequest;
|
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
import org.elasticsearch.common.xcontent.XContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
|
||||||
import org.elasticsearch.transport.TransportService;
|
|
||||||
import org.elasticsearch.xpack.ml.MlMetaIndex;
|
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.messages.Messages;
|
import org.elasticsearch.xpack.ml.job.messages.Messages;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
|
||||||
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.ClientHelper.ML_ORIGIN;
|
|
||||||
import static org.elasticsearch.xpack.ClientHelper.executeAsyncWithOrigin;
|
import static org.elasticsearch.xpack.ClientHelper.executeAsyncWithOrigin;
|
||||||
|
|
||||||
public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Request, PostCalendarEventsAction.Response,
|
public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Request, PostCalendarEventsAction.Response,
|
||||||
|
@ -60,7 +40,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
public static final PostCalendarEventsAction INSTANCE = new PostCalendarEventsAction();
|
public static final PostCalendarEventsAction INSTANCE = new PostCalendarEventsAction();
|
||||||
public static final String NAME = "cluster:admin/xpack/ml/calendars/events/post";
|
public static final String NAME = "cluster:admin/xpack/ml/calendars/events/post";
|
||||||
|
|
||||||
public static final ParseField SPECIAL_EVENTS = new ParseField("special_events");
|
public static final ParseField EVENTS = new ParseField("events");
|
||||||
|
|
||||||
private PostCalendarEventsAction() {
|
private PostCalendarEventsAction() {
|
||||||
super(NAME);
|
super(NAME);
|
||||||
|
@ -79,7 +59,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
public static class Request extends ActionRequest {
|
public static class Request extends ActionRequest {
|
||||||
|
|
||||||
public static Request parseRequest(String calendarId, BytesReference data, XContentType contentType) throws IOException {
|
public static Request parseRequest(String calendarId, BytesReference data, XContentType contentType) throws IOException {
|
||||||
List<SpecialEvent.Builder> events = new ArrayList<>();
|
List<ScheduledEvent.Builder> events = new ArrayList<>();
|
||||||
|
|
||||||
XContent xContent = contentType.xContent();
|
XContent xContent = contentType.xContent();
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
|
@ -95,17 +75,17 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
|
|
||||||
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, data.slice(from, nextMarker - from))) {
|
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, data.slice(from, nextMarker - from))) {
|
||||||
try {
|
try {
|
||||||
SpecialEvent.Builder event = SpecialEvent.PARSER.apply(parser, null);
|
ScheduledEvent.Builder event = ScheduledEvent.PARSER.apply(parser, null);
|
||||||
events.add(event);
|
events.add(event);
|
||||||
} catch (ParsingException pe) {
|
} catch (ParsingException pe) {
|
||||||
throw ExceptionsHelper.badRequestException("Failed to parse special event on line [" + lineNumber + "]", pe);
|
throw ExceptionsHelper.badRequestException("Failed to parse scheduled event on line [" + lineNumber + "]", pe);
|
||||||
}
|
}
|
||||||
|
|
||||||
from = nextMarker + 1;
|
from = nextMarker + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SpecialEvent.Builder event: events) {
|
for (ScheduledEvent.Builder event: events) {
|
||||||
if (event.getCalendarId() != null && event.getCalendarId().equals(calendarId) == false) {
|
if (event.getCalendarId() != null && event.getCalendarId().equals(calendarId) == false) {
|
||||||
throw ExceptionsHelper.badRequestException(Messages.getMessage(Messages.INCONSISTENT_ID,
|
throw ExceptionsHelper.badRequestException(Messages.getMessage(Messages.INCONSISTENT_ID,
|
||||||
Calendar.ID.getPreferredName(), event.getCalendarId(), calendarId));
|
Calendar.ID.getPreferredName(), event.getCalendarId(), calendarId));
|
||||||
|
@ -114,7 +94,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
// Set the calendar Id in case it is null
|
// Set the calendar Id in case it is null
|
||||||
event.calendarId(calendarId);
|
event.calendarId(calendarId);
|
||||||
}
|
}
|
||||||
return new Request(calendarId, events.stream().map(SpecialEvent.Builder::build).collect(Collectors.toList()));
|
return new Request(calendarId, events.stream().map(ScheduledEvent.Builder::build).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findNextMarker(byte marker, int from, BytesReference data, int length) {
|
private static int findNextMarker(byte marker, int from, BytesReference data, int length) {
|
||||||
|
@ -130,22 +110,22 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
}
|
}
|
||||||
|
|
||||||
private String calendarId;
|
private String calendarId;
|
||||||
private List<SpecialEvent> specialEvents;
|
private List<ScheduledEvent> scheduledEvents;
|
||||||
|
|
||||||
Request() {
|
Request() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(String calendarId, List<SpecialEvent> specialEvents) {
|
public Request(String calendarId, List<ScheduledEvent> scheduledEvents) {
|
||||||
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
|
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
|
||||||
this.specialEvents = ExceptionsHelper.requireNonNull(specialEvents, SPECIAL_EVENTS.getPreferredName());
|
this.scheduledEvents = ExceptionsHelper.requireNonNull(scheduledEvents, EVENTS.getPreferredName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCalendarId() {
|
public String getCalendarId() {
|
||||||
return calendarId;
|
return calendarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SpecialEvent> getSpecialEvents() {
|
public List<ScheduledEvent> getScheduledEvents() {
|
||||||
return specialEvents;
|
return scheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,19 +137,19 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
calendarId = in.readString();
|
calendarId = in.readString();
|
||||||
specialEvents = in.readList(SpecialEvent::new);
|
scheduledEvents = in.readList(ScheduledEvent::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeString(calendarId);
|
out.writeString(calendarId);
|
||||||
out.writeList(specialEvents);
|
out.writeList(scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(calendarId, specialEvents);
|
return Objects.hash(calendarId, scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,7 +161,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Request other = (Request) obj;
|
Request other = (Request) obj;
|
||||||
return Objects.equals(calendarId, other.calendarId) && Objects.equals(specialEvents, other.specialEvents);
|
return Objects.equals(calendarId, other.calendarId) && Objects.equals(scheduledEvents, other.scheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,41 +174,41 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
|
|
||||||
public static class Response extends AcknowledgedResponse implements ToXContentObject {
|
public static class Response extends AcknowledgedResponse implements ToXContentObject {
|
||||||
|
|
||||||
private List<SpecialEvent> specialEvent;
|
private List<ScheduledEvent> scheduledEvents;
|
||||||
|
|
||||||
Response() {
|
Response() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response(List<SpecialEvent> specialEvents) {
|
public Response(List<ScheduledEvent> scheduledEvents) {
|
||||||
super(true);
|
super(true);
|
||||||
this.specialEvent = specialEvents;
|
this.scheduledEvents = scheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
readAcknowledged(in);
|
readAcknowledged(in);
|
||||||
in.readList(SpecialEvent::new);
|
in.readList(ScheduledEvent::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
writeAcknowledged(out);
|
writeAcknowledged(out);
|
||||||
out.writeList(specialEvent);
|
out.writeList(scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(SPECIAL_EVENTS.getPreferredName(), specialEvent);
|
builder.field(EVENTS.getPreferredName(), scheduledEvents);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(isAcknowledged(), specialEvent);
|
return Objects.hash(isAcknowledged(), scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -240,7 +220,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Response other = (Response) obj;
|
Response other = (Response) obj;
|
||||||
return Objects.equals(isAcknowledged(), other.isAcknowledged()) && Objects.equals(specialEvent, other.specialEvent);
|
return Objects.equals(isAcknowledged(), other.isAcknowledged()) && Objects.equals(scheduledEvents, other.scheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,17 +111,17 @@ public class UpdateProcessAction extends
|
||||||
|
|
||||||
private ModelPlotConfig modelPlotConfig;
|
private ModelPlotConfig modelPlotConfig;
|
||||||
private List<JobUpdate.DetectorUpdate> detectorUpdates;
|
private List<JobUpdate.DetectorUpdate> detectorUpdates;
|
||||||
private boolean updateSpecialEvents = false;
|
private boolean updateScheduledEvents = false;
|
||||||
|
|
||||||
Request() {
|
Request() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(String jobId, ModelPlotConfig modelPlotConfig, List<JobUpdate.DetectorUpdate> detectorUpdates,
|
public Request(String jobId, ModelPlotConfig modelPlotConfig, List<JobUpdate.DetectorUpdate> detectorUpdates,
|
||||||
boolean updateSpecialEvents) {
|
boolean updateScheduledEvents) {
|
||||||
super(jobId);
|
super(jobId);
|
||||||
this.modelPlotConfig = modelPlotConfig;
|
this.modelPlotConfig = modelPlotConfig;
|
||||||
this.detectorUpdates = detectorUpdates;
|
this.detectorUpdates = detectorUpdates;
|
||||||
this.updateSpecialEvents = updateSpecialEvents;
|
this.updateScheduledEvents = updateScheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModelPlotConfig getModelPlotConfig() {
|
public ModelPlotConfig getModelPlotConfig() {
|
||||||
|
@ -132,8 +132,8 @@ public class UpdateProcessAction extends
|
||||||
return detectorUpdates;
|
return detectorUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateSpecialEvents() {
|
public boolean isUpdateScheduledEvents() {
|
||||||
return updateSpecialEvents;
|
return updateScheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -144,7 +144,7 @@ public class UpdateProcessAction extends
|
||||||
detectorUpdates = in.readList(JobUpdate.DetectorUpdate::new);
|
detectorUpdates = in.readList(JobUpdate.DetectorUpdate::new);
|
||||||
}
|
}
|
||||||
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
|
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
updateSpecialEvents = in.readBoolean();
|
updateScheduledEvents = in.readBoolean();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +158,13 @@ public class UpdateProcessAction extends
|
||||||
out.writeList(detectorUpdates);
|
out.writeList(detectorUpdates);
|
||||||
}
|
}
|
||||||
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
|
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
out.writeBoolean(updateSpecialEvents);
|
out.writeBoolean(updateScheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(getJobId(), modelPlotConfig, detectorUpdates, updateSpecialEvents);
|
return Objects.hash(getJobId(), modelPlotConfig, detectorUpdates, updateScheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -180,7 +180,7 @@ public class UpdateProcessAction extends
|
||||||
return Objects.equals(getJobId(), other.getJobId()) &&
|
return Objects.equals(getJobId(), other.getJobId()) &&
|
||||||
Objects.equals(modelPlotConfig, other.modelPlotConfig) &&
|
Objects.equals(modelPlotConfig, other.modelPlotConfig) &&
|
||||||
Objects.equals(detectorUpdates, other.detectorUpdates) &&
|
Objects.equals(detectorUpdates, other.detectorUpdates) &&
|
||||||
Objects.equals(updateSpecialEvents, other.updateSpecialEvents);
|
Objects.equals(updateScheduledEvents, other.updateScheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,24 +33,24 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class SpecialEvent implements ToXContentObject, Writeable {
|
public class ScheduledEvent implements ToXContentObject, Writeable {
|
||||||
|
|
||||||
public static final ParseField DESCRIPTION = new ParseField("description");
|
public static final ParseField DESCRIPTION = new ParseField("description");
|
||||||
public static final ParseField START_TIME = new ParseField("start_time");
|
public static final ParseField START_TIME = new ParseField("start_time");
|
||||||
public static final ParseField END_TIME = new ParseField("end_time");
|
public static final ParseField END_TIME = new ParseField("end_time");
|
||||||
public static final ParseField TYPE = new ParseField("type");
|
public static final ParseField TYPE = new ParseField("type");
|
||||||
|
|
||||||
public static final ParseField RESULTS_FIELD = new ParseField("special_events");
|
public static final ParseField RESULTS_FIELD = new ParseField("events");
|
||||||
|
|
||||||
public static final String SPECIAL_EVENT_TYPE = "special_event";
|
public static final String SCHEDULED_EVENT_TYPE = "scheduled_event";
|
||||||
public static final String DOCUMENT_ID_PREFIX = "event_";
|
public static final String DOCUMENT_ID_PREFIX = "event_";
|
||||||
|
|
||||||
public static final ObjectParser<SpecialEvent.Builder, Void> PARSER =
|
public static final ObjectParser<ScheduledEvent.Builder, Void> PARSER =
|
||||||
new ObjectParser<>("special_event", Builder::new);
|
new ObjectParser<>("scheduled_event", Builder::new);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareString(SpecialEvent.Builder::description, DESCRIPTION);
|
PARSER.declareString(ScheduledEvent.Builder::description, DESCRIPTION);
|
||||||
PARSER.declareField(SpecialEvent.Builder::startTime, p -> {
|
PARSER.declareField(ScheduledEvent.Builder::startTime, p -> {
|
||||||
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
|
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
|
||||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
|
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
|
||||||
} else if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
} else if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
|
@ -59,7 +59,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"unexpected token [" + p.currentToken() + "] for [" + START_TIME.getPreferredName() + "]");
|
"unexpected token [" + p.currentToken() + "] for [" + START_TIME.getPreferredName() + "]");
|
||||||
}, START_TIME, ObjectParser.ValueType.VALUE);
|
}, START_TIME, ObjectParser.ValueType.VALUE);
|
||||||
PARSER.declareField(SpecialEvent.Builder::endTime, p -> {
|
PARSER.declareField(ScheduledEvent.Builder::endTime, p -> {
|
||||||
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
|
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
|
||||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
|
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
|
||||||
} else if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
} else if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
|
||||||
|
@ -69,7 +69,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
"unexpected token [" + p.currentToken() + "] for [" + END_TIME.getPreferredName() + "]");
|
"unexpected token [" + p.currentToken() + "] for [" + END_TIME.getPreferredName() + "]");
|
||||||
}, END_TIME, ObjectParser.ValueType.VALUE);
|
}, END_TIME, ObjectParser.ValueType.VALUE);
|
||||||
|
|
||||||
PARSER.declareString(SpecialEvent.Builder::calendarId, Calendar.ID);
|
PARSER.declareString(ScheduledEvent.Builder::calendarId, Calendar.ID);
|
||||||
PARSER.declareString((builder, s) -> {}, TYPE);
|
PARSER.declareString((builder, s) -> {}, TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +82,14 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
private final ZonedDateTime endTime;
|
private final ZonedDateTime endTime;
|
||||||
private final String calendarId;
|
private final String calendarId;
|
||||||
|
|
||||||
SpecialEvent(String description, ZonedDateTime startTime, ZonedDateTime endTime, String calendarId) {
|
ScheduledEvent(String description, ZonedDateTime startTime, ZonedDateTime endTime, String calendarId) {
|
||||||
this.description = Objects.requireNonNull(description);
|
this.description = Objects.requireNonNull(description);
|
||||||
this.startTime = Objects.requireNonNull(startTime);
|
this.startTime = Objects.requireNonNull(startTime);
|
||||||
this.endTime = Objects.requireNonNull(endTime);
|
this.endTime = Objects.requireNonNull(endTime);
|
||||||
this.calendarId = Objects.requireNonNull(calendarId);
|
this.calendarId = Objects.requireNonNull(calendarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEvent(StreamInput in) throws IOException {
|
public ScheduledEvent(StreamInput in) throws IOException {
|
||||||
description = in.readString();
|
description = in.readString();
|
||||||
startTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.readVLong()), ZoneOffset.UTC);
|
startTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.readVLong()), ZoneOffset.UTC);
|
||||||
endTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.readVLong()), ZoneOffset.UTC);
|
endTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.readVLong()), ZoneOffset.UTC);
|
||||||
|
@ -113,7 +113,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the special event to a detection rule.
|
* Convert the scheduled event to a detection rule.
|
||||||
* The rule will have 2 time based conditions for the start and
|
* The rule will have 2 time based conditions for the start and
|
||||||
* end of the event.
|
* end of the event.
|
||||||
*
|
*
|
||||||
|
@ -156,7 +156,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
builder.dateField(END_TIME.getPreferredName(), END_TIME.getPreferredName() + "_string", endTime.toInstant().toEpochMilli());
|
builder.dateField(END_TIME.getPreferredName(), END_TIME.getPreferredName() + "_string", endTime.toInstant().toEpochMilli());
|
||||||
builder.field(Calendar.ID.getPreferredName(), calendarId);
|
builder.field(Calendar.ID.getPreferredName(), calendarId);
|
||||||
if (params.paramAsBoolean(MlMetaIndex.INCLUDE_TYPE_KEY, false)) {
|
if (params.paramAsBoolean(MlMetaIndex.INCLUDE_TYPE_KEY, false)) {
|
||||||
builder.field(TYPE.getPreferredName(), SPECIAL_EVENT_TYPE);
|
builder.field(TYPE.getPreferredName(), SCHEDULED_EVENT_TYPE);
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -168,11 +168,11 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(obj instanceof SpecialEvent)) {
|
if (!(obj instanceof ScheduledEvent)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecialEvent other = (SpecialEvent) obj;
|
ScheduledEvent other = (ScheduledEvent) obj;
|
||||||
// In Java 8 the tests pass with ZonedDateTime.isEquals() or ZonedDateTime.toInstant.equals()
|
// In Java 8 the tests pass with ZonedDateTime.isEquals() or ZonedDateTime.toInstant.equals()
|
||||||
// but in Java 9 & 10 the same tests fail.
|
// but in Java 9 & 10 the same tests fail.
|
||||||
// Both isEquals() and toInstant.equals() work the same; convert to epoch seconds and
|
// Both isEquals() and toInstant.equals() work the same; convert to epoch seconds and
|
||||||
|
@ -223,7 +223,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
return calendarId;
|
return calendarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEvent build() {
|
public ScheduledEvent build() {
|
||||||
if (description == null) {
|
if (description == null) {
|
||||||
throw ExceptionsHelper.badRequestException(
|
throw ExceptionsHelper.badRequestException(
|
||||||
Messages.getMessage(Messages.FIELD_CANNOT_BE_NULL, DESCRIPTION.getPreferredName()));
|
Messages.getMessage(Messages.FIELD_CANNOT_BE_NULL, DESCRIPTION.getPreferredName()));
|
||||||
|
@ -245,11 +245,11 @@ public class SpecialEvent implements ToXContentObject, Writeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startTime.isBefore(endTime) == false) {
|
if (startTime.isBefore(endTime) == false) {
|
||||||
throw ExceptionsHelper.badRequestException("Special event start time [" + startTime +
|
throw ExceptionsHelper.badRequestException("Event start time [" + startTime +
|
||||||
"] must come before end time [" + endTime + "]");
|
"] must come before end time [" + endTime + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SpecialEvent(description, startTime, endTime, calendarId);
|
return new ScheduledEvent(description, startTime, endTime, calendarId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
public class JobUpdate implements Writeable, ToXContentObject {
|
public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
public static final ParseField DETECTORS = new ParseField("detectors");
|
public static final ParseField DETECTORS = new ParseField("detectors");
|
||||||
public static final ParseField UPDATE_SPECIAL_EVENTS = new ParseField("update_special_events");
|
public static final ParseField UPDATE_SCHEDULED_EVENTS = new ParseField("update_scheduled_events");
|
||||||
|
|
||||||
public static final ConstructingObjectParser<Builder, Void> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<Builder, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
"job_update", args -> new Builder((String) args[0]));
|
"job_update", args -> new Builder((String) args[0]));
|
||||||
|
@ -50,7 +50,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
PARSER.declareField(Builder::setCustomSettings, (p, c) -> p.map(), Job.CUSTOM_SETTINGS, ObjectParser.ValueType.OBJECT);
|
PARSER.declareField(Builder::setCustomSettings, (p, c) -> p.map(), Job.CUSTOM_SETTINGS, ObjectParser.ValueType.OBJECT);
|
||||||
PARSER.declareString(Builder::setModelSnapshotId, Job.MODEL_SNAPSHOT_ID);
|
PARSER.declareString(Builder::setModelSnapshotId, Job.MODEL_SNAPSHOT_ID);
|
||||||
PARSER.declareLong(Builder::setEstablishedModelMemory, Job.ESTABLISHED_MODEL_MEMORY);
|
PARSER.declareLong(Builder::setEstablishedModelMemory, Job.ESTABLISHED_MODEL_MEMORY);
|
||||||
PARSER.declareBoolean(Builder::setUpdateSpecialEvents, UPDATE_SPECIAL_EVENTS);
|
PARSER.declareBoolean(Builder::setUpdateScheduledEvents, UPDATE_SCHEDULED_EVENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
private final Map<String, Object> customSettings;
|
private final Map<String, Object> customSettings;
|
||||||
private final String modelSnapshotId;
|
private final String modelSnapshotId;
|
||||||
private final Long establishedModelMemory;
|
private final Long establishedModelMemory;
|
||||||
private final boolean updateSpecialEvents;
|
private final boolean updateScheduledEvents;
|
||||||
|
|
||||||
private JobUpdate(String jobId, @Nullable List<String> groups, @Nullable String description,
|
private JobUpdate(String jobId, @Nullable List<String> groups, @Nullable String description,
|
||||||
@Nullable List<DetectorUpdate> detectorUpdates, @Nullable ModelPlotConfig modelPlotConfig,
|
@Nullable List<DetectorUpdate> detectorUpdates, @Nullable ModelPlotConfig modelPlotConfig,
|
||||||
|
@ -83,7 +83,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
@Nullable Long renormalizationWindowDays, @Nullable Long resultsRetentionDays,
|
@Nullable Long renormalizationWindowDays, @Nullable Long resultsRetentionDays,
|
||||||
@Nullable Long modelSnapshotRetentionDays, @Nullable List<String> categorisationFilters,
|
@Nullable Long modelSnapshotRetentionDays, @Nullable List<String> categorisationFilters,
|
||||||
@Nullable Map<String, Object> customSettings, @Nullable String modelSnapshotId,
|
@Nullable Map<String, Object> customSettings, @Nullable String modelSnapshotId,
|
||||||
@Nullable Long establishedModelMemory, boolean updateSpecialEvents) {
|
@Nullable Long establishedModelMemory, boolean updateScheduledEvents) {
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
@ -98,7 +98,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
this.customSettings = customSettings;
|
this.customSettings = customSettings;
|
||||||
this.modelSnapshotId = modelSnapshotId;
|
this.modelSnapshotId = modelSnapshotId;
|
||||||
this.establishedModelMemory = establishedModelMemory;
|
this.establishedModelMemory = establishedModelMemory;
|
||||||
this.updateSpecialEvents = updateSpecialEvents;
|
this.updateScheduledEvents = updateScheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobUpdate(StreamInput in) throws IOException {
|
public JobUpdate(StreamInput in) throws IOException {
|
||||||
|
@ -135,9 +135,9 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
|
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
updateSpecialEvents = in.readBoolean();
|
updateScheduledEvents = in.readBoolean();
|
||||||
} else {
|
} else {
|
||||||
updateSpecialEvents = false;
|
updateScheduledEvents = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
|
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
|
||||||
out.writeBoolean(updateSpecialEvents);
|
out.writeBoolean(updateScheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +234,8 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
return modelPlotConfig != null || detectorUpdates != null;
|
return modelPlotConfig != null || detectorUpdates != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateSpecialEvents() {
|
public boolean isUpdateScheduledEvents() {
|
||||||
return updateSpecialEvents;
|
return updateScheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -281,7 +281,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
if (establishedModelMemory != null) {
|
if (establishedModelMemory != null) {
|
||||||
builder.field(Job.ESTABLISHED_MODEL_MEMORY.getPreferredName(), establishedModelMemory);
|
builder.field(Job.ESTABLISHED_MODEL_MEMORY.getPreferredName(), establishedModelMemory);
|
||||||
}
|
}
|
||||||
builder.field(UPDATE_SPECIAL_EVENTS.getPreferredName(), updateSpecialEvents);
|
builder.field(UPDATE_SCHEDULED_EVENTS.getPreferredName(), updateScheduledEvents);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -419,14 +419,14 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
&& Objects.equals(this.customSettings, that.customSettings)
|
&& Objects.equals(this.customSettings, that.customSettings)
|
||||||
&& Objects.equals(this.modelSnapshotId, that.modelSnapshotId)
|
&& Objects.equals(this.modelSnapshotId, that.modelSnapshotId)
|
||||||
&& Objects.equals(this.establishedModelMemory, that.establishedModelMemory)
|
&& Objects.equals(this.establishedModelMemory, that.establishedModelMemory)
|
||||||
&& Objects.equals(this.updateSpecialEvents, that.updateSpecialEvents);
|
&& Objects.equals(this.updateScheduledEvents, that.updateScheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, renormalizationWindowDays,
|
return Objects.hash(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, renormalizationWindowDays,
|
||||||
backgroundPersistInterval, modelSnapshotRetentionDays, resultsRetentionDays, categorizationFilters, customSettings,
|
backgroundPersistInterval, modelSnapshotRetentionDays, resultsRetentionDays, categorizationFilters, customSettings,
|
||||||
modelSnapshotId, establishedModelMemory, updateSpecialEvents);
|
modelSnapshotId, establishedModelMemory, updateScheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DetectorUpdate implements Writeable, ToXContentObject {
|
public static class DetectorUpdate implements Writeable, ToXContentObject {
|
||||||
|
@ -536,7 +536,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
private Map<String, Object> customSettings;
|
private Map<String, Object> customSettings;
|
||||||
private String modelSnapshotId;
|
private String modelSnapshotId;
|
||||||
private Long establishedModelMemory;
|
private Long establishedModelMemory;
|
||||||
private boolean updateSpecialEvents = false;
|
private boolean updateScheduledEvents = false;
|
||||||
|
|
||||||
public Builder(String jobId) {
|
public Builder(String jobId) {
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
|
@ -612,15 +612,15 @@ public class JobUpdate implements Writeable, ToXContentObject {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setUpdateSpecialEvents(boolean updateSpecialEvents) {
|
public Builder setUpdateScheduledEvents(boolean updateScheduledEvents) {
|
||||||
this.updateSpecialEvents = updateSpecialEvents;
|
this.updateScheduledEvents = updateScheduledEvents;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobUpdate build() {
|
public JobUpdate build() {
|
||||||
return new JobUpdate(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, backgroundPersistInterval,
|
return new JobUpdate(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, backgroundPersistInterval,
|
||||||
renormalizationWindowDays, resultsRetentionDays, modelSnapshotRetentionDays, categorizationFilters, customSettings,
|
renormalizationWindowDays, resultsRetentionDays, modelSnapshotRetentionDays, categorizationFilters, customSettings,
|
||||||
modelSnapshotId, establishedModelMemory, updateSpecialEvents);
|
modelSnapshotId, establishedModelMemory, updateScheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ import org.elasticsearch.xpack.ml.action.GetInfluencersAction;
|
||||||
import org.elasticsearch.xpack.ml.action.GetRecordsAction;
|
import org.elasticsearch.xpack.ml.action.GetRecordsAction;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery;
|
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery;
|
||||||
|
@ -366,16 +366,16 @@ public class JobProvider {
|
||||||
|
|
||||||
String jobId = job.getId();
|
String jobId = job.getId();
|
||||||
|
|
||||||
ActionListener<AutodetectParams.Builder> getSpecialEventsListener = ActionListener.wrap(
|
ActionListener<AutodetectParams.Builder> getScheduledEventsListener = ActionListener.wrap(
|
||||||
paramsBuilder -> {
|
paramsBuilder -> {
|
||||||
SpecialEventsQueryBuilder specialEventsQuery = new SpecialEventsQueryBuilder();
|
ScheduledEventsQueryBuilder scheduledEventsQueryBuilder = new ScheduledEventsQueryBuilder();
|
||||||
Date lastestRecordTime = paramsBuilder.getDataCounts().getLatestRecordTimeStamp();
|
Date lastestRecordTime = paramsBuilder.getDataCounts().getLatestRecordTimeStamp();
|
||||||
if (lastestRecordTime != null) {
|
if (lastestRecordTime != null) {
|
||||||
specialEventsQuery.after(Long.toString(lastestRecordTime.getTime()));
|
scheduledEventsQueryBuilder.after(Long.toString(lastestRecordTime.getTime()));
|
||||||
}
|
}
|
||||||
specialEventsForJob(jobId, specialEventsQuery, ActionListener.wrap(
|
scheduledEventsForJob(jobId, scheduledEventsQueryBuilder, ActionListener.wrap(
|
||||||
events -> {
|
events -> {
|
||||||
paramsBuilder.setSpecialEvents(events.results());
|
paramsBuilder.setScheduledEvents(events.results());
|
||||||
consumer.accept(paramsBuilder.build());
|
consumer.accept(paramsBuilder.build());
|
||||||
},
|
},
|
||||||
errorHandler
|
errorHandler
|
||||||
|
@ -434,7 +434,7 @@ public class JobProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpecialEventsListener.onResponse(paramsBuilder);
|
getScheduledEventsListener.onResponse(paramsBuilder);
|
||||||
},
|
},
|
||||||
errorHandler
|
errorHandler
|
||||||
), client::multiSearch);
|
), client::multiSearch);
|
||||||
|
@ -1029,19 +1029,20 @@ public class JobProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void specialEventsForJob(String jobId, SpecialEventsQueryBuilder queryBuilder, ActionListener<QueryPage<SpecialEvent>> handler) {
|
public void scheduledEventsForJob(String jobId, ScheduledEventsQueryBuilder queryBuilder,
|
||||||
|
ActionListener<QueryPage<ScheduledEvent>> handler) {
|
||||||
|
|
||||||
// Find all the calendars used by the job then the events for those calendars
|
// Find all the calendars used by the job then the events for those calendars
|
||||||
|
|
||||||
ActionListener<QueryPage<Calendar>> calendarsListener = ActionListener.wrap(
|
ActionListener<QueryPage<Calendar>> calendarsListener = ActionListener.wrap(
|
||||||
calendars -> {
|
calendars -> {
|
||||||
if (calendars.results().isEmpty()) {
|
if (calendars.results().isEmpty()) {
|
||||||
handler.onResponse(new QueryPage<>(Collections.emptyList(), 0, SpecialEvent.RESULTS_FIELD));
|
handler.onResponse(new QueryPage<>(Collections.emptyList(), 0, ScheduledEvent.RESULTS_FIELD));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> calendarIds = calendars.results().stream().map(Calendar::getId).collect(Collectors.toList());
|
List<String> calendarIds = calendars.results().stream().map(Calendar::getId).collect(Collectors.toList());
|
||||||
queryBuilder.calendarIds(calendarIds);
|
queryBuilder.calendarIds(calendarIds);
|
||||||
specialEvents(queryBuilder, handler);
|
scheduledEvents(queryBuilder, handler);
|
||||||
},
|
},
|
||||||
handler::onFailure
|
handler::onFailure
|
||||||
);
|
);
|
||||||
|
@ -1050,7 +1051,7 @@ public class JobProvider {
|
||||||
calendars(query, calendarsListener);
|
calendars(query, calendarsListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void specialEvents(SpecialEventsQueryBuilder query, ActionListener<QueryPage<SpecialEvent>> handler) {
|
public void scheduledEvents(ScheduledEventsQueryBuilder query, ActionListener<QueryPage<ScheduledEvent>> handler) {
|
||||||
SearchRequestBuilder request = client.prepareSearch(MlMetaIndex.INDEX_NAME)
|
SearchRequestBuilder request = client.prepareSearch(MlMetaIndex.INDEX_NAME)
|
||||||
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
|
||||||
.setSource(query.build());
|
.setSource(query.build());
|
||||||
|
@ -1058,14 +1059,14 @@ public class JobProvider {
|
||||||
executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, request.request(),
|
executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, request.request(),
|
||||||
ActionListener.<SearchResponse>wrap(
|
ActionListener.<SearchResponse>wrap(
|
||||||
response -> {
|
response -> {
|
||||||
List<SpecialEvent> specialEvents = new ArrayList<>();
|
List<ScheduledEvent> events = new ArrayList<>();
|
||||||
SearchHit[] hits = response.getHits().getHits();
|
SearchHit[] hits = response.getHits().getHits();
|
||||||
for (SearchHit hit : hits) {
|
for (SearchHit hit : hits) {
|
||||||
specialEvents.add(parseSearchHit(hit, SpecialEvent.PARSER, handler::onFailure).build());
|
events.add(parseSearchHit(hit, ScheduledEvent.PARSER, handler::onFailure).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.onResponse(new QueryPage<>(specialEvents, response.getHits().getTotalHits(),
|
handler.onResponse(new QueryPage<>(events, response.getHits().getTotalHits(),
|
||||||
SpecialEvent.RESULTS_FIELD));
|
ScheduledEvent.RESULTS_FIELD));
|
||||||
},
|
},
|
||||||
handler::onFailure)
|
handler::onFailure)
|
||||||
, client::search);
|
, client::search);
|
||||||
|
|
|
@ -12,16 +12,16 @@ import org.elasticsearch.index.query.RangeQueryBuilder;
|
||||||
import org.elasticsearch.index.query.TermsQueryBuilder;
|
import org.elasticsearch.index.query.TermsQueryBuilder;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query builder for {@link SpecialEvent}s
|
* Query builder for {@link ScheduledEvent}s
|
||||||
* If <code>calendarIds</code> are not set then all calendars will match.
|
* If <code>calendarIds</code> are not set then all calendars will match.
|
||||||
*/
|
*/
|
||||||
public class SpecialEventsQueryBuilder {
|
public class ScheduledEventsQueryBuilder {
|
||||||
public static final int DEFAULT_SIZE = 1000;
|
public static final int DEFAULT_SIZE = 1000;
|
||||||
|
|
||||||
private int from = 0;
|
private int from = 0;
|
||||||
|
@ -31,27 +31,27 @@ public class SpecialEventsQueryBuilder {
|
||||||
private String after;
|
private String after;
|
||||||
private String before;
|
private String before;
|
||||||
|
|
||||||
public SpecialEventsQueryBuilder calendarIds(List<String> calendarIds) {
|
public ScheduledEventsQueryBuilder calendarIds(List<String> calendarIds) {
|
||||||
this.calendarIds = calendarIds;
|
this.calendarIds = calendarIds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEventsQueryBuilder after(String after) {
|
public ScheduledEventsQueryBuilder after(String after) {
|
||||||
this.after = after;
|
this.after = after;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEventsQueryBuilder before(String before) {
|
public ScheduledEventsQueryBuilder before(String before) {
|
||||||
this.before = before;
|
this.before = before;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEventsQueryBuilder from(int from) {
|
public ScheduledEventsQueryBuilder from(int from) {
|
||||||
this.from = from;
|
this.from = from;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecialEventsQueryBuilder size(int size) {
|
public ScheduledEventsQueryBuilder size(int size) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,12 @@ public class SpecialEventsQueryBuilder {
|
||||||
List<QueryBuilder> queries = new ArrayList<>();
|
List<QueryBuilder> queries = new ArrayList<>();
|
||||||
|
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
RangeQueryBuilder afterQuery = QueryBuilders.rangeQuery(SpecialEvent.END_TIME.getPreferredName());
|
RangeQueryBuilder afterQuery = QueryBuilders.rangeQuery(ScheduledEvent.END_TIME.getPreferredName());
|
||||||
afterQuery.gt(after);
|
afterQuery.gt(after);
|
||||||
queries.add(afterQuery);
|
queries.add(afterQuery);
|
||||||
}
|
}
|
||||||
if (before != null) {
|
if (before != null) {
|
||||||
RangeQueryBuilder beforeQuery = QueryBuilders.rangeQuery(SpecialEvent.START_TIME.getPreferredName());
|
RangeQueryBuilder beforeQuery = QueryBuilders.rangeQuery(ScheduledEvent.START_TIME.getPreferredName());
|
||||||
beforeQuery.lt(before);
|
beforeQuery.lt(before);
|
||||||
queries.add(beforeQuery);
|
queries.add(beforeQuery);
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,10 @@ public class SpecialEventsQueryBuilder {
|
||||||
queries.add(new TermsQueryBuilder(Calendar.ID.getPreferredName(), calendarIds));
|
queries.add(new TermsQueryBuilder(Calendar.ID.getPreferredName(), calendarIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder typeQuery = new TermsQueryBuilder(SpecialEvent.TYPE.getPreferredName(), SpecialEvent.SPECIAL_EVENT_TYPE);
|
QueryBuilder typeQuery = new TermsQueryBuilder(ScheduledEvent.TYPE.getPreferredName(), ScheduledEvent.SCHEDULED_EVENT_TYPE);
|
||||||
|
|
||||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
searchSourceBuilder.sort(SpecialEvent.START_TIME.getPreferredName());
|
searchSourceBuilder.sort(ScheduledEvent.START_TIME.getPreferredName());
|
||||||
searchSourceBuilder.from(from);
|
searchSourceBuilder.from(from);
|
||||||
searchSourceBuilder.size(size);
|
searchSourceBuilder.size(size);
|
||||||
|
|
|
@ -5,9 +5,8 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.ml.job.process.autodetect.params;
|
package org.elasticsearch.xpack.ml.job.process.autodetect.params;
|
||||||
|
|
||||||
import org.elasticsearch.Build;
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCounts;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCounts;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSizeStats;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelSizeStats;
|
||||||
|
@ -15,7 +14,6 @@ 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.process.autodetect.state.Quantiles;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -30,19 +28,19 @@ public class AutodetectParams {
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Quantiles quantiles;
|
private final Quantiles quantiles;
|
||||||
private final Set<MlFilter> filters;
|
private final Set<MlFilter> filters;
|
||||||
private final List<SpecialEvent> specialEvents;
|
private final List<ScheduledEvent> scheduledEvents;
|
||||||
|
|
||||||
|
|
||||||
private AutodetectParams(DataCounts dataCounts, ModelSizeStats modelSizeStats,
|
private AutodetectParams(DataCounts dataCounts, ModelSizeStats modelSizeStats,
|
||||||
@Nullable ModelSnapshot modelSnapshot,
|
@Nullable ModelSnapshot modelSnapshot,
|
||||||
@Nullable Quantiles quantiles, Set<MlFilter> filters,
|
@Nullable Quantiles quantiles, Set<MlFilter> filters,
|
||||||
List<SpecialEvent> specialEvents) {
|
List<ScheduledEvent> scheduledEvents) {
|
||||||
this.dataCounts = Objects.requireNonNull(dataCounts);
|
this.dataCounts = Objects.requireNonNull(dataCounts);
|
||||||
this.modelSizeStats = Objects.requireNonNull(modelSizeStats);
|
this.modelSizeStats = Objects.requireNonNull(modelSizeStats);
|
||||||
this.modelSnapshot = modelSnapshot;
|
this.modelSnapshot = modelSnapshot;
|
||||||
this.quantiles = quantiles;
|
this.quantiles = quantiles;
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
this.specialEvents = specialEvents;
|
this.scheduledEvents = scheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataCounts dataCounts() {
|
public DataCounts dataCounts() {
|
||||||
|
@ -67,8 +65,8 @@ public class AutodetectParams {
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SpecialEvent> specialEvents() {
|
public List<ScheduledEvent> scheduledEvents() {
|
||||||
return specialEvents;
|
return scheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,12 +86,12 @@ public class AutodetectParams {
|
||||||
&& Objects.equals(this.modelSnapshot, that.modelSnapshot)
|
&& Objects.equals(this.modelSnapshot, that.modelSnapshot)
|
||||||
&& Objects.equals(this.quantiles, that.quantiles)
|
&& Objects.equals(this.quantiles, that.quantiles)
|
||||||
&& Objects.equals(this.filters, that.filters)
|
&& Objects.equals(this.filters, that.filters)
|
||||||
&& Objects.equals(this.specialEvents, that.specialEvents);
|
&& Objects.equals(this.scheduledEvents, that.scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(dataCounts, modelSizeStats, modelSnapshot, quantiles, filters, specialEvents);
|
return Objects.hash(dataCounts, modelSizeStats, modelSnapshot, quantiles, filters, scheduledEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
@ -103,13 +101,13 @@ public class AutodetectParams {
|
||||||
private ModelSnapshot modelSnapshot;
|
private ModelSnapshot modelSnapshot;
|
||||||
private Quantiles quantiles;
|
private Quantiles quantiles;
|
||||||
private Set<MlFilter> filters;
|
private Set<MlFilter> filters;
|
||||||
private List<SpecialEvent> specialEvents;
|
private List<ScheduledEvent> scheduledEvents;
|
||||||
|
|
||||||
public Builder(String jobId) {
|
public Builder(String jobId) {
|
||||||
dataCounts = new DataCounts(jobId);
|
dataCounts = new DataCounts(jobId);
|
||||||
modelSizeStats = new ModelSizeStats.Builder(jobId).build();
|
modelSizeStats = new ModelSizeStats.Builder(jobId).build();
|
||||||
filters = new HashSet<>();
|
filters = new HashSet<>();
|
||||||
specialEvents = new ArrayList<>();
|
scheduledEvents = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setDataCounts(DataCounts dataCounts) {
|
public Builder setDataCounts(DataCounts dataCounts) {
|
||||||
|
@ -136,12 +134,8 @@ public class AutodetectParams {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addSpecialEvent(SpecialEvent specialEvent) {
|
public Builder setScheduledEvents(List<ScheduledEvent> scheduledEvents) {
|
||||||
specialEvents.add(specialEvent);
|
this.scheduledEvents = scheduledEvents;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public Builder setSpecialEvents(List<SpecialEvent> specialEvents) {
|
|
||||||
this.specialEvents = specialEvents;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +151,7 @@ public class AutodetectParams {
|
||||||
|
|
||||||
public AutodetectParams build() {
|
public AutodetectParams build() {
|
||||||
return new AutodetectParams(dataCounts, modelSizeStats, modelSnapshot, quantiles,
|
return new AutodetectParams(dataCounts, modelSizeStats, modelSnapshot, quantiles,
|
||||||
filters, specialEvents);
|
filters, scheduledEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.SpecialEventsQueryBuilder;
|
import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
|
||||||
ActionListener<GetCalendarEventsAction.Response> listener) {
|
ActionListener<GetCalendarEventsAction.Response> listener) {
|
||||||
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
|
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
|
||||||
r -> {
|
r -> {
|
||||||
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder()
|
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder()
|
||||||
.after(request.getAfter())
|
.after(request.getAfter())
|
||||||
.before(request.getBefore())
|
.before(request.getBefore())
|
||||||
.from(request.getPageParams().getFrom())
|
.from(request.getPageParams().getFrom())
|
||||||
|
@ -50,7 +50,7 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
|
||||||
query.calendarIds(Collections.singletonList(request.getCalendarId()));
|
query.calendarIds(Collections.singletonList(request.getCalendarId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionListener<QueryPage<SpecialEvent>> eventsListener = ActionListener.wrap(
|
ActionListener<QueryPage<ScheduledEvent>> eventsListener = ActionListener.wrap(
|
||||||
events -> {
|
events -> {
|
||||||
listener.onResponse(new GetCalendarEventsAction.Response(events));
|
listener.onResponse(new GetCalendarEventsAction.Response(events));
|
||||||
},
|
},
|
||||||
|
@ -58,9 +58,9 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
|
||||||
);
|
);
|
||||||
|
|
||||||
if (request.getJobId() != null) {
|
if (request.getJobId() != null) {
|
||||||
jobProvider.specialEventsForJob(request.getJobId(), query, eventsListener);
|
jobProvider.scheduledEventsForJob(request.getJobId(), query, eventsListener);
|
||||||
} else {
|
} else {
|
||||||
jobProvider.specialEvents(query, eventsListener);
|
jobProvider.scheduledEvents(query, eventsListener);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
listener::onFailure);
|
listener::onFailure);
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.xpack.ml.MlMetaIndex;
|
import org.elasticsearch.xpack.ml.MlMetaIndex;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
||||||
|
|
||||||
|
@ -54,20 +54,20 @@ public class TransportPostCalendarEventsAction extends HandledTransportAction<Po
|
||||||
@Override
|
@Override
|
||||||
protected void doExecute(PostCalendarEventsAction.Request request,
|
protected void doExecute(PostCalendarEventsAction.Request request,
|
||||||
ActionListener<PostCalendarEventsAction.Response> listener) {
|
ActionListener<PostCalendarEventsAction.Response> listener) {
|
||||||
List<SpecialEvent> events = request.getSpecialEvents();
|
List<ScheduledEvent> events = request.getScheduledEvents();
|
||||||
|
|
||||||
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
|
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
|
||||||
r -> {
|
r -> {
|
||||||
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
|
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
|
||||||
|
|
||||||
for (SpecialEvent event: events) {
|
for (ScheduledEvent event: events) {
|
||||||
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
|
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
|
||||||
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
|
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
|
||||||
indexRequest.source(event.toXContent(builder,
|
indexRequest.source(event.toXContent(builder,
|
||||||
new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY,
|
new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY,
|
||||||
"true"))));
|
"true"))));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException("Failed to serialise special event", e);
|
throw new IllegalStateException("Failed to serialise event", e);
|
||||||
}
|
}
|
||||||
bulkRequestBuilder.add(indexRequest);
|
bulkRequestBuilder.add(indexRequest);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class TransportPostCalendarEventsAction extends HandledTransportAction<Po
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Exception e) {
|
public void onFailure(Exception e) {
|
||||||
listener.onFailure(
|
listener.onFailure(
|
||||||
ExceptionsHelper.serverError("Error indexing special event", e));
|
ExceptionsHelper.serverError("Error indexing event", e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class TransportUpdateProcessAction extends TransportJobTaskAction<UpdateP
|
||||||
try {
|
try {
|
||||||
processManager.writeUpdateProcessMessage(task,
|
processManager.writeUpdateProcessMessage(task,
|
||||||
new UpdateParams(request.getModelPlotConfig(),
|
new UpdateParams(request.getModelPlotConfig(),
|
||||||
request.getDetectorUpdates(), request.isUpdateSpecialEvents()),
|
request.getDetectorUpdates(), request.isUpdateScheduledEvents()),
|
||||||
e -> {
|
e -> {
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
listener.onResponse(new UpdateProcessAction.Response());
|
listener.onResponse(new UpdateProcessAction.Response());
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class UpdateJobProcessNotifier extends AbstractComponent implements Local
|
||||||
|
|
||||||
void executeRemoteJob(JobUpdate update) {
|
void executeRemoteJob(JobUpdate update) {
|
||||||
Request request = new Request(update.getJobId(), update.getModelPlotConfig(), update.getDetectorUpdates(),
|
Request request = new Request(update.getJobId(), update.getModelPlotConfig(), update.getDetectorUpdates(),
|
||||||
update.isUpdateSpecialEvents());
|
update.isUpdateScheduledEvents());
|
||||||
|
|
||||||
executeAsyncWithOrigin(client, ML_ORIGIN, UpdateProcessAction.INSTANCE, request,
|
executeAsyncWithOrigin(client, ML_ORIGIN, UpdateProcessAction.INSTANCE, request,
|
||||||
new ActionListener<Response>() {
|
new ActionListener<Response>() {
|
||||||
|
|
|
@ -8,7 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.AnalysisLimits;
|
import org.elasticsearch.xpack.ml.job.config.AnalysisLimits;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
||||||
|
@ -46,7 +46,7 @@ public class AutodetectBuilder {
|
||||||
private List<Path> filesToDelete;
|
private List<Path> filesToDelete;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private Set<MlFilter> referencedFilters;
|
private Set<MlFilter> referencedFilters;
|
||||||
private List<SpecialEvent> specialEvents;
|
private List<ScheduledEvent> scheduledEvents;
|
||||||
private Quantiles quantiles;
|
private Quantiles quantiles;
|
||||||
private Environment env;
|
private Environment env;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
@ -71,7 +71,7 @@ public class AutodetectBuilder {
|
||||||
this.filesToDelete = Objects.requireNonNull(filesToDelete);
|
this.filesToDelete = Objects.requireNonNull(filesToDelete);
|
||||||
this.logger = Objects.requireNonNull(logger);
|
this.logger = Objects.requireNonNull(logger);
|
||||||
referencedFilters = new HashSet<>();
|
referencedFilters = new HashSet<>();
|
||||||
specialEvents = Collections.emptyList();
|
scheduledEvents = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutodetectBuilder referencedFilters(Set<MlFilter> filters) {
|
public AutodetectBuilder referencedFilters(Set<MlFilter> filters) {
|
||||||
|
@ -89,8 +89,8 @@ public class AutodetectBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutodetectBuilder specialEvents(List<SpecialEvent> specialEvents) {
|
public AutodetectBuilder scheduledEvents(List<ScheduledEvent> scheduledEvents) {
|
||||||
this.specialEvents = specialEvents;
|
this.scheduledEvents = scheduledEvents;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ public class AutodetectBuilder {
|
||||||
try (OutputStreamWriter osw = new OutputStreamWriter(
|
try (OutputStreamWriter osw = new OutputStreamWriter(
|
||||||
Files.newOutputStream(fieldConfigFile),
|
Files.newOutputStream(fieldConfigFile),
|
||||||
StandardCharsets.UTF_8)) {
|
StandardCharsets.UTF_8)) {
|
||||||
new FieldConfigWriter(job.getAnalysisConfig(), referencedFilters, specialEvents, osw, logger).write();
|
new FieldConfigWriter(job.getAnalysisConfig(), referencedFilters, scheduledEvents, osw, logger).write();
|
||||||
}
|
}
|
||||||
|
|
||||||
String fieldConfig = FIELD_CONFIG_ARG + fieldConfigFile.toString();
|
String fieldConfig = FIELD_CONFIG_ARG + fieldConfigFile.toString();
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
|
@ -189,7 +189,7 @@ public class AutodetectCommunicator implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeUpdateProcessMessage(UpdateParams updateParams, List<SpecialEvent> specialEvents,
|
public void writeUpdateProcessMessage(UpdateParams updateParams, List<ScheduledEvent> scheduledEvents,
|
||||||
BiConsumer<Void, Exception> handler) {
|
BiConsumer<Void, Exception> handler) {
|
||||||
submitOperation(() -> {
|
submitOperation(() -> {
|
||||||
if (updateParams.getModelPlotConfig() != null) {
|
if (updateParams.getModelPlotConfig() != null) {
|
||||||
|
@ -197,15 +197,15 @@ public class AutodetectCommunicator implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DetectionRule> eventsAsRules = Collections.emptyList();
|
List<DetectionRule> eventsAsRules = Collections.emptyList();
|
||||||
if (specialEvents.isEmpty() == false) {
|
if (scheduledEvents.isEmpty() == false) {
|
||||||
eventsAsRules = specialEvents.stream()
|
eventsAsRules = scheduledEvents.stream()
|
||||||
.map(e -> e.toDetectionRule(job.getAnalysisConfig().getBucketSpan()))
|
.map(e -> e.toDetectionRule(job.getAnalysisConfig().getBucketSpan()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// All detection rules for a detector must be updated together as the update
|
// All detection rules for a detector must be updated together as the update
|
||||||
// wipes any previously set rules.
|
// wipes any previously set rules.
|
||||||
// Build a single list of rules for special events and detection rules.
|
// Build a single list of rules for events and detection rules.
|
||||||
List<List<DetectionRule>> rules = new ArrayList<>(job.getAnalysisConfig().getDetectors().size());
|
List<List<DetectionRule>> rules = new ArrayList<>(job.getAnalysisConfig().getDetectors().size());
|
||||||
for (int i = 0; i < job.getAnalysisConfig().getDetectors().size(); i++) {
|
for (int i = 0; i < job.getAnalysisConfig().getDetectors().size(); i++) {
|
||||||
List<DetectionRule> detectorRules = new ArrayList<>(eventsAsRules);
|
List<DetectionRule> detectorRules = new ArrayList<>(eventsAsRules);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.xpack.ml.MachineLearning;
|
import org.elasticsearch.xpack.ml.MachineLearning;
|
||||||
import org.elasticsearch.xpack.ml.action.TransportOpenJobAction.JobTask;
|
import org.elasticsearch.xpack.ml.action.TransportOpenJobAction.JobTask;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.JobManager;
|
import org.elasticsearch.xpack.ml.job.JobManager;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.config.JobState;
|
import org.elasticsearch.xpack.ml.job.config.JobState;
|
||||||
|
@ -34,7 +34,7 @@ import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobRenormalizedResultsPersister;
|
import org.elasticsearch.xpack.ml.job.persistence.JobRenormalizedResultsPersister;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
|
import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.SpecialEventsQueryBuilder;
|
import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.StateStreamer;
|
import org.elasticsearch.xpack.ml.job.persistence.StateStreamer;
|
||||||
import org.elasticsearch.xpack.ml.job.process.DataCountsReporter;
|
import org.elasticsearch.xpack.ml.job.process.DataCountsReporter;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutoDetectResultProcessor;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutoDetectResultProcessor;
|
||||||
|
@ -261,9 +261,9 @@ public class AutodetectProcessManager extends AbstractComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionListener<QueryPage<SpecialEvent>> eventsListener = ActionListener.wrap(
|
ActionListener<QueryPage<ScheduledEvent>> eventsListener = ActionListener.wrap(
|
||||||
specialEvents -> {
|
events -> {
|
||||||
communicator.writeUpdateProcessMessage(updateParams, specialEvents.results(), (aVoid, e) -> {
|
communicator.writeUpdateProcessMessage(updateParams, events.results(), (aVoid, e) -> {
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
handler.accept(null);
|
handler.accept(null);
|
||||||
} else {
|
} else {
|
||||||
|
@ -273,11 +273,11 @@ public class AutodetectProcessManager extends AbstractComponent {
|
||||||
},
|
},
|
||||||
handler::accept);
|
handler::accept);
|
||||||
|
|
||||||
if (updateParams.isUpdateSpecialEvents()) {
|
if (updateParams.isUpdateScheduledEvents()) {
|
||||||
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder().after(Long.toString(new Date().getTime()));
|
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder().after(Long.toString(new Date().getTime()));
|
||||||
jobProvider.specialEventsForJob(jobTask.getJobId(), query, eventsListener);
|
jobProvider.scheduledEventsForJob(jobTask.getJobId(), query, eventsListener);
|
||||||
} else {
|
} else {
|
||||||
eventsListener.onResponse(new QueryPage<SpecialEvent>(Collections.emptyList(), 0, SpecialEvent.RESULTS_FIELD));
|
eventsListener.onResponse(new QueryPage<ScheduledEvent>(Collections.emptyList(), 0, ScheduledEvent.RESULTS_FIELD));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,12 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
|
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Job;
|
import org.elasticsearch.xpack.ml.job.config.Job;
|
||||||
import org.elasticsearch.xpack.ml.job.config.MlFilter;
|
|
||||||
import org.elasticsearch.xpack.ml.job.process.NativeController;
|
import org.elasticsearch.xpack.ml.job.process.NativeController;
|
||||||
import org.elasticsearch.xpack.ml.job.process.ProcessCtrl;
|
import org.elasticsearch.xpack.ml.job.process.ProcessCtrl;
|
||||||
import org.elasticsearch.xpack.ml.job.process.ProcessPipes;
|
import org.elasticsearch.xpack.ml.job.process.ProcessPipes;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutodetectResultsParser;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutodetectResultsParser;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.output.StateProcessor;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.output.StateProcessor;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams;
|
||||||
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.utils.ExceptionsHelper;
|
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
|
||||||
import org.elasticsearch.xpack.ml.utils.NamedPipeHelper;
|
import org.elasticsearch.xpack.ml.utils.NamedPipeHelper;
|
||||||
|
|
||||||
|
@ -31,7 +28,6 @@ import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -89,7 +85,7 @@ public class NativeAutodetectProcessFactory implements AutodetectProcessFactory
|
||||||
AutodetectBuilder autodetectBuilder = new AutodetectBuilder(job, filesToDelete, LOGGER, env,
|
AutodetectBuilder autodetectBuilder = new AutodetectBuilder(job, filesToDelete, LOGGER, env,
|
||||||
settings, nativeController, processPipes)
|
settings, nativeController, processPipes)
|
||||||
.referencedFilters(autodetectParams.filters())
|
.referencedFilters(autodetectParams.filters())
|
||||||
.specialEvents(autodetectParams.specialEvents());
|
.scheduledEvents(autodetectParams.scheduledEvents());
|
||||||
|
|
||||||
// if state is null or empty it will be ignored
|
// if state is null or empty it will be ignored
|
||||||
// else it is used to restore the quantiles
|
// else it is used to restore the quantiles
|
||||||
|
|
|
@ -15,14 +15,14 @@ public final class UpdateParams {
|
||||||
|
|
||||||
private final ModelPlotConfig modelPlotConfig;
|
private final ModelPlotConfig modelPlotConfig;
|
||||||
private final List<JobUpdate.DetectorUpdate> detectorUpdates;
|
private final List<JobUpdate.DetectorUpdate> detectorUpdates;
|
||||||
private final boolean updateSpecialEvents;
|
private final boolean updateScheduledEvents;
|
||||||
|
|
||||||
public UpdateParams(@Nullable ModelPlotConfig modelPlotConfig,
|
public UpdateParams(@Nullable ModelPlotConfig modelPlotConfig,
|
||||||
@Nullable List<JobUpdate.DetectorUpdate> detectorUpdates,
|
@Nullable List<JobUpdate.DetectorUpdate> detectorUpdates,
|
||||||
boolean updateSpecialEvents) {
|
boolean updateScheduledEvents) {
|
||||||
this.modelPlotConfig = modelPlotConfig;
|
this.modelPlotConfig = modelPlotConfig;
|
||||||
this.detectorUpdates = detectorUpdates;
|
this.detectorUpdates = detectorUpdates;
|
||||||
this.updateSpecialEvents = updateSpecialEvents;
|
this.updateScheduledEvents = updateScheduledEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModelPlotConfig getModelPlotConfig() {
|
public ModelPlotConfig getModelPlotConfig() {
|
||||||
|
@ -33,7 +33,7 @@ public final class UpdateParams {
|
||||||
return detectorUpdates;
|
return detectorUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateSpecialEvents() {
|
public boolean isUpdateScheduledEvents() {
|
||||||
return updateSpecialEvents;
|
return updateScheduledEvents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
|
||||||
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
||||||
import org.elasticsearch.xpack.ml.job.config.ModelPlotConfig;
|
import org.elasticsearch.xpack.ml.job.config.ModelPlotConfig;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DefaultDetectorDescription;
|
import org.elasticsearch.xpack.ml.job.config.DefaultDetectorDescription;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
||||||
|
@ -36,7 +36,6 @@ public class FieldConfigWriter {
|
||||||
private static final String CATEGORIZATION_FIELD_OPTION = " categorizationfield=";
|
private static final String CATEGORIZATION_FIELD_OPTION = " categorizationfield=";
|
||||||
private static final String CATEGORIZATION_FILTER_PREFIX = "categorizationfilter.";
|
private static final String CATEGORIZATION_FILTER_PREFIX = "categorizationfilter.";
|
||||||
private static final String FILTER_PREFIX = "filter.";
|
private static final String FILTER_PREFIX = "filter.";
|
||||||
private static final String SPECIAL_EVENT_PREFIX = "specialevent.";
|
|
||||||
|
|
||||||
// Note: for the Engine API summarycountfield is currently passed as a
|
// Note: for the Engine API summarycountfield is currently passed as a
|
||||||
// command line option to autodetect rather than in the field config file
|
// command line option to autodetect rather than in the field config file
|
||||||
|
@ -45,15 +44,15 @@ public class FieldConfigWriter {
|
||||||
|
|
||||||
private final AnalysisConfig config;
|
private final AnalysisConfig config;
|
||||||
private final Set<MlFilter> filters;
|
private final Set<MlFilter> filters;
|
||||||
private final List<SpecialEvent> specialEvents;
|
private final List<ScheduledEvent> scheduledEvents;
|
||||||
private final OutputStreamWriter writer;
|
private final OutputStreamWriter writer;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public FieldConfigWriter(AnalysisConfig config, Set<MlFilter> filters, List<SpecialEvent> specialEvents,
|
public FieldConfigWriter(AnalysisConfig config, Set<MlFilter> filters, List<ScheduledEvent> scheduledEvents,
|
||||||
OutputStreamWriter writer, Logger logger) {
|
OutputStreamWriter writer, Logger logger) {
|
||||||
this.config = Objects.requireNonNull(config);
|
this.config = Objects.requireNonNull(config);
|
||||||
this.filters = Objects.requireNonNull(filters);
|
this.filters = Objects.requireNonNull(filters);
|
||||||
this.specialEvents = Objects.requireNonNull(specialEvents);
|
this.scheduledEvents = Objects.requireNonNull(scheduledEvents);
|
||||||
this.writer = Objects.requireNonNull(writer);
|
this.writer = Objects.requireNonNull(writer);
|
||||||
this.logger = Objects.requireNonNull(logger);
|
this.logger = Objects.requireNonNull(logger);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +78,7 @@ public class FieldConfigWriter {
|
||||||
|
|
||||||
private void writeDetectors(StringBuilder contents) throws IOException {
|
private void writeDetectors(StringBuilder contents) throws IOException {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
List<DetectionRule> events = specialEvents.stream().map(e -> e.toDetectionRule(config.getBucketSpan()))
|
List<DetectionRule> events = scheduledEvents.stream().map(e -> e.toDetectionRule(config.getBucketSpan()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (Detector detector : config.getDetectors()) {
|
for (Detector detector : config.getDetectors()) {
|
||||||
|
@ -103,14 +102,14 @@ public class FieldConfigWriter {
|
||||||
contents.append(NEW_LINE);
|
contents.append(NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDetectorRules(int detectorId, Detector detector, List<DetectionRule> specialEvents,
|
private void writeDetectorRules(int detectorId, Detector detector, List<DetectionRule> scheduledEvents,
|
||||||
StringBuilder contents) throws IOException {
|
StringBuilder contents) throws IOException {
|
||||||
|
|
||||||
List<DetectionRule> rules = new ArrayList<>();
|
List<DetectionRule> rules = new ArrayList<>();
|
||||||
if (detector.getRules() != null) {
|
if (detector.getRules() != null) {
|
||||||
rules.addAll(detector.getRules());
|
rules.addAll(detector.getRules());
|
||||||
}
|
}
|
||||||
rules.addAll(specialEvents);
|
rules.addAll(scheduledEvents);
|
||||||
|
|
||||||
if (rules.isEmpty()) {
|
if (rules.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -10,8 +10,8 @@ import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEventTests;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEventTests;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -28,9 +28,9 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
|
||||||
|
|
||||||
private PostCalendarEventsAction.Request createTestInstance(String calendarId) {
|
private PostCalendarEventsAction.Request createTestInstance(String calendarId) {
|
||||||
int numEvents = randomIntBetween(1, 10);
|
int numEvents = randomIntBetween(1, 10);
|
||||||
List<SpecialEvent> events = new ArrayList<>();
|
List<ScheduledEvent> events = new ArrayList<>();
|
||||||
for (int i=0; i<numEvents; i++) {
|
for (int i=0; i<numEvents; i++) {
|
||||||
events.add(SpecialEventTests.createSpecialEvent(calendarId));
|
events.add(ScheduledEventTests.createScheduledEvent(calendarId));
|
||||||
}
|
}
|
||||||
|
|
||||||
PostCalendarEventsAction.Request request = new PostCalendarEventsAction.Request(calendarId, events);
|
PostCalendarEventsAction.Request request = new PostCalendarEventsAction.Request(calendarId, events);
|
||||||
|
@ -47,7 +47,7 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
|
||||||
PostCalendarEventsAction.Request sourceRequest = createTestInstance();
|
PostCalendarEventsAction.Request sourceRequest = createTestInstance();
|
||||||
|
|
||||||
StringBuilder requestString = new StringBuilder();
|
StringBuilder requestString = new StringBuilder();
|
||||||
for (SpecialEvent event: sourceRequest.getSpecialEvents()) {
|
for (ScheduledEvent event: sourceRequest.getScheduledEvents()) {
|
||||||
requestString.append(Strings.toString(event)).append("\r\n");
|
requestString.append(Strings.toString(event)).append("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +60,11 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
|
||||||
|
|
||||||
public void testParseRequest_throwsIfCalendarIdsAreDifferent() throws IOException {
|
public void testParseRequest_throwsIfCalendarIdsAreDifferent() throws IOException {
|
||||||
PostCalendarEventsAction.Request sourceRequest = createTestInstance("foo");
|
PostCalendarEventsAction.Request sourceRequest = createTestInstance("foo");
|
||||||
PostCalendarEventsAction.Request request = new PostCalendarEventsAction.Request("bar", sourceRequest.getSpecialEvents());
|
PostCalendarEventsAction.Request request = new PostCalendarEventsAction.Request("bar", sourceRequest.getScheduledEvents());
|
||||||
|
|
||||||
|
|
||||||
StringBuilder requestString = new StringBuilder();
|
StringBuilder requestString = new StringBuilder();
|
||||||
for (SpecialEvent event: sourceRequest.getSpecialEvents()) {
|
for (ScheduledEvent event: sourceRequest.getScheduledEvents()) {
|
||||||
requestString.append(Strings.toString(event)).append("\r\n");
|
requestString.append(Strings.toString(event)).append("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,10 @@
|
||||||
package org.elasticsearch.xpack.ml.action;
|
package org.elasticsearch.xpack.ml.action;
|
||||||
|
|
||||||
import org.elasticsearch.test.AbstractStreamableTestCase;
|
import org.elasticsearch.test.AbstractStreamableTestCase;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
|
||||||
import org.elasticsearch.xpack.ml.job.config.JobUpdate;
|
import org.elasticsearch.xpack.ml.job.config.JobUpdate;
|
||||||
import org.elasticsearch.xpack.ml.job.config.ModelPlotConfig;
|
import org.elasticsearch.xpack.ml.job.config.ModelPlotConfig;
|
||||||
import org.joda.time.DateTime;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UpdateProcessActionRequestTests extends AbstractStreamableTestCase<UpdateProcessAction.Request> {
|
public class UpdateProcessActionRequestTests extends AbstractStreamableTestCase<UpdateProcessAction.Request> {
|
||||||
|
|
|
@ -27,32 +27,32 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
|
||||||
public class SpecialEventTests extends AbstractSerializingTestCase<SpecialEvent> {
|
public class ScheduledEventTests extends AbstractSerializingTestCase<ScheduledEvent> {
|
||||||
|
|
||||||
public static SpecialEvent createSpecialEvent(String calendarId) {
|
public static ScheduledEvent createScheduledEvent(String calendarId) {
|
||||||
ZonedDateTime start = ZonedDateTime.ofInstant(Instant.ofEpochMilli(new DateTime(randomDateTimeZone()).getMillis()), ZoneOffset.UTC);
|
ZonedDateTime start = ZonedDateTime.ofInstant(Instant.ofEpochMilli(new DateTime(randomDateTimeZone()).getMillis()), ZoneOffset.UTC);
|
||||||
return new SpecialEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
|
return new ScheduledEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
|
||||||
calendarId);
|
calendarId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpecialEvent createTestInstance() {
|
protected ScheduledEvent createTestInstance() {
|
||||||
return createSpecialEvent(randomAlphaOfLengthBetween(1, 20));
|
return createScheduledEvent(randomAlphaOfLengthBetween(1, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Writeable.Reader<SpecialEvent> instanceReader() {
|
protected Writeable.Reader<ScheduledEvent> instanceReader() {
|
||||||
return SpecialEvent::new;
|
return ScheduledEvent::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpecialEvent doParseInstance(XContentParser parser) throws IOException {
|
protected ScheduledEvent doParseInstance(XContentParser parser) throws IOException {
|
||||||
return SpecialEvent.PARSER.apply(parser, null).build();
|
return ScheduledEvent.PARSER.apply(parser, null).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToDetectionRule() {
|
public void testToDetectionRule() {
|
||||||
long bucketSpanSecs = 300;
|
long bucketSpanSecs = 300;
|
||||||
SpecialEvent event = createTestInstance();
|
ScheduledEvent event = createTestInstance();
|
||||||
DetectionRule rule = event.toDetectionRule(TimeValue.timeValueSeconds(bucketSpanSecs));
|
DetectionRule rule = event.toDetectionRule(TimeValue.timeValueSeconds(bucketSpanSecs));
|
||||||
|
|
||||||
assertEquals(Connective.AND, rule.getConditionsConnective());
|
assertEquals(Connective.AND, rule.getConditionsConnective());
|
||||||
|
@ -82,7 +82,7 @@ public class SpecialEventTests extends AbstractSerializingTestCase<SpecialEvent>
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBuild() {
|
public void testBuild() {
|
||||||
SpecialEvent.Builder builder = new SpecialEvent.Builder();
|
ScheduledEvent.Builder builder = new ScheduledEvent.Builder();
|
||||||
|
|
||||||
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, builder::build);
|
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, builder::build);
|
||||||
assertEquals("Field [description] cannot be null", e.getMessage());
|
assertEquals("Field [description] cannot be null", e.getMessage());
|
||||||
|
@ -100,7 +100,7 @@ public class SpecialEventTests extends AbstractSerializingTestCase<SpecialEvent>
|
||||||
builder.build();
|
builder.build();
|
||||||
|
|
||||||
|
|
||||||
builder = new SpecialEvent.Builder().description("f").calendarId("c");
|
builder = new ScheduledEvent.Builder().description("f").calendarId("c");
|
||||||
builder.startTime(now);
|
builder.startTime(now);
|
||||||
builder.endTime(now.minusHours(2));
|
builder.endTime(now.minusHours(2));
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.xpack.ml.MlMetaIndex;
|
||||||
import org.elasticsearch.xpack.ml.action.PutJobAction;
|
import org.elasticsearch.xpack.ml.action.PutJobAction;
|
||||||
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
import org.elasticsearch.xpack.ml.action.util.QueryPage;
|
||||||
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
import org.elasticsearch.xpack.ml.calendars.Calendar;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Connective;
|
import org.elasticsearch.xpack.ml.job.config.Connective;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
||||||
|
@ -42,7 +42,7 @@ import org.elasticsearch.xpack.ml.job.persistence.CalendarQueryBuilder;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister;
|
import org.elasticsearch.xpack.ml.job.persistence.JobDataCountsPersister;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
|
import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister;
|
||||||
import org.elasticsearch.xpack.ml.job.persistence.SpecialEventsQueryBuilder;
|
import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.params.AutodetectParams;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCounts;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCounts;
|
||||||
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests;
|
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests;
|
||||||
|
@ -282,7 +282,7 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
return calendarHolder.get();
|
return calendarHolder.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSpecialEvents() throws Exception {
|
public void testScheduledEvents() throws Exception {
|
||||||
Job.Builder jobA = createJob("job_a");
|
Job.Builder jobA = createJob("job_a");
|
||||||
Job.Builder jobB = createJob("job_b");
|
Job.Builder jobB = createJob("job_b");
|
||||||
Job.Builder jobC = createJob("job_c");
|
Job.Builder jobC = createJob("job_c");
|
||||||
|
@ -292,32 +292,32 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
calendars.add(new Calendar(calendarAId, Collections.singletonList("job_a")));
|
calendars.add(new Calendar(calendarAId, Collections.singletonList("job_a")));
|
||||||
|
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
List<SpecialEvent> events = new ArrayList<>();
|
List<ScheduledEvent> events = new ArrayList<>();
|
||||||
events.add(buildSpecialEvent("downtime", now.plusDays(1), now.plusDays(2), calendarAId));
|
events.add(buildScheduledEvent("downtime", now.plusDays(1), now.plusDays(2), calendarAId));
|
||||||
events.add(buildSpecialEvent("downtime_AA", now.plusDays(8), now.plusDays(9), calendarAId));
|
events.add(buildScheduledEvent("downtime_AA", now.plusDays(8), now.plusDays(9), calendarAId));
|
||||||
events.add(buildSpecialEvent("downtime_AAA", now.plusDays(15), now.plusDays(16), calendarAId));
|
events.add(buildScheduledEvent("downtime_AAA", now.plusDays(15), now.plusDays(16), calendarAId));
|
||||||
|
|
||||||
String calendarABId = "maintenance_a_and_b";
|
String calendarABId = "maintenance_a_and_b";
|
||||||
calendars.add(new Calendar(calendarABId, Arrays.asList("job_a", "job_b")));
|
calendars.add(new Calendar(calendarABId, Arrays.asList("job_a", "job_b")));
|
||||||
|
|
||||||
events.add(buildSpecialEvent("downtime_AB", now.plusDays(12), now.plusDays(13), calendarABId));
|
events.add(buildScheduledEvent("downtime_AB", now.plusDays(12), now.plusDays(13), calendarABId));
|
||||||
|
|
||||||
indexCalendars(calendars);
|
indexCalendars(calendars);
|
||||||
indexSpecialEvents(events);
|
indexScheduledEvents(events);
|
||||||
|
|
||||||
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder();
|
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder();
|
||||||
List<SpecialEvent> returnedEvents = getSpecialEventsForJob(jobA.getId(), query);
|
List<ScheduledEvent> returnedEvents = getScheduledEventsForJob(jobA.getId(), query);
|
||||||
assertEquals(4, returnedEvents.size());
|
assertEquals(4, returnedEvents.size());
|
||||||
assertEquals(events.get(0), returnedEvents.get(0));
|
assertEquals(events.get(0), returnedEvents.get(0));
|
||||||
assertEquals(events.get(1), returnedEvents.get(1));
|
assertEquals(events.get(1), returnedEvents.get(1));
|
||||||
assertEquals(events.get(3), returnedEvents.get(2));
|
assertEquals(events.get(3), returnedEvents.get(2));
|
||||||
assertEquals(events.get(2), returnedEvents.get(3));
|
assertEquals(events.get(2), returnedEvents.get(3));
|
||||||
|
|
||||||
returnedEvents = getSpecialEventsForJob(jobB.getId(), query);
|
returnedEvents = getScheduledEventsForJob(jobB.getId(), query);
|
||||||
assertEquals(1, returnedEvents.size());
|
assertEquals(1, returnedEvents.size());
|
||||||
assertEquals(events.get(3), returnedEvents.get(0));
|
assertEquals(events.get(3), returnedEvents.get(0));
|
||||||
|
|
||||||
returnedEvents = getSpecialEventsForJob(jobC.getId(), query);
|
returnedEvents = getScheduledEventsForJob(jobC.getId(), query);
|
||||||
assertEquals(0, returnedEvents.size());
|
assertEquals(0, returnedEvents.size());
|
||||||
|
|
||||||
// Test time filters
|
// Test time filters
|
||||||
|
@ -325,14 +325,14 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
query.after(Long.toString(now.plusDays(8).plusHours(1).toInstant().toEpochMilli()));
|
query.after(Long.toString(now.plusDays(8).plusHours(1).toInstant().toEpochMilli()));
|
||||||
// Lands halfway through the 3rd event which should be returned
|
// Lands halfway through the 3rd event which should be returned
|
||||||
query.before(Long.toString(now.plusDays(12).plusHours(1).toInstant().toEpochMilli()));
|
query.before(Long.toString(now.plusDays(12).plusHours(1).toInstant().toEpochMilli()));
|
||||||
returnedEvents = getSpecialEventsForJob(jobA.getId(), query);
|
returnedEvents = getScheduledEventsForJob(jobA.getId(), query);
|
||||||
assertEquals(2, returnedEvents.size());
|
assertEquals(2, returnedEvents.size());
|
||||||
assertEquals(events.get(1), returnedEvents.get(0));
|
assertEquals(events.get(1), returnedEvents.get(0));
|
||||||
assertEquals(events.get(3), returnedEvents.get(1));
|
assertEquals(events.get(3), returnedEvents.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpecialEvent buildSpecialEvent(String description, ZonedDateTime start, ZonedDateTime end, String calendarId) {
|
private ScheduledEvent buildScheduledEvent(String description, ZonedDateTime start, ZonedDateTime end, String calendarId) {
|
||||||
return new SpecialEvent.Builder().description(description).startTime(start).endTime(end).calendarId(calendarId).build();
|
return new ScheduledEvent.Builder().description(description).startTime(start).endTime(end).calendarId(calendarId).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAutodetectParams() throws Exception {
|
public void testGetAutodetectParams() throws Exception {
|
||||||
|
@ -345,12 +345,12 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
|
|
||||||
// index the param docs
|
// index the param docs
|
||||||
ZonedDateTime now = ZonedDateTime.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
List<SpecialEvent> events = new ArrayList<>();
|
List<ScheduledEvent> events = new ArrayList<>();
|
||||||
// events in the past should be filtered out
|
// events in the past should be filtered out
|
||||||
events.add(buildSpecialEvent("In the past", now.minusDays(7), now.minusDays(6), calendarId));
|
events.add(buildScheduledEvent("In the past", now.minusDays(7), now.minusDays(6), calendarId));
|
||||||
events.add(buildSpecialEvent("A_downtime", now.plusDays(1), now.plusDays(2), calendarId));
|
events.add(buildScheduledEvent("A_downtime", now.plusDays(1), now.plusDays(2), calendarId));
|
||||||
events.add(buildSpecialEvent("A_downtime2", now.plusDays(8), now.plusDays(9), calendarId));
|
events.add(buildScheduledEvent("A_downtime2", now.plusDays(8), now.plusDays(9), calendarId));
|
||||||
indexSpecialEvents(events);
|
indexScheduledEvents(events);
|
||||||
|
|
||||||
List<MlFilter> filters = new ArrayList<>();
|
List<MlFilter> filters = new ArrayList<>();
|
||||||
filters.add(new MlFilter("fruit", Arrays.asList("apple", "pear")));
|
filters.add(new MlFilter("fruit", Arrays.asList("apple", "pear")));
|
||||||
|
@ -382,12 +382,12 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
|
|
||||||
AutodetectParams params = getAutodetectParams(job.build(new Date()));
|
AutodetectParams params = getAutodetectParams(job.build(new Date()));
|
||||||
|
|
||||||
// special events
|
// events
|
||||||
assertNotNull(params.specialEvents());
|
assertNotNull(params.scheduledEvents());
|
||||||
assertEquals(3, params.specialEvents().size());
|
assertEquals(3, params.scheduledEvents().size());
|
||||||
assertEquals(events.get(0), params.specialEvents().get(0));
|
assertEquals(events.get(0), params.scheduledEvents().get(0));
|
||||||
assertEquals(events.get(1), params.specialEvents().get(1));
|
assertEquals(events.get(1), params.scheduledEvents().get(1));
|
||||||
assertEquals(events.get(2), params.specialEvents().get(2));
|
assertEquals(events.get(2), params.scheduledEvents().get(2));
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
assertNotNull(params.filters());
|
assertNotNull(params.filters());
|
||||||
|
@ -432,11 +432,11 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
return searchResultHolder.get();
|
return searchResultHolder.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SpecialEvent> getSpecialEventsForJob(String jobId, SpecialEventsQueryBuilder query) throws Exception {
|
private List<ScheduledEvent> getScheduledEventsForJob(String jobId, ScheduledEventsQueryBuilder query) throws Exception {
|
||||||
AtomicReference<Exception> errorHolder = new AtomicReference<>();
|
AtomicReference<Exception> errorHolder = new AtomicReference<>();
|
||||||
AtomicReference<QueryPage<SpecialEvent>> searchResultHolder = new AtomicReference<>();
|
AtomicReference<QueryPage<ScheduledEvent>> searchResultHolder = new AtomicReference<>();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
jobProvider.specialEventsForJob(jobId, query, ActionListener.wrap(
|
jobProvider.scheduledEventsForJob(jobId, query, ActionListener.wrap(
|
||||||
params -> {
|
params -> {
|
||||||
searchResultHolder.set(params);
|
searchResultHolder.set(params);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
@ -491,11 +491,11 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
||||||
return new AnalysisConfig.Builder(Collections.singletonList(detector.build()));
|
return new AnalysisConfig.Builder(Collections.singletonList(detector.build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexSpecialEvents(List<SpecialEvent> events) throws IOException {
|
private void indexScheduledEvents(List<ScheduledEvent> events) throws IOException {
|
||||||
BulkRequestBuilder bulkRequest = client().prepareBulk();
|
BulkRequestBuilder bulkRequest = client().prepareBulk();
|
||||||
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||||
|
|
||||||
for (SpecialEvent event : events) {
|
for (ScheduledEvent event : events) {
|
||||||
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
|
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
|
||||||
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
|
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
|
||||||
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY, "true"));
|
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY, "true"));
|
||||||
|
|
|
@ -10,8 +10,8 @@ import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEventTests;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEventTests;
|
||||||
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
import org.elasticsearch.xpack.ml.job.config.DataDescription;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
||||||
|
@ -91,11 +91,11 @@ public class AutodetectCommunicatorTests extends ESTestCase {
|
||||||
Collections.singletonList(new DetectionRule.Builder(conditions).build())));
|
Collections.singletonList(new DetectionRule.Builder(conditions).build())));
|
||||||
|
|
||||||
UpdateParams updateParams = new UpdateParams(null, detectorUpdates, true);
|
UpdateParams updateParams = new UpdateParams(null, detectorUpdates, true);
|
||||||
List<SpecialEvent> events = Collections.singletonList(SpecialEventTests.createSpecialEvent(randomAlphaOfLength(10)));
|
List<ScheduledEvent> events = Collections.singletonList(ScheduledEventTests.createScheduledEvent(randomAlphaOfLength(10)));
|
||||||
|
|
||||||
communicator.writeUpdateProcessMessage(updateParams, events, ((aVoid, e) -> {}));
|
communicator.writeUpdateProcessMessage(updateParams, events, ((aVoid, e) -> {}));
|
||||||
|
|
||||||
// There are 2 detectors both will be updated with the rule for the special event.
|
// There are 2 detectors both will be updated with the rule for the scheduled event.
|
||||||
// The first has an additional update rule
|
// The first has an additional update rule
|
||||||
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
|
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
|
||||||
InOrder inOrder = Mockito.inOrder(process);
|
InOrder inOrder = Mockito.inOrder(process);
|
||||||
|
@ -107,7 +107,7 @@ public class AutodetectCommunicatorTests extends ESTestCase {
|
||||||
verifyNoMoreInteractions(process);
|
verifyNoMoreInteractions(process);
|
||||||
|
|
||||||
|
|
||||||
// This time there is a single detector update and no special events
|
// This time there is a single detector update and no scheduled events
|
||||||
detectorUpdates = Collections.singletonList(
|
detectorUpdates = Collections.singletonList(
|
||||||
new JobUpdate.DetectorUpdate(1, "updated description",
|
new JobUpdate.DetectorUpdate(1, "updated description",
|
||||||
Collections.singletonList(new DetectionRule.Builder(conditions).build())));
|
Collections.singletonList(new DetectionRule.Builder(conditions).build())));
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
|
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
|
||||||
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
|
||||||
import org.elasticsearch.xpack.ml.job.config.Condition;
|
import org.elasticsearch.xpack.ml.job.config.Condition;
|
||||||
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
|
||||||
|
@ -47,14 +47,14 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
public class FieldConfigWriterTests extends ESTestCase {
|
public class FieldConfigWriterTests extends ESTestCase {
|
||||||
private AnalysisConfig analysisConfig;
|
private AnalysisConfig analysisConfig;
|
||||||
private Set<MlFilter> filters;
|
private Set<MlFilter> filters;
|
||||||
private List<SpecialEvent> specialEvents;
|
private List<ScheduledEvent> scheduledEvents;
|
||||||
private OutputStreamWriter writer;
|
private OutputStreamWriter writer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpDeps() {
|
public void setUpDeps() {
|
||||||
analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(new Detector.Builder("count", null).build())).build();
|
analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(new Detector.Builder("count", null).build())).build();
|
||||||
filters = new LinkedHashSet<>();
|
filters = new LinkedHashSet<>();
|
||||||
specialEvents = new ArrayList<>();
|
scheduledEvents = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleDetectorsToConfFile()
|
public void testMultipleDetectorsToConfFile()
|
||||||
|
@ -232,17 +232,17 @@ public class FieldConfigWriterTests extends ESTestCase {
|
||||||
verifyNoMoreInteractions(writer);
|
verifyNoMoreInteractions(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWrite_GivenSpecialEvents() throws IOException {
|
public void testWrite_GivenScheduledEvents() throws IOException {
|
||||||
Detector d = new Detector.Builder("count", null).build();
|
Detector d = new Detector.Builder("count", null).build();
|
||||||
|
|
||||||
AnalysisConfig.Builder builder = new AnalysisConfig.Builder(Arrays.asList(d));
|
AnalysisConfig.Builder builder = new AnalysisConfig.Builder(Arrays.asList(d));
|
||||||
analysisConfig = builder.build();
|
analysisConfig = builder.build();
|
||||||
|
|
||||||
specialEvents.add(new SpecialEvent.Builder().description("The Ashes")
|
scheduledEvents.add(new ScheduledEvent.Builder().description("The Ashes")
|
||||||
.startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1511395200000L), ZoneOffset.UTC))
|
.startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1511395200000L), ZoneOffset.UTC))
|
||||||
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1515369600000L), ZoneOffset.UTC))
|
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1515369600000L), ZoneOffset.UTC))
|
||||||
.calendarId("calendar_id").build());
|
.calendarId("calendar_id").build());
|
||||||
specialEvents.add(new SpecialEvent.Builder().description("elasticon")
|
scheduledEvents.add(new ScheduledEvent.Builder().description("elasticon")
|
||||||
.startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1519603200000L), ZoneOffset.UTC))
|
.startTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1519603200000L), ZoneOffset.UTC))
|
||||||
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1519862400000L), ZoneOffset.UTC))
|
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1519862400000L), ZoneOffset.UTC))
|
||||||
.calendarId("calendar_id").build());
|
.calendarId("calendar_id").build());
|
||||||
|
@ -263,6 +263,6 @@ public class FieldConfigWriterTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldConfigWriter createFieldConfigWriter() {
|
private FieldConfigWriter createFieldConfigWriter() {
|
||||||
return new FieldConfigWriter(analysisConfig, filters, specialEvents, writer, mock(Logger.class));
|
return new FieldConfigWriter(analysisConfig, filters, scheduledEvents, writer, mock(Logger.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"description" : "A list of special events",
|
"description" : "A list of events",
|
||||||
"required" : true
|
"required" : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,45 +259,45 @@
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "events"
|
calendar_id: "events"
|
||||||
- length: { special_events: 4 }
|
- length: { events: 4 }
|
||||||
- match: { special_events.0.description: "event 1" }
|
- match: { events.0.description: "event 1" }
|
||||||
- match: { special_events.1.description: "event 2" }
|
- match: { events.1.description: "event 2" }
|
||||||
- match: { special_events.2.description: "event 3" }
|
- match: { events.2.description: "event 3" }
|
||||||
- match: { special_events.3.description: "event 4" }
|
- match: { events.3.description: "event 4" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "events"
|
calendar_id: "events"
|
||||||
from: 1
|
from: 1
|
||||||
size: 2
|
size: 2
|
||||||
- length: { special_events: 2 }
|
- length: { events: 2 }
|
||||||
- match: { special_events.0.description: "event 2" }
|
- match: { events.0.description: "event 2" }
|
||||||
- match: { special_events.1.description: "event 3" }
|
- match: { events.1.description: "event 3" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "events"
|
calendar_id: "events"
|
||||||
before: "2017-12-12T00:00:00Z"
|
before: "2017-12-12T00:00:00Z"
|
||||||
- length: { special_events: 2 }
|
- length: { events: 2 }
|
||||||
- match: { special_events.0.description: "event 1" }
|
- match: { events.0.description: "event 1" }
|
||||||
- match: { special_events.1.description: "event 2" }
|
- match: { events.1.description: "event 2" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "events"
|
calendar_id: "events"
|
||||||
after: "2017-12-05T03:00:00Z"
|
after: "2017-12-05T03:00:00Z"
|
||||||
- length: { special_events: 3 }
|
- length: { events: 3 }
|
||||||
- match: { special_events.0.description: "event 2" }
|
- match: { events.0.description: "event 2" }
|
||||||
- match: { special_events.1.description: "event 3" }
|
- match: { events.1.description: "event 3" }
|
||||||
- match: { special_events.2.description: "event 4" }
|
- match: { events.2.description: "event 4" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "events"
|
calendar_id: "events"
|
||||||
after: "2017-12-02T00:00:00Z"
|
after: "2017-12-02T00:00:00Z"
|
||||||
before: "2017-12-12T00:00:00Z"
|
before: "2017-12-12T00:00:00Z"
|
||||||
- length: { special_events: 1 }
|
- length: { events: 1 }
|
||||||
- match: { special_events.0.description: "event 2" }
|
- match: { events.0.description: "event 2" }
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test get all calendar events":
|
"Test get all calendar events":
|
||||||
|
@ -327,7 +327,7 @@
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
calendar_id: "_all"
|
calendar_id: "_all"
|
||||||
- length: { special_events: 4 }
|
- length: { events: 4 }
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test get calendar events for job":
|
"Test get calendar events for job":
|
||||||
|
@ -397,7 +397,7 @@
|
||||||
calendar_id: _all
|
calendar_id: _all
|
||||||
job_id: cal-crud-job-with-events
|
job_id: cal-crud-job-with-events
|
||||||
- match: { count: 4 }
|
- match: { count: 4 }
|
||||||
- length: { special_events: 4 }
|
- length: { events: 4 }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
xpack.ml.get_calendar_events:
|
xpack.ml.get_calendar_events:
|
||||||
|
@ -405,6 +405,6 @@
|
||||||
after: "2018-01-01T00:00:00Z"
|
after: "2018-01-01T00:00:00Z"
|
||||||
job_id: cal-crud-job-with-events
|
job_id: cal-crud-job-with-events
|
||||||
- match: { count: 2 }
|
- match: { count: 2 }
|
||||||
- length: { special_events: 2 }
|
- length: { events: 2 }
|
||||||
- match: { special_events.0.description: ny }
|
- match: { events.0.description: ny }
|
||||||
- match: { special_events.1.description: other }
|
- match: { events.1.description: other }
|
||||||
|
|
Loading…
Reference in New Issue