[ML] Rename SpecialEvents -> ScheduledEvents (elastic/x-pack-elasticsearch#3485)

* Rename SpecialEvents -> ScheduledEvents


Original commit: elastic/x-pack-elasticsearch@4bfc52c435
This commit is contained in:
David Kyle 2018-01-05 16:35:42 +00:00 committed by GitHub
parent f508e14e06
commit 2eb3f02e40
28 changed files with 253 additions and 301 deletions

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.ml;
import org.elasticsearch.common.xcontent.XContentBuilder;
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 java.io.IOException;
@ -39,10 +39,10 @@ public final class MlMetaIndex {
.startObject(Calendar.JOB_IDS.getPreferredName())
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.KEYWORD)
.endObject()
.startObject(SpecialEvent.START_TIME.getPreferredName())
.startObject(ScheduledEvent.START_TIME.getPreferredName())
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
.endObject()
.startObject(SpecialEvent.END_TIME.getPreferredName())
.startObject(ScheduledEvent.END_TIME.getPreferredName())
.field(ElasticsearchMappings.TYPE, ElasticsearchMappings.DATE)
.endObject()
.endObject()

View File

@ -6,38 +6,27 @@
package org.elasticsearch.xpack.ml.action;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
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.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
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.QueryPage;
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.persistence.JobProvider;
import org.elasticsearch.xpack.ml.job.persistence.SpecialEventsQueryBuilder;
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
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 {
private QueryPage<SpecialEvent> specialEvents;
private QueryPage<ScheduledEvent> scheduledEvents;
Response() {
}
public Response(QueryPage<SpecialEvent> specialEvents) {
this.specialEvents = specialEvents;
public Response(QueryPage<ScheduledEvent> scheduledEvents) {
this.scheduledEvents = scheduledEvents;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
specialEvents = new QueryPage<>(in, SpecialEvent::new);
scheduledEvents = new QueryPage<>(in, ScheduledEvent::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
specialEvents.writeTo(out);
scheduledEvents.writeTo(out);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return specialEvents.toXContent(builder, params);
return scheduledEvents.toXContent(builder, params);
}
@Override
public int hashCode() {
return Objects.hash(specialEvents);
return Objects.hash(scheduledEvents);
}
@Override
@ -254,7 +243,7 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
return false;
}
Response other = (Response) obj;
return Objects.equals(specialEvents, other.specialEvents);
return Objects.equals(scheduledEvents, other.scheduledEvents);
}
}

View File

@ -6,53 +6,33 @@
package org.elasticsearch.xpack.ml.action;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
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.client.Client;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
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.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
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.SpecialEvent;
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
import org.elasticsearch.xpack.ml.job.messages.Messages;
import org.elasticsearch.xpack.ml.job.persistence.JobProvider;
import org.elasticsearch.xpack.ml.utils.ExceptionsHelper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.elasticsearch.xpack.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.ClientHelper.executeAsyncWithOrigin;
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 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() {
super(NAME);
@ -79,7 +59,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
public static class Request extends ActionRequest {
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();
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 {
SpecialEvent.Builder event = SpecialEvent.PARSER.apply(parser, null);
ScheduledEvent.Builder event = ScheduledEvent.PARSER.apply(parser, null);
events.add(event);
} 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;
}
}
for (SpecialEvent.Builder event: events) {
for (ScheduledEvent.Builder event: events) {
if (event.getCalendarId() != null && event.getCalendarId().equals(calendarId) == false) {
throw ExceptionsHelper.badRequestException(Messages.getMessage(Messages.INCONSISTENT_ID,
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
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) {
@ -130,22 +110,22 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
}
private String calendarId;
private List<SpecialEvent> specialEvents;
private List<ScheduledEvent> scheduledEvents;
Request() {
}
public Request(String calendarId, List<SpecialEvent> specialEvents) {
public Request(String calendarId, List<ScheduledEvent> scheduledEvents) {
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() {
return calendarId;
}
public List<SpecialEvent> getSpecialEvents() {
return specialEvents;
public List<ScheduledEvent> getScheduledEvents() {
return scheduledEvents;
}
@Override
@ -157,19 +137,19 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
calendarId = in.readString();
specialEvents = in.readList(SpecialEvent::new);
scheduledEvents = in.readList(ScheduledEvent::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(calendarId);
out.writeList(specialEvents);
out.writeList(scheduledEvents);
}
@Override
public int hashCode() {
return Objects.hash(calendarId, specialEvents);
return Objects.hash(calendarId, scheduledEvents);
}
@Override
@ -181,7 +161,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
return false;
}
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 {
private List<SpecialEvent> specialEvent;
private List<ScheduledEvent> scheduledEvents;
Response() {
}
public Response(List<SpecialEvent> specialEvents) {
public Response(List<ScheduledEvent> scheduledEvents) {
super(true);
this.specialEvent = specialEvents;
this.scheduledEvents = scheduledEvents;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
readAcknowledged(in);
in.readList(SpecialEvent::new);
in.readList(ScheduledEvent::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeAcknowledged(out);
out.writeList(specialEvent);
out.writeList(scheduledEvents);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(SPECIAL_EVENTS.getPreferredName(), specialEvent);
builder.field(EVENTS.getPreferredName(), scheduledEvents);
builder.endObject();
return builder;
}
@Override
public int hashCode() {
return Objects.hash(isAcknowledged(), specialEvent);
return Objects.hash(isAcknowledged(), scheduledEvents);
}
@Override
@ -240,7 +220,7 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
return false;
}
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);
}
}
}

View File

@ -111,17 +111,17 @@ public class UpdateProcessAction extends
private ModelPlotConfig modelPlotConfig;
private List<JobUpdate.DetectorUpdate> detectorUpdates;
private boolean updateSpecialEvents = false;
private boolean updateScheduledEvents = false;
Request() {
}
public Request(String jobId, ModelPlotConfig modelPlotConfig, List<JobUpdate.DetectorUpdate> detectorUpdates,
boolean updateSpecialEvents) {
boolean updateScheduledEvents) {
super(jobId);
this.modelPlotConfig = modelPlotConfig;
this.detectorUpdates = detectorUpdates;
this.updateSpecialEvents = updateSpecialEvents;
this.updateScheduledEvents = updateScheduledEvents;
}
public ModelPlotConfig getModelPlotConfig() {
@ -132,8 +132,8 @@ public class UpdateProcessAction extends
return detectorUpdates;
}
public boolean isUpdateSpecialEvents() {
return updateSpecialEvents;
public boolean isUpdateScheduledEvents() {
return updateScheduledEvents;
}
@Override
@ -144,7 +144,7 @@ public class UpdateProcessAction extends
detectorUpdates = in.readList(JobUpdate.DetectorUpdate::new);
}
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);
}
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
out.writeBoolean(updateSpecialEvents);
out.writeBoolean(updateScheduledEvents);
}
}
@Override
public int hashCode() {
return Objects.hash(getJobId(), modelPlotConfig, detectorUpdates, updateSpecialEvents);
return Objects.hash(getJobId(), modelPlotConfig, detectorUpdates, updateScheduledEvents);
}
@Override
@ -180,7 +180,7 @@ public class UpdateProcessAction extends
return Objects.equals(getJobId(), other.getJobId()) &&
Objects.equals(modelPlotConfig, other.modelPlotConfig) &&
Objects.equals(detectorUpdates, other.detectorUpdates) &&
Objects.equals(updateSpecialEvents, other.updateSpecialEvents);
Objects.equals(updateScheduledEvents, other.updateScheduledEvents);
}
}

