diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/MlMetaIndex.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/MlMetaIndex.java index cc8153c0777..4b93fe39fa4 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/MlMetaIndex.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/MlMetaIndex.java @@ -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() diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsAction.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsAction.java index 1f596070a4c..cfb4000dc41 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsAction.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/action/GetCalendarEventsAction.java @@ -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 specialEvents; + private QueryPage scheduledEvents; Response() { } - public Response(QueryPage specialEvents) { - this.specialEvents = specialEvents; + public Response(QueryPage 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 events = new ArrayList<>(); + List events = new ArrayList<>(); XContent xContent = contentType.xContent(); int lineNumber = 0; @@ -95,17 +75,17 @@ public class PostCalendarEventsAction extends Action specialEvents; + private List scheduledEvents; Request() { } - public Request(String calendarId, List specialEvents) { + public Request(String calendarId, List 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 getSpecialEvents() { - return specialEvents; + public List getScheduledEvents() { + return scheduledEvents; } @Override @@ -157,19 +137,19 @@ public class PostCalendarEventsAction extends Action specialEvent; + private List scheduledEvents; Response() { } - public Response(List specialEvents) { + public Response(List 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 detectorUpdates; - private boolean updateSpecialEvents = false; + private boolean updateScheduledEvents = false; Request() { } public Request(String jobId, ModelPlotConfig modelPlotConfig, List 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); } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/SpecialEvent.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/ScheduledEvent.java similarity index 88% rename from plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/SpecialEvent.java rename to plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/ScheduledEvent.java index 38250dfb454..1c99a25720f 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/SpecialEvent.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/calendars/ScheduledEvent.java @@ -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 PARSER = - new ObjectParser<>("special_event", Builder::new); + public static final ObjectParser 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); } } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/config/JobUpdate.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/config/JobUpdate.java index 85096c49a34..1e24a2dde69 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/config/JobUpdate.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/config/JobUpdate.java @@ -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 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 customSettings; private final String modelSnapshotId; private final Long establishedModelMemory; - private final boolean updateSpecialEvents; + private final boolean updateScheduledEvents; private JobUpdate(String jobId, @Nullable List groups, @Nullable String description, @Nullable List 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 categorisationFilters, @Nullable Map 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 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); } } } diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java index 269ea86fe33..167a51e6fc2 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java @@ -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 getSpecialEventsListener = ActionListener.wrap( + ActionListener 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> handler) { + public void scheduledEventsForJob(String jobId, ScheduledEventsQueryBuilder queryBuilder, + ActionListener> handler) { // Find all the calendars used by the job then the events for those calendars ActionListener> 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 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> handler) { + public void scheduledEvents(ScheduledEventsQueryBuilder query, ActionListener> 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.wrap( response -> { - List specialEvents = new ArrayList<>(); + List 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); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/SpecialEventsQueryBuilder.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java similarity index 76% rename from plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/SpecialEventsQueryBuilder.java rename to plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java index 18646adcd17..4909ef55d77 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/SpecialEventsQueryBuilder.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/persistence/ScheduledEventsQueryBuilder.java @@ -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 calendarIds 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 calendarIds) { + public ScheduledEventsQueryBuilder calendarIds(List 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 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); diff --git a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java index c9ca66fb69d..0991e0935bd 100644 --- a/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java +++ b/plugin/core/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/params/AutodetectParams.java @@ -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 filters; - private final List specialEvents; + private final List scheduledEvents; private AutodetectParams(DataCounts dataCounts, ModelSizeStats modelSizeStats, @Nullable ModelSnapshot modelSnapshot, @Nullable Quantiles quantiles, Set filters, - List specialEvents) { + List 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 specialEvents() { - return specialEvents; + public List 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 filters; - private List specialEvents; + private List 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 specialEvents) { - this.specialEvents = specialEvents; + public Builder setScheduledEvents(List 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); } } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java index 8c282caa77c..e8980d00203 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetCalendarEventsAction.java @@ -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 listener) { ActionListener 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> eventsListener = ActionListener.wrap( + ActionListener> eventsListener = ActionListener.wrap( events -> { listener.onResponse(new GetCalendarEventsAction.Response(events)); }, @@ -58,9 +58,9 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction listener) { - List events = request.getSpecialEvents(); + List events = request.getScheduledEvents(); ActionListener 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 { if (e == null) { listener.onResponse(new UpdateProcessAction.Response()); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java index 03466ec4ac2..2e677f2f92c 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/UpdateJobProcessNotifier.java @@ -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() { diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java index 4f812928465..904c8a7b1aa 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectBuilder.java @@ -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 filesToDelete; private Logger logger; private Set referencedFilters; - private List specialEvents; + private List 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 filters) { @@ -89,8 +89,8 @@ public class AutodetectBuilder { return this; } - public AutodetectBuilder specialEvents(List specialEvents) { - this.specialEvents = specialEvents; + public AutodetectBuilder scheduledEvents(List 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(); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicator.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicator.java index b3d044b1807..c76b8e5c3e8 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicator.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicator.java @@ -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 specialEvents, + public void writeUpdateProcessMessage(UpdateParams updateParams, List scheduledEvents, BiConsumer handler) { submitOperation(() -> { if (updateParams.getModelPlotConfig() != null) { @@ -197,15 +197,15 @@ public class AutodetectCommunicator implements Closeable { } List 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> rules = new ArrayList<>(job.getAnalysisConfig().getDetectors().size()); for (int i = 0; i < job.getAnalysisConfig().getDetectors().size(); i++) { List detectorRules = new ArrayList<>(eventsAsRules); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java index f3857b6c5c6..1802b5a230f 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManager.java @@ -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> eventsListener = ActionListener.wrap( - specialEvents -> { - communicator.writeUpdateProcessMessage(updateParams, specialEvents.results(), (aVoid, e) -> { + ActionListener> 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(Collections.emptyList(), 0, SpecialEvent.RESULTS_FIELD)); + eventsListener.onResponse(new QueryPage(Collections.emptyList(), 0, ScheduledEvent.RESULTS_FIELD)); } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java index c5193d17eb4..320d7100a4f 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/NativeAutodetectProcessFactory.java @@ -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 diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/UpdateParams.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/UpdateParams.java index db2b7f1d320..64947c57d32 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/UpdateParams.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/UpdateParams.java @@ -15,14 +15,14 @@ public final class UpdateParams { private final ModelPlotConfig modelPlotConfig; private final List detectorUpdates; - private final boolean updateSpecialEvents; + private final boolean updateScheduledEvents; public UpdateParams(@Nullable ModelPlotConfig modelPlotConfig, @Nullable List 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; } } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ControlMsgToProcessWriter.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ControlMsgToProcessWriter.java index 3bcf086449a..e5e81697209 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ControlMsgToProcessWriter.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/ControlMsgToProcessWriter.java @@ -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; diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java index c25635478dc..5933783837f 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriter.java @@ -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 filters; - private final List specialEvents; + private final List scheduledEvents; private final OutputStreamWriter writer; private final Logger logger; - public FieldConfigWriter(AnalysisConfig config, Set filters, List specialEvents, + public FieldConfigWriter(AnalysisConfig config, Set filters, List 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 events = specialEvents.stream().map(e -> e.toDetectionRule(config.getBucketSpan())) + List 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 specialEvents, + private void writeDetectorRules(int detectorId, Detector detector, List scheduledEvents, StringBuilder contents) throws IOException { List rules = new ArrayList<>(); if (detector.getRules() != null) { rules.addAll(detector.getRules()); } - rules.addAll(specialEvents); + rules.addAll(scheduledEvents); if (rules.isEmpty()) { return; diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java index 09f1663f9d6..b74936b2c5b 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PostCalendarEventActionRequestTests.java @@ -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 events = new ArrayList<>(); + List events = new ArrayList<>(); for (int i=0; i { diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/SpecialEventTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/ScheduledEventTests.java similarity index 82% rename from plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/SpecialEventTests.java rename to plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/ScheduledEventTests.java index 8cf11a300e1..fae46b00ec0 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/SpecialEventTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/calendars/ScheduledEventTests.java @@ -27,32 +27,32 @@ import java.util.List; import static org.hamcrest.Matchers.containsString; -public class SpecialEventTests extends AbstractSerializingTestCase { +public class ScheduledEventTests extends AbstractSerializingTestCase { - 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 instanceReader() { - return SpecialEvent::new; + protected Writeable.Reader 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 } 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 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)); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java index 501bf435624..4cbd387dde7 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/JobProviderIT.java @@ -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 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 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 returnedEvents = getSpecialEventsForJob(jobA.getId(), query); + ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder(); + List 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 events = new ArrayList<>(); + List 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 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 getSpecialEventsForJob(String jobId, SpecialEventsQueryBuilder query) throws Exception { + private List getScheduledEventsForJob(String jobId, ScheduledEventsQueryBuilder query) throws Exception { AtomicReference errorHolder = new AtomicReference<>(); - AtomicReference> searchResultHolder = new AtomicReference<>(); + AtomicReference> 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 events) throws IOException { + private void indexScheduledEvents(List 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")); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicatorTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicatorTests.java index 449060a0110..799305ea8ab 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicatorTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectCommunicatorTests.java @@ -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 events = Collections.singletonList(SpecialEventTests.createSpecialEvent(randomAlphaOfLength(10))); + List 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 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()))); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java index b6ea9e659b2..33b68193937 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/writer/FieldConfigWriterTests.java @@ -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 filters; - private List specialEvents; + private List 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)); } } diff --git a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.post_calendar_events.json b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.post_calendar_events.json index 7c75c3d6fef..71ed167a736 100644 --- a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.post_calendar_events.json +++ b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.post_calendar_events.json @@ -13,7 +13,7 @@ } }, "body": { - "description" : "A list of special events", + "description" : "A list of events", "required" : true } } diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/calendar_crud.yml b/plugin/src/test/resources/rest-api-spec/test/ml/calendar_crud.yml index c31b056a293..df8434a64e0 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/calendar_crud.yml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/calendar_crud.yml @@ -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 }