View File

@ -33,24 +33,24 @@ import java.util.ArrayList;
import java.util.List;
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 START_TIME = new ParseField("start_time");
public static final ParseField END_TIME = new ParseField("end_time");
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 ObjectParser<SpecialEvent.Builder, Void> PARSER =
new ObjectParser<>("special_event", Builder::new);
public static final ObjectParser<ScheduledEvent.Builder, Void> PARSER =
new ObjectParser<>("scheduled_event", Builder::new);
static {
PARSER.declareString(SpecialEvent.Builder::description, DESCRIPTION);
PARSER.declareField(SpecialEvent.Builder::startTime, p -> {
PARSER.declareString(ScheduledEvent.Builder::description, DESCRIPTION);
PARSER.declareField(ScheduledEvent.Builder::startTime, p -> {
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
} else if (p.currentToken() == XContentParser.Token.VALUE_STRING) {
@ -59,7 +59,7 @@ public class SpecialEvent implements ToXContentObject, Writeable {
throw new IllegalArgumentException(
"unexpected token [" + p.currentToken() + "] for [" + START_TIME.getPreferredName() + "]");
}, START_TIME, ObjectParser.ValueType.VALUE);
PARSER.declareField(SpecialEvent.Builder::endTime, p -> {
PARSER.declareField(ScheduledEvent.Builder::endTime, p -> {
if (p.currentToken() == XContentParser.Token.VALUE_NUMBER) {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(p.longValue()), ZoneOffset.UTC);
} 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() + "]");
}, END_TIME, ObjectParser.ValueType.VALUE);
PARSER.declareString(SpecialEvent.Builder::calendarId, Calendar.ID);
PARSER.declareString(ScheduledEvent.Builder::calendarId, Calendar.ID);
PARSER.declareString((builder, s) -> {}, TYPE);
}
@ -82,14 +82,14 @@ public class SpecialEvent implements ToXContentObject, Writeable {
private final ZonedDateTime endTime;
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.startTime = Objects.requireNonNull(startTime);
this.endTime = Objects.requireNonNull(endTime);
this.calendarId = Objects.requireNonNull(calendarId);
}
public SpecialEvent(StreamInput in) throws IOException {
public ScheduledEvent(StreamInput in) throws IOException {
description = in.readString();
startTime = 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
* 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.field(Calendar.ID.getPreferredName(), calendarId);
if (params.paramAsBoolean(MlMetaIndex.INCLUDE_TYPE_KEY, false)) {
builder.field(TYPE.getPreferredName(), SPECIAL_EVENT_TYPE);
builder.field(TYPE.getPreferredName(), SCHEDULED_EVENT_TYPE);
}
builder.endObject();
return builder;
@ -168,11 +168,11 @@ public class SpecialEvent implements ToXContentObject, Writeable {
return true;
}
if (!(obj instanceof SpecialEvent)) {
if (!(obj instanceof ScheduledEvent)) {
return false;
}
SpecialEvent other = (SpecialEvent) obj;
ScheduledEvent other = (ScheduledEvent) obj;
// In Java 8 the tests pass with ZonedDateTime.isEquals() or ZonedDateTime.toInstant.equals()
// but in Java 9 & 10 the same tests fail.
// 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;
}
public SpecialEvent build() {
public ScheduledEvent build() {
if (description == null) {
throw ExceptionsHelper.badRequestException(
Messages.getMessage(Messages.FIELD_CANNOT_BE_NULL, DESCRIPTION.getPreferredName()));
@ -245,11 +245,11 @@ public class SpecialEvent implements ToXContentObject, Writeable {
}
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 + "]");
}
return new SpecialEvent(description, startTime, endTime, calendarId);
return new ScheduledEvent(description, startTime, endTime, calendarId);
}
}
}

View File

@ -29,7 +29,7 @@ import java.util.Objects;
public class JobUpdate implements Writeable, ToXContentObject {
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<>(
"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.declareString(Builder::setModelSnapshotId, Job.MODEL_SNAPSHOT_ID);
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 String modelSnapshotId;
private final Long establishedModelMemory;
private final boolean updateSpecialEvents;
private final boolean updateScheduledEvents;
private JobUpdate(String jobId, @Nullable List<String> groups, @Nullable String description,
@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 modelSnapshotRetentionDays, @Nullable List<String> categorisationFilters,
@Nullable Map<String, Object> customSettings, @Nullable String modelSnapshotId,
@Nullable Long establishedModelMemory, boolean updateSpecialEvents) {
@Nullable Long establishedModelMemory, boolean updateScheduledEvents) {
this.jobId = jobId;
this.groups = groups;
this.description = description;
@ -98,7 +98,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
this.customSettings = customSettings;
this.modelSnapshotId = modelSnapshotId;
this.establishedModelMemory = establishedModelMemory;
this.updateSpecialEvents = updateSpecialEvents;
this.updateScheduledEvents = updateScheduledEvents;
}
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)) {
updateSpecialEvents = in.readBoolean();
updateScheduledEvents = in.readBoolean();
} else {
updateSpecialEvents = false;
updateScheduledEvents = false;
}
}
@ -170,7 +170,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
}
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;
}
public boolean isUpdateSpecialEvents() {
return updateSpecialEvents;
public boolean isUpdateScheduledEvents() {
return updateScheduledEvents;
}
@Override
@ -281,7 +281,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
if (establishedModelMemory != null) {
builder.field(Job.ESTABLISHED_MODEL_MEMORY.getPreferredName(), establishedModelMemory);
}
builder.field(UPDATE_SPECIAL_EVENTS.getPreferredName(), updateSpecialEvents);
builder.field(UPDATE_SCHEDULED_EVENTS.getPreferredName(), updateScheduledEvents);
builder.endObject();
return builder;
}
@ -419,14 +419,14 @@ public class JobUpdate implements Writeable, ToXContentObject {
&& Objects.equals(this.customSettings, that.customSettings)
&& Objects.equals(this.modelSnapshotId, that.modelSnapshotId)
&& Objects.equals(this.establishedModelMemory, that.establishedModelMemory)
&& Objects.equals(this.updateSpecialEvents, that.updateSpecialEvents);
&& Objects.equals(this.updateScheduledEvents, that.updateScheduledEvents);
}
@Override
public int hashCode() {
return Objects.hash(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, renormalizationWindowDays,
backgroundPersistInterval, modelSnapshotRetentionDays, resultsRetentionDays, categorizationFilters, customSettings,
modelSnapshotId, establishedModelMemory, updateSpecialEvents);
modelSnapshotId, establishedModelMemory, updateScheduledEvents);
}
public static class DetectorUpdate implements Writeable, ToXContentObject {
@ -536,7 +536,7 @@ public class JobUpdate implements Writeable, ToXContentObject {
private Map<String, Object> customSettings;
private String modelSnapshotId;
private Long establishedModelMemory;
private boolean updateSpecialEvents = false;
private boolean updateScheduledEvents = false;
public Builder(String jobId) {
this.jobId = jobId;
@ -612,15 +612,15 @@ public class JobUpdate implements Writeable, ToXContentObject {
return this;
}
public Builder setUpdateSpecialEvents(boolean updateSpecialEvents) {
this.updateSpecialEvents = updateSpecialEvents;
public Builder setUpdateScheduledEvents(boolean updateScheduledEvents) {
this.updateScheduledEvents = updateScheduledEvents;
return this;
}
public JobUpdate build() {
return new JobUpdate(jobId, groups, description, detectorUpdates, modelPlotConfig, analysisLimits, backgroundPersistInterval,
renormalizationWindowDays, resultsRetentionDays, modelSnapshotRetentionDays, categorizationFilters, customSettings,
modelSnapshotId, establishedModelMemory, updateSpecialEvents);
modelSnapshotId, establishedModelMemory, updateScheduledEvents);
}
}
}

View File

@ -73,7 +73,7 @@ import org.elasticsearch.xpack.ml.action.GetInfluencersAction;
import org.elasticsearch.xpack.ml.action.GetRecordsAction;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
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.MlFilter;
import org.elasticsearch.xpack.ml.job.persistence.InfluencersQueryBuilder.InfluencersQuery;
@ -366,16 +366,16 @@ public class JobProvider {
String jobId = job.getId();
ActionListener<AutodetectParams.Builder> getSpecialEventsListener = ActionListener.wrap(
ActionListener<AutodetectParams.Builder> getScheduledEventsListener = ActionListener.wrap(
paramsBuilder -> {
SpecialEventsQueryBuilder specialEventsQuery = new SpecialEventsQueryBuilder();
ScheduledEventsQueryBuilder scheduledEventsQueryBuilder = new ScheduledEventsQueryBuilder();
Date lastestRecordTime = paramsBuilder.getDataCounts().getLatestRecordTimeStamp();
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 -> {
paramsBuilder.setSpecialEvents(events.results());
paramsBuilder.setScheduledEvents(events.results());
consumer.accept(paramsBuilder.build());
},
errorHandler
@ -434,7 +434,7 @@ public class JobProvider {
}
}
getSpecialEventsListener.onResponse(paramsBuilder);
getScheduledEventsListener.onResponse(paramsBuilder);
},
errorHandler
), 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
ActionListener<QueryPage<Calendar>> calendarsListener = ActionListener.wrap(
calendars -> {
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;
}
List<String> calendarIds = calendars.results().stream().map(Calendar::getId).collect(Collectors.toList());
queryBuilder.calendarIds(calendarIds);
specialEvents(queryBuilder, handler);
scheduledEvents(queryBuilder, handler);
},
handler::onFailure
);
@ -1050,7 +1051,7 @@ public class JobProvider {
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)
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setSource(query.build());
@ -1058,14 +1059,14 @@ public class JobProvider {
executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, request.request(),
ActionListener.<SearchResponse>wrap(
response -> {
List<SpecialEvent> specialEvents = new ArrayList<>();
List<ScheduledEvent> events = new ArrayList<>();
SearchHit[] hits = response.getHits().getHits();
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(),
SpecialEvent.RESULTS_FIELD));
handler.onResponse(new QueryPage<>(events, response.getHits().getTotalHits(),
ScheduledEvent.RESULTS_FIELD));
},
handler::onFailure)
, client::search);

View File

@ -12,16 +12,16 @@ import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.index.query.TermsQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
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.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.
*/
public class SpecialEventsQueryBuilder {
public class ScheduledEventsQueryBuilder {
public static final int DEFAULT_SIZE = 1000;
private int from = 0;
@ -31,27 +31,27 @@ public class SpecialEventsQueryBuilder {
private String after;
private String before;
public SpecialEventsQueryBuilder calendarIds(List<String> calendarIds) {
public ScheduledEventsQueryBuilder calendarIds(List<String> calendarIds) {
this.calendarIds = calendarIds;
return this;
}
public SpecialEventsQueryBuilder after(String after) {
public ScheduledEventsQueryBuilder after(String after) {
this.after = after;
return this;
}
public SpecialEventsQueryBuilder before(String before) {
public ScheduledEventsQueryBuilder before(String before) {
this.before = before;
return this;
}
public SpecialEventsQueryBuilder from(int from) {
public ScheduledEventsQueryBuilder from(int from) {
this.from = from;
return this;
}
public SpecialEventsQueryBuilder size(int size) {
public ScheduledEventsQueryBuilder size(int size) {
this.size = size;
return this;
}
@ -60,12 +60,12 @@ public class SpecialEventsQueryBuilder {
List<QueryBuilder> queries = new ArrayList<>();
if (after != null) {
RangeQueryBuilder afterQuery = QueryBuilders.rangeQuery(SpecialEvent.END_TIME.getPreferredName());
RangeQueryBuilder afterQuery = QueryBuilders.rangeQuery(ScheduledEvent.END_TIME.getPreferredName());
afterQuery.gt(after);
queries.add(afterQuery);
}
if (before != null) {
RangeQueryBuilder beforeQuery = QueryBuilders.rangeQuery(SpecialEvent.START_TIME.getPreferredName());
RangeQueryBuilder beforeQuery = QueryBuilders.rangeQuery(ScheduledEvent.START_TIME.getPreferredName());
beforeQuery.lt(before);
queries.add(beforeQuery);
}
@ -74,10 +74,10 @@ public class SpecialEventsQueryBuilder {
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.sort(SpecialEvent.START_TIME.getPreferredName());
searchSourceBuilder.sort(ScheduledEvent.START_TIME.getPreferredName());
searchSourceBuilder.from(from);
searchSourceBuilder.size(size);

View File

@ -5,9 +5,8 @@
*/
package org.elasticsearch.xpack.ml.job.process.autodetect.params;
import org.elasticsearch.Build;
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.process.autodetect.state.DataCounts;
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 java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@ -30,19 +28,19 @@ public class AutodetectParams {
@Nullable
private final Quantiles quantiles;
private final Set<MlFilter> filters;
private final List<SpecialEvent> specialEvents;
private final List<ScheduledEvent> scheduledEvents;
private AutodetectParams(DataCounts dataCounts, ModelSizeStats modelSizeStats,
@Nullable ModelSnapshot modelSnapshot,
@Nullable Quantiles quantiles, Set<MlFilter> filters,
List<SpecialEvent> specialEvents) {
List<ScheduledEvent> scheduledEvents) {
this.dataCounts = Objects.requireNonNull(dataCounts);
this.modelSizeStats = Objects.requireNonNull(modelSizeStats);
this.modelSnapshot = modelSnapshot;
this.quantiles = quantiles;
this.filters = filters;
this.specialEvents = specialEvents;
this.scheduledEvents = scheduledEvents;
}
public DataCounts dataCounts() {
@ -67,8 +65,8 @@ public class AutodetectParams {
return filters;
}
public List<SpecialEvent> specialEvents() {
return specialEvents;
public List<ScheduledEvent> scheduledEvents() {
return scheduledEvents;
}
@Override
@ -88,12 +86,12 @@ public class AutodetectParams {
&& Objects.equals(this.modelSnapshot, that.modelSnapshot)
&& Objects.equals(this.quantiles, that.quantiles)
&& Objects.equals(this.filters, that.filters)
&& Objects.equals(this.specialEvents, that.specialEvents);
&& Objects.equals(this.scheduledEvents, that.scheduledEvents);
}
@Override
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 {
@ -103,13 +101,13 @@ public class AutodetectParams {
private ModelSnapshot modelSnapshot;
private Quantiles quantiles;
private Set<MlFilter> filters;
private List<SpecialEvent> specialEvents;
private List<ScheduledEvent> scheduledEvents;
public Builder(String jobId) {
dataCounts = new DataCounts(jobId);
modelSizeStats = new ModelSizeStats.Builder(jobId).build();
filters = new HashSet<>();
specialEvents = new ArrayList<>();
scheduledEvents = new ArrayList<>();
}
public Builder setDataCounts(DataCounts dataCounts) {
@ -136,12 +134,8 @@ public class AutodetectParams {
return this;
}
public Builder addSpecialEvent(SpecialEvent specialEvent) {
specialEvents.add(specialEvent);
return this;
}
public Builder setSpecialEvents(List<SpecialEvent> specialEvents) {
this.specialEvents = specialEvents;
public Builder setScheduledEvents(List<ScheduledEvent> scheduledEvents) {
this.scheduledEvents = scheduledEvents;
return this;
}
@ -157,7 +151,7 @@ public class AutodetectParams {
public AutodetectParams build() {
return new AutodetectParams(dataCounts, modelSizeStats, modelSnapshot, quantiles,
filters, specialEvents);
filters, scheduledEvents);
}
}
}

View File

@ -14,9 +14,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
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.SpecialEventsQueryBuilder;
import org.elasticsearch.xpack.ml.job.persistence.ScheduledEventsQueryBuilder;
import java.util.Collections;
@ -40,7 +40,7 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
ActionListener<GetCalendarEventsAction.Response> listener) {
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
r -> {
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder()
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder()
.after(request.getAfter())
.before(request.getBefore())
.from(request.getPageParams().getFrom())
@ -50,7 +50,7 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
query.calendarIds(Collections.singletonList(request.getCalendarId()));
}
ActionListener<QueryPage<SpecialEvent>> eventsListener = ActionListener.wrap(
ActionListener<QueryPage<ScheduledEvent>> eventsListener = ActionListener.wrap(
events -> {
listener.onResponse(new GetCalendarEventsAction.Response(events));
},
@ -58,9 +58,9 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
);
if (request.getJobId() != null) {
jobProvider.specialEventsForJob(request.getJobId(), query, eventsListener);
jobProvider.scheduledEventsForJob(request.getJobId(), query, eventsListener);
} else {
jobProvider.specialEvents(query, eventsListener);
jobProvider.scheduledEvents(query, eventsListener);
}
},
listener::onFailure);

View File

@ -23,7 +23,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
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.utils.ExceptionsHelper;
@ -54,20 +54,20 @@ public class TransportPostCalendarEventsAction extends HandledTransportAction<Po
@Override
protected void doExecute(PostCalendarEventsAction.Request request,
ActionListener<PostCalendarEventsAction.Response> listener) {
List<SpecialEvent> events = request.getSpecialEvents();
List<ScheduledEvent> events = request.getScheduledEvents();
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
r -> {
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
for (SpecialEvent event: events) {
for (ScheduledEvent event: events) {
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
indexRequest.source(event.toXContent(builder,
new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY,
"true"))));
} catch (IOException e) {
throw new IllegalStateException("Failed to serialise special event", e);
throw new IllegalStateException("Failed to serialise event", e);
}
bulkRequestBuilder.add(indexRequest);
}
@ -84,7 +84,7 @@ public class TransportPostCalendarEventsAction extends HandledTransportAction<Po
@Override
public void onFailure(Exception e) {
listener.onFailure(
ExceptionsHelper.serverError("Error indexing special event", e));
ExceptionsHelper.serverError("Error indexing event", e));
}
});
},

View File

@ -44,7 +44,7 @@ public class TransportUpdateProcessAction extends TransportJobTaskAction<UpdateP
try {
processManager.writeUpdateProcessMessage(task,
new UpdateParams(request.getModelPlotConfig(),
request.getDetectorUpdates(), request.isUpdateSpecialEvents()),
request.getDetectorUpdates(), request.isUpdateScheduledEvents()),
e -> {
if (e == null) {
listener.onResponse(new UpdateProcessAction.Response());

View File

@ -100,7 +100,7 @@ public class UpdateJobProcessNotifier extends AbstractComponent implements Local
void executeRemoteJob(JobUpdate update) {
Request request = new Request(update.getJobId(), update.getModelPlotConfig(), update.getDetectorUpdates(),
update.isUpdateSpecialEvents());
update.isUpdateScheduledEvents());
executeAsyncWithOrigin(client, ML_ORIGIN, UpdateProcessAction.INSTANCE, request,
new ActionListener<Response>() {

View File

@ -8,7 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.settings.Settings;
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.Job;
import org.elasticsearch.xpack.ml.job.config.MlFilter;
@ -46,7 +46,7 @@ public class AutodetectBuilder {
private List<Path> filesToDelete;
private Logger logger;
private Set<MlFilter> referencedFilters;
private List<SpecialEvent> specialEvents;
private List<ScheduledEvent> scheduledEvents;
private Quantiles quantiles;
private Environment env;
private Settings settings;
@ -71,7 +71,7 @@ public class AutodetectBuilder {
this.filesToDelete = Objects.requireNonNull(filesToDelete);
this.logger = Objects.requireNonNull(logger);
referencedFilters = new HashSet<>();
specialEvents = Collections.emptyList();
scheduledEvents = Collections.emptyList();
}
public AutodetectBuilder referencedFilters(Set<MlFilter> filters) {
@ -89,8 +89,8 @@ public class AutodetectBuilder {
return this;
}
public AutodetectBuilder specialEvents(List<SpecialEvent> specialEvents) {
this.specialEvents = specialEvents;
public AutodetectBuilder scheduledEvents(List<ScheduledEvent> scheduledEvents) {
this.scheduledEvents = scheduledEvents;
return this;
}
@ -170,7 +170,7 @@ public class AutodetectBuilder {
try (OutputStreamWriter osw = new OutputStreamWriter(
Files.newOutputStream(fieldConfigFile),
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();

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
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.DetectionRule;
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) {
submitOperation(() -> {
if (updateParams.getModelPlotConfig() != null) {
@ -197,15 +197,15 @@ public class AutodetectCommunicator implements Closeable {
}
List<DetectionRule> eventsAsRules = Collections.emptyList();
if (specialEvents.isEmpty() == false) {
eventsAsRules = specialEvents.stream()
if (scheduledEvents.isEmpty() == false) {
eventsAsRules = scheduledEvents.stream()
.map(e -> e.toDetectionRule(job.getAnalysisConfig().getBucketSpan()))
.collect(Collectors.toList());
}
// All detection rules for a detector must be updated together as the update
// 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());
for (int i = 0; i < job.getAnalysisConfig().getDetectors().size(); i++) {
List<DetectionRule> detectorRules = new ArrayList<>(eventsAsRules);

View File

@ -25,7 +25,7 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.ml.MachineLearning;
import org.elasticsearch.xpack.ml.action.TransportOpenJobAction.JobTask;
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.config.Job;
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.JobRenormalizedResultsPersister;
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.process.DataCountsReporter;
import org.elasticsearch.xpack.ml.job.process.autodetect.output.AutoDetectResultProcessor;
@ -261,9 +261,9 @@ public class AutodetectProcessManager extends AbstractComponent {
return;
}
ActionListener<QueryPage<SpecialEvent>> eventsListener = ActionListener.wrap(
specialEvents -> {
communicator.writeUpdateProcessMessage(updateParams, specialEvents.results(), (aVoid, e) -> {
ActionListener<QueryPage<ScheduledEvent>> eventsListener = ActionListener.wrap(
events -> {
communicator.writeUpdateProcessMessage(updateParams, events.results(), (aVoid, e) -> {
if (e == null) {
handler.accept(null);
} else {
@ -273,11 +273,11 @@ public class AutodetectProcessManager extends AbstractComponent {
},
handler::accept);
if (updateParams.isUpdateSpecialEvents()) {
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder().after(Long.toString(new Date().getTime()));
jobProvider.specialEventsForJob(jobTask.getJobId(), query, eventsListener);
if (updateParams.isUpdateScheduledEvents()) {
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder().after(Long.toString(new Date().getTime()));
jobProvider.scheduledEventsForJob(jobTask.getJobId(), query, eventsListener);
} else {
eventsListener.onResponse(new QueryPage<SpecialEvent>(Collections.emptyList(), 0, SpecialEvent.RESULTS_FIELD));
eventsListener.onResponse(new QueryPage<ScheduledEvent>(Collections.emptyList(), 0, ScheduledEvent.RESULTS_FIELD));
}
}

View File

@ -13,15 +13,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.env.Environment;
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.ProcessCtrl;
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.StateProcessor;
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.NamedPipeHelper;
@ -31,7 +28,6 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;
@ -89,7 +85,7 @@ public class NativeAutodetectProcessFactory implements AutodetectProcessFactory
AutodetectBuilder autodetectBuilder = new AutodetectBuilder(job, filesToDelete, LOGGER, env,
settings, nativeController, processPipes)
.referencedFilters(autodetectParams.filters())
.specialEvents(autodetectParams.specialEvents());
.scheduledEvents(autodetectParams.scheduledEvents());
// if state is null or empty it will be ignored
// else it is used to restore the quantiles

View File

@ -15,14 +15,14 @@ public final class UpdateParams {
private final ModelPlotConfig modelPlotConfig;
private final List<JobUpdate.DetectorUpdate> detectorUpdates;
private final boolean updateSpecialEvents;
private final boolean updateScheduledEvents;
public UpdateParams(@Nullable ModelPlotConfig modelPlotConfig,
@Nullable List<JobUpdate.DetectorUpdate> detectorUpdates,
boolean updateSpecialEvents) {
boolean updateScheduledEvents) {
this.modelPlotConfig = modelPlotConfig;
this.detectorUpdates = detectorUpdates;
this.updateSpecialEvents = updateSpecialEvents;
this.updateScheduledEvents = updateScheduledEvents;
}
public ModelPlotConfig getModelPlotConfig() {
@ -33,7 +33,7 @@ public final class UpdateParams {
return detectorUpdates;
}
public boolean isUpdateSpecialEvents() {
return updateSpecialEvents;
public boolean isUpdateScheduledEvents() {
return updateScheduledEvents;
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
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.ModelPlotConfig;
import org.elasticsearch.xpack.ml.job.process.autodetect.params.DataLoadParams;

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
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.DefaultDetectorDescription;
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_FILTER_PREFIX = "categorizationfilter.";
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
// 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 Set<MlFilter> filters;
private final List<SpecialEvent> specialEvents;
private final List<ScheduledEvent> scheduledEvents;
private final OutputStreamWriter writer;
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) {
this.config = Objects.requireNonNull(config);
this.filters = Objects.requireNonNull(filters);
this.specialEvents = Objects.requireNonNull(specialEvents);
this.scheduledEvents = Objects.requireNonNull(scheduledEvents);
this.writer = Objects.requireNonNull(writer);
this.logger = Objects.requireNonNull(logger);
}
@ -79,7 +78,7 @@ public class FieldConfigWriter {
private void writeDetectors(StringBuilder contents) throws IOException {
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());
for (Detector detector : config.getDetectors()) {
@ -103,14 +102,14 @@ public class FieldConfigWriter {
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 {
List<DetectionRule> rules = new ArrayList<>();
if (detector.getRules() != null) {
rules.addAll(detector.getRules());
}
rules.addAll(specialEvents);
rules.addAll(scheduledEvents);
if (rules.isEmpty()) {
return;

View File

@ -10,8 +10,8 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.AbstractStreamableTestCase;
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
import org.elasticsearch.xpack.ml.calendars.SpecialEventTests;
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
import org.elasticsearch.xpack.ml.calendars.ScheduledEventTests;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -28,9 +28,9 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
private PostCalendarEventsAction.Request createTestInstance(String calendarId) {
int numEvents = randomIntBetween(1, 10);
List<SpecialEvent> events = new ArrayList<>();
List<ScheduledEvent> events = new ArrayList<>();
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);
@ -47,7 +47,7 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
PostCalendarEventsAction.Request sourceRequest = createTestInstance();
StringBuilder requestString = new StringBuilder();
for (SpecialEvent event: sourceRequest.getSpecialEvents()) {
for (ScheduledEvent event: sourceRequest.getScheduledEvents()) {
requestString.append(Strings.toString(event)).append("\r\n");
}
@ -60,11 +60,11 @@ public class PostCalendarEventActionRequestTests extends AbstractStreamableTestC
public void testParseRequest_throwsIfCalendarIdsAreDifferent() throws IOException {
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();
for (SpecialEvent event: sourceRequest.getSpecialEvents()) {
for (ScheduledEvent event: sourceRequest.getScheduledEvents()) {
requestString.append(Strings.toString(event)).append("\r\n");
}

View File

@ -6,16 +6,10 @@
package org.elasticsearch.xpack.ml.action;
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.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.Arrays;
import java.util.List;
public class UpdateProcessActionRequestTests extends AbstractStreamableTestCase<UpdateProcessAction.Request> {

View File

@ -27,32 +27,32 @@ import java.util.List;
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);
return new SpecialEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
return new ScheduledEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
calendarId);
}
@Override
protected SpecialEvent createTestInstance() {
return createSpecialEvent(randomAlphaOfLengthBetween(1, 20));
protected ScheduledEvent createTestInstance() {
return createScheduledEvent(randomAlphaOfLengthBetween(1, 20));
}
@Override
protected Writeable.Reader<SpecialEvent> instanceReader() {
return SpecialEvent::new;
protected Writeable.Reader<ScheduledEvent> instanceReader() {
return ScheduledEvent::new;
}
@Override
protected SpecialEvent doParseInstance(XContentParser parser) throws IOException {
return SpecialEvent.PARSER.apply(parser, null).build();
protected ScheduledEvent doParseInstance(XContentParser parser) throws IOException {
return ScheduledEvent.PARSER.apply(parser, null).build();
}
public void testToDetectionRule() {
long bucketSpanSecs = 300;
SpecialEvent event = createTestInstance();
ScheduledEvent event = createTestInstance();
DetectionRule rule = event.toDetectionRule(TimeValue.timeValueSeconds(bucketSpanSecs));
assertEquals(Connective.AND, rule.getConditionsConnective());
@ -82,7 +82,7 @@ public class SpecialEventTests extends AbstractSerializingTestCase<SpecialEvent>
}
public void testBuild() {
SpecialEvent.Builder builder = new SpecialEvent.Builder();
ScheduledEvent.Builder builder = new ScheduledEvent.Builder();
ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, builder::build);
assertEquals("Field [description] cannot be null", e.getMessage());
@ -100,7 +100,7 @@ public class SpecialEventTests extends AbstractSerializingTestCase<SpecialEvent>
builder.build();
builder = new SpecialEvent.Builder().description("f").calendarId("c");
builder = new ScheduledEvent.Builder().description("f").calendarId("c");
builder.startTime(now);
builder.endTime(now.minusHours(2));

View File

@ -27,7 +27,7 @@ import org.elasticsearch.xpack.ml.MlMetaIndex;
import org.elasticsearch.xpack.ml.action.PutJobAction;
import org.elasticsearch.xpack.ml.action.util.QueryPage;
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.Connective;
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.JobProvider;
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.state.DataCounts;
import org.elasticsearch.xpack.ml.job.process.autodetect.state.DataCountsTests;
@ -282,7 +282,7 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
return calendarHolder.get();
}
public void testSpecialEvents() throws Exception {
public void testScheduledEvents() throws Exception {
Job.Builder jobA = createJob("job_a");
Job.Builder jobB = createJob("job_b");
Job.Builder jobC = createJob("job_c");
@ -292,32 +292,32 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
calendars.add(new Calendar(calendarAId, Collections.singletonList("job_a")));
ZonedDateTime now = ZonedDateTime.now();
List<SpecialEvent> events = new ArrayList<>();
events.add(buildSpecialEvent("downtime", now.plusDays(1), now.plusDays(2), calendarAId));
events.add(buildSpecialEvent("downtime_AA", now.plusDays(8), now.plusDays(9), calendarAId));
events.add(buildSpecialEvent("downtime_AAA", now.plusDays(15), now.plusDays(16), calendarAId));
List<ScheduledEvent> events = new ArrayList<>();
events.add(buildScheduledEvent("downtime", now.plusDays(1), now.plusDays(2), calendarAId));
events.add(buildScheduledEvent("downtime_AA", now.plusDays(8), now.plusDays(9), calendarAId));
events.add(buildScheduledEvent("downtime_AAA", now.plusDays(15), now.plusDays(16), calendarAId));
String calendarABId = "maintenance_a_and_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);
indexSpecialEvents(events);
indexScheduledEvents(events);
SpecialEventsQueryBuilder query = new SpecialEventsQueryBuilder();
List<SpecialEvent> returnedEvents = getSpecialEventsForJob(jobA.getId(), query);
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder();
List<ScheduledEvent> returnedEvents = getScheduledEventsForJob(jobA.getId(), query);
assertEquals(4, returnedEvents.size());
assertEquals(events.get(0), returnedEvents.get(0));
assertEquals(events.get(1), returnedEvents.get(1));
assertEquals(events.get(3), returnedEvents.get(2));
assertEquals(events.get(2), returnedEvents.get(3));
returnedEvents = getSpecialEventsForJob(jobB.getId(), query);
returnedEvents = getScheduledEventsForJob(jobB.getId(), query);
assertEquals(1, returnedEvents.size());
assertEquals(events.get(3), returnedEvents.get(0));
returnedEvents = getSpecialEventsForJob(jobC.getId(), query);
returnedEvents = getScheduledEventsForJob(jobC.getId(), query);
assertEquals(0, returnedEvents.size());
// Test time filters
@ -325,14 +325,14 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
query.after(Long.toString(now.plusDays(8).plusHours(1).toInstant().toEpochMilli()));
// Lands halfway through the 3rd event which should be returned
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(events.get(1), returnedEvents.get(0));
assertEquals(events.get(3), returnedEvents.get(1));
}
private SpecialEvent buildSpecialEvent(String description, ZonedDateTime start, ZonedDateTime end, String calendarId) {
return new SpecialEvent.Builder().description(description).startTime(start).endTime(end).calendarId(calendarId).build();
private ScheduledEvent buildScheduledEvent(String description, ZonedDateTime start, ZonedDateTime end, String calendarId) {
return new ScheduledEvent.Builder().description(description).startTime(start).endTime(end).calendarId(calendarId).build();
}
public void testGetAutodetectParams() throws Exception {
@ -345,12 +345,12 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
// index the param docs
ZonedDateTime now = ZonedDateTime.now();
List<SpecialEvent> events = new ArrayList<>();
List<ScheduledEvent> events = new ArrayList<>();
// events in the past should be filtered out
events.add(buildSpecialEvent("In the past", now.minusDays(7), now.minusDays(6), calendarId));
events.add(buildSpecialEvent("A_downtime", now.plusDays(1), now.plusDays(2), calendarId));
events.add(buildSpecialEvent("A_downtime2", now.plusDays(8), now.plusDays(9), calendarId));
indexSpecialEvents(events);
events.add(buildScheduledEvent("In the past", now.minusDays(7), now.minusDays(6), calendarId));
events.add(buildScheduledEvent("A_downtime", now.plusDays(1), now.plusDays(2), calendarId));
events.add(buildScheduledEvent("A_downtime2", now.plusDays(8), now.plusDays(9), calendarId));
indexScheduledEvents(events);
List<MlFilter> filters = new ArrayList<>();
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()));
// special events
assertNotNull(params.specialEvents());
assertEquals(3, params.specialEvents().size());
assertEquals(events.get(0), params.specialEvents().get(0));
assertEquals(events.get(1), params.specialEvents().get(1));
assertEquals(events.get(2), params.specialEvents().get(2));
// events
assertNotNull(params.scheduledEvents());
assertEquals(3, params.scheduledEvents().size());
assertEquals(events.get(0), params.scheduledEvents().get(0));
assertEquals(events.get(1), params.scheduledEvents().get(1));
assertEquals(events.get(2), params.scheduledEvents().get(2));
// filters
assertNotNull(params.filters());
@ -432,11 +432,11 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
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<QueryPage<SpecialEvent>> searchResultHolder = new AtomicReference<>();
AtomicReference<QueryPage<ScheduledEvent>> searchResultHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
jobProvider.specialEventsForJob(jobId, query, ActionListener.wrap(
jobProvider.scheduledEventsForJob(jobId, query, ActionListener.wrap(
params -> {
searchResultHolder.set(params);
latch.countDown();
@ -491,11 +491,11 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
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();
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
for (SpecialEvent event : events) {
for (ScheduledEvent event : events) {
IndexRequest indexRequest = new IndexRequest(MlMetaIndex.INDEX_NAME, MlMetaIndex.TYPE);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(MlMetaIndex.INCLUDE_TYPE_KEY, "true"));

View File

@ -10,8 +10,8 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.ml.calendars.SpecialEvent;
import org.elasticsearch.xpack.ml.calendars.SpecialEventTests;
import org.elasticsearch.xpack.ml.calendars.ScheduledEvent;
import org.elasticsearch.xpack.ml.calendars.ScheduledEventTests;
import org.elasticsearch.xpack.ml.job.config.AnalysisConfig;
import org.elasticsearch.xpack.ml.job.config.DataDescription;
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
@ -91,11 +91,11 @@ public class AutodetectCommunicatorTests extends ESTestCase {
Collections.singletonList(new DetectionRule.Builder(conditions).build())));
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) -> {}));
// 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
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
InOrder inOrder = Mockito.inOrder(process);
@ -107,7 +107,7 @@ public class AutodetectCommunicatorTests extends ESTestCase {
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(
new JobUpdate.DetectorUpdate(1, "updated description",
Collections.singletonList(new DetectionRule.Builder(conditions).build())));

View File

@ -9,7 +9,7 @@ import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentFactory;
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.Condition;
import org.elasticsearch.xpack.ml.job.config.DetectionRule;
@ -47,14 +47,14 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
public class FieldConfigWriterTests extends ESTestCase {
private AnalysisConfig analysisConfig;
private Set<MlFilter> filters;
private List<SpecialEvent> specialEvents;
private List<ScheduledEvent> scheduledEvents;
private OutputStreamWriter writer;
@Before
public void setUpDeps() {
analysisConfig = new AnalysisConfig.Builder(Collections.singletonList(new Detector.Builder("count", null).build())).build();
filters = new LinkedHashSet<>();
specialEvents = new ArrayList<>();
scheduledEvents = new ArrayList<>();
}
public void testMultipleDetectorsToConfFile()
@ -232,17 +232,17 @@ public class FieldConfigWriterTests extends ESTestCase {
verifyNoMoreInteractions(writer);
}
public void testWrite_GivenSpecialEvents() throws IOException {
public void testWrite_GivenScheduledEvents() throws IOException {
Detector d = new Detector.Builder("count", null).build();
AnalysisConfig.Builder builder = new AnalysisConfig.Builder(Arrays.asList(d));
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))
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1515369600000L), ZoneOffset.UTC))
.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))
.endTime(ZonedDateTime.ofInstant(Instant.ofEpochMilli(1519862400000L), ZoneOffset.UTC))
.calendarId("calendar_id").build());
@ -263,6 +263,6 @@ public class FieldConfigWriterTests extends ESTestCase {
}
private FieldConfigWriter createFieldConfigWriter() {
return new FieldConfigWriter(analysisConfig, filters, specialEvents, writer, mock(Logger.class));
return new FieldConfigWriter(analysisConfig, filters, scheduledEvents, writer, mock(Logger.class));
}
}

View File

@ -13,7 +13,7 @@
}
},
"body": {
"description" : "A list of special events",
"description" : "A list of events",
"required" : true
}
}

View File

@ -259,45 +259,45 @@
- do:
xpack.ml.get_calendar_events:
calendar_id: "events"
- length: { special_events: 4 }
- match: { special_events.0.description: "event 1" }
- match: { special_events.1.description: "event 2" }
- match: { special_events.2.description: "event 3" }
- match: { special_events.3.description: "event 4" }
- length: { events: 4 }
- match: { events.0.description: "event 1" }
- match: { events.1.description: "event 2" }
- match: { events.2.description: "event 3" }
- match: { events.3.description: "event 4" }
- do:
xpack.ml.get_calendar_events:
calendar_id: "events"
from: 1
size: 2
- length: { special_events: 2 }
- match: { special_events.0.description: "event 2" }
- match: { special_events.1.description: "event 3" }
- length: { events: 2 }
- match: { events.0.description: "event 2" }
- match: { events.1.description: "event 3" }
- do:
xpack.ml.get_calendar_events:
calendar_id: "events"
before: "2017-12-12T00:00:00Z"
- length: { special_events: 2 }
- match: { special_events.0.description: "event 1" }
- match: { special_events.1.description: "event 2" }
- length: { events: 2 }
- match: { events.0.description: "event 1" }
- match: { events.1.description: "event 2" }
- do:
xpack.ml.get_calendar_events:
calendar_id: "events"
after: "2017-12-05T03:00:00Z"
- length: { special_events: 3 }
- match: { special_events.0.description: "event 2" }
- match: { special_events.1.description: "event 3" }
- match: { special_events.2.description: "event 4" }
- length: { events: 3 }
- match: { events.0.description: "event 2" }
- match: { events.1.description: "event 3" }
- match: { events.2.description: "event 4" }
- do:
xpack.ml.get_calendar_events:
calendar_id: "events"
after: "2017-12-02T00:00:00Z"
before: "2017-12-12T00:00:00Z"
- length: { special_events: 1 }
- match: { special_events.0.description: "event 2" }
- length: { events: 1 }
- match: { events.0.description: "event 2" }
---
"Test get all calendar events":
@ -327,7 +327,7 @@
- do:
xpack.ml.get_calendar_events:
calendar_id: "_all"
- length: { special_events: 4 }
- length: { events: 4 }
---
"Test get calendar events for job":
@ -397,7 +397,7 @@
calendar_id: _all
job_id: cal-crud-job-with-events
- match: { count: 4 }
- length: { special_events: 4 }
- length: { events: 4 }
- do:
xpack.ml.get_calendar_events:
@ -405,6 +405,6 @@
after: "2018-01-01T00:00:00Z"
job_id: cal-crud-job-with-events
- match: { count: 2 }
- length: { special_events: 2 }
- match: { special_events.0.description: ny }
- match: { special_events.1.description: other }
- length: { events: 2 }
- match: { events.0.description: ny }
- match: { events.1.description: other }