[ML] Rename event filter params (elastic/x-pack-elasticsearch#3525)
Original commit: elastic/x-pack-elasticsearch@3089193d45
This commit is contained in:
parent
45a31c953c
commit
4c973c16c2
|
@ -50,15 +50,15 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
|
||||
public static class Request extends ActionRequest implements ToXContentObject {
|
||||
|
||||
public static final ParseField AFTER = new ParseField("after");
|
||||
public static final ParseField BEFORE = new ParseField("before");
|
||||
public static final ParseField START = new ParseField("start");
|
||||
public static final ParseField END = new ParseField("end");
|
||||
|
||||
private static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
|
||||
|
||||
static {
|
||||
PARSER.declareString(Request::setCalendarId, Calendar.ID);
|
||||
PARSER.declareString(Request::setAfter, AFTER);
|
||||
PARSER.declareString(Request::setBefore, BEFORE);
|
||||
PARSER.declareString(Request::setStart, START);
|
||||
PARSER.declareString(Request::setEnd, END);
|
||||
PARSER.declareString(Request::setJobId, Job.ID);
|
||||
PARSER.declareObject(Request::setPageParams, PageParams.PARSER, PageParams.PAGE);
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
}
|
||||
|
||||
private String calendarId;
|
||||
private String after;
|
||||
private String before;
|
||||
private String start;
|
||||
private String end;
|
||||
private String jobId;
|
||||
private PageParams pageParams = PageParams.defaultParams();
|
||||
|
||||
|
@ -92,19 +92,19 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
|
||||
}
|
||||
|
||||
public String getAfter() {
|
||||
return after;
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
public void setAfter(String after) {
|
||||
this.after = after;
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public String getBefore() {
|
||||
return before;
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setBefore(String before) {
|
||||
this.before = before;
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String getJobId() {
|
||||
|
@ -139,8 +139,8 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
calendarId = in.readString();
|
||||
after = in.readOptionalString();
|
||||
before = in.readOptionalString();
|
||||
start = in.readOptionalString();
|
||||
end = in.readOptionalString();
|
||||
jobId = in.readOptionalString();
|
||||
pageParams = new PageParams(in);
|
||||
}
|
||||
|
@ -149,15 +149,15 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeString(calendarId);
|
||||
out.writeOptionalString(after);
|
||||
out.writeOptionalString(before);
|
||||
out.writeOptionalString(start);
|
||||
out.writeOptionalString(end);
|
||||
out.writeOptionalString(jobId);
|
||||
pageParams.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(calendarId, after, before, pageParams, jobId);
|
||||
return Objects.hash(calendarId, start, end, pageParams, jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,8 +169,8 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
return false;
|
||||
}
|
||||
Request other = (Request) obj;
|
||||
return Objects.equals(calendarId, other.calendarId) && Objects.equals(after, other.after)
|
||||
&& Objects.equals(before, other.before) && Objects.equals(pageParams, other.pageParams)
|
||||
return Objects.equals(calendarId, other.calendarId) && Objects.equals(start, other.start)
|
||||
&& Objects.equals(end, other.end) && Objects.equals(pageParams, other.pageParams)
|
||||
&& Objects.equals(jobId, other.jobId);
|
||||
}
|
||||
|
||||
|
@ -178,11 +178,11 @@ public class GetCalendarEventsAction extends Action<GetCalendarEventsAction.Requ
|
|||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(Calendar.ID.getPreferredName(), calendarId);
|
||||
if (after != null) {
|
||||
builder.field(AFTER.getPreferredName(), after);
|
||||
if (start != null) {
|
||||
builder.field(START.getPreferredName(), start);
|
||||
}
|
||||
if (before != null) {
|
||||
builder.field(BEFORE.getPreferredName(), before);
|
||||
if (end != null) {
|
||||
builder.field(END.getPreferredName(), end);
|
||||
}
|
||||
if (jobId != null) {
|
||||
builder.field(Job.ID.getPreferredName(), jobId);
|
||||
|
|
|
@ -371,7 +371,7 @@ public class JobProvider {
|
|||
ScheduledEventsQueryBuilder scheduledEventsQueryBuilder = new ScheduledEventsQueryBuilder();
|
||||
Date lastestRecordTime = paramsBuilder.getDataCounts().getLatestRecordTimeStamp();
|
||||
if (lastestRecordTime != null) {
|
||||
scheduledEventsQueryBuilder.after(Long.toString(lastestRecordTime.getTime()));
|
||||
scheduledEventsQueryBuilder.start(Long.toString(lastestRecordTime.getTime()));
|
||||
}
|
||||
scheduledEventsForJob(jobId, job.getGroups(), scheduledEventsQueryBuilder, ActionListener.wrap(
|
||||
events -> {
|
||||
|
|
|
@ -28,21 +28,21 @@ public class ScheduledEventsQueryBuilder {
|
|||
private Integer size = DEFAULT_SIZE;
|
||||
|
||||
private List<String> calendarIds;
|
||||
private String after;
|
||||
private String before;
|
||||
private String start;
|
||||
private String end;
|
||||
|
||||
public ScheduledEventsQueryBuilder calendarIds(List<String> calendarIds) {
|
||||
this.calendarIds = calendarIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScheduledEventsQueryBuilder after(String after) {
|
||||
this.after = after;
|
||||
public ScheduledEventsQueryBuilder start(String start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScheduledEventsQueryBuilder before(String before) {
|
||||
this.before = before;
|
||||
public ScheduledEventsQueryBuilder end(String end) {
|
||||
this.end = end;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -69,15 +69,15 @@ public class ScheduledEventsQueryBuilder {
|
|||
public SearchSourceBuilder build() {
|
||||
List<QueryBuilder> queries = new ArrayList<>();
|
||||
|
||||
if (after != null) {
|
||||
RangeQueryBuilder afterQuery = QueryBuilders.rangeQuery(ScheduledEvent.END_TIME.getPreferredName());
|
||||
afterQuery.gt(after);
|
||||
queries.add(afterQuery);
|
||||
if (start != null) {
|
||||
RangeQueryBuilder startQuery = QueryBuilders.rangeQuery(ScheduledEvent.END_TIME.getPreferredName());
|
||||
startQuery.gt(start);
|
||||
queries.add(startQuery);
|
||||
}
|
||||
if (before != null) {
|
||||
RangeQueryBuilder beforeQuery = QueryBuilders.rangeQuery(ScheduledEvent.START_TIME.getPreferredName());
|
||||
beforeQuery.lt(before);
|
||||
queries.add(beforeQuery);
|
||||
if (end != null) {
|
||||
RangeQueryBuilder endQuery = QueryBuilders.rangeQuery(ScheduledEvent.START_TIME.getPreferredName());
|
||||
endQuery.lt(end);
|
||||
queries.add(endQuery);
|
||||
}
|
||||
|
||||
if (calendarIds != null && calendarIds.isEmpty() == false) {
|
||||
|
|
|
@ -50,8 +50,8 @@ public class TransportGetCalendarEventsAction extends HandledTransportAction<Get
|
|||
ActionListener<Boolean> calendarExistsListener = ActionListener.wrap(
|
||||
r -> {
|
||||
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder()
|
||||
.after(request.getAfter())
|
||||
.before(request.getBefore())
|
||||
.start(request.getStart())
|
||||
.end(request.getEnd())
|
||||
.from(request.getPageParams().getFrom())
|
||||
.size(request.getPageParams().getSize());
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ public class AutodetectProcessManager extends AbstractComponent {
|
|||
|
||||
if (updateParams.isUpdateScheduledEvents()) {
|
||||
Job job = jobManager.getJobOrThrowIfUnknown(jobTask.getJobId());
|
||||
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder().after(Long.toString(new Date().getTime()));
|
||||
ScheduledEventsQueryBuilder query = new ScheduledEventsQueryBuilder().start(Long.toString(new Date().getTime()));
|
||||
jobProvider.scheduledEventsForJob(jobTask.getJobId(), job.getGroups(), query, eventsListener);
|
||||
} else {
|
||||
eventsListener.onResponse(new QueryPage<>(Collections.emptyList(), 0, ScheduledEvent.RESULTS_FIELD));
|
||||
|
|
|
@ -44,8 +44,8 @@ public class RestGetCalendarEventsAction extends BaseRestHandler {
|
|||
}
|
||||
} else {
|
||||
request = new GetCalendarEventsAction.Request(calendarId);
|
||||
request.setAfter(restRequest.param(GetCalendarEventsAction.Request.AFTER.getPreferredName(), null));
|
||||
request.setBefore(restRequest.param(GetCalendarEventsAction.Request.BEFORE.getPreferredName(), null));
|
||||
request.setStart(restRequest.param(GetCalendarEventsAction.Request.START.getPreferredName(), null));
|
||||
request.setEnd(restRequest.param(GetCalendarEventsAction.Request.END.getPreferredName(), null));
|
||||
request.setJobId(restRequest.param(Job.ID.getPreferredName(), null));
|
||||
|
||||
if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
|
||||
|
|
|
@ -17,10 +17,10 @@ public class GetCalendarEventsActionRequestTests extends AbstractStreamableXCont
|
|||
String id = randomAlphaOfLengthBetween(1, 20);
|
||||
GetCalendarEventsAction.Request request = new GetCalendarEventsAction.Request(id);
|
||||
if (randomBoolean()) {
|
||||
request.setAfter(randomAlphaOfLengthBetween(1, 20));
|
||||
request.setStart(randomAlphaOfLengthBetween(1, 20));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setBefore(randomAlphaOfLengthBetween(1, 20));
|
||||
request.setEnd(randomAlphaOfLengthBetween(1, 20));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setJobId(randomAlphaOfLength(8));
|
||||
|
|
|
@ -322,9 +322,9 @@ public class JobProviderIT extends XPackSingleNodeTestCase {
|
|||
|
||||
// Test time filters
|
||||
// Lands halfway through the second event which should be returned
|
||||
query.after(Long.toString(now.plusDays(8).plusHours(1).toInstant().toEpochMilli()));
|
||||
query.start(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()));
|
||||
query.end(Long.toString(now.plusDays(12).plusHours(1).toInstant().toEpochMilli()));
|
||||
returnedEvents = getScheduledEventsForJob(jobA.getId(), Collections.emptyList(), query);
|
||||
assertEquals(2, returnedEvents.size());
|
||||
assertEquals(events.get(1), returnedEvents.get(0));
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
"type": "string",
|
||||
"description": "Get events for the job. When this option is used calendar_id must be '_all'"
|
||||
},
|
||||
"after": {
|
||||
"start": {
|
||||
"type": "string",
|
||||
"description": "Get events after this time"
|
||||
},
|
||||
"before": {
|
||||
"end": {
|
||||
"type": "date",
|
||||
"description": "Get events before this time"
|
||||
},
|
||||
|
|
|
@ -279,7 +279,7 @@
|
|||
- do:
|
||||
xpack.ml.get_calendar_events:
|
||||
calendar_id: "events"
|
||||
before: "2017-12-12T00:00:00Z"
|
||||
end: "2017-12-12T00:00:00Z"
|
||||
- length: { events: 2 }
|
||||
- match: { events.0.description: "event 1" }
|
||||
- match: { events.1.description: "event 2" }
|
||||
|
@ -287,7 +287,7 @@
|
|||
- do:
|
||||
xpack.ml.get_calendar_events:
|
||||
calendar_id: "events"
|
||||
after: "2017-12-05T03:00:00Z"
|
||||
start: "2017-12-05T03:00:00Z"
|
||||
- length: { events: 3 }
|
||||
- match: { events.0.description: "event 2" }
|
||||
- match: { events.1.description: "event 3" }
|
||||
|
@ -296,8 +296,8 @@
|
|||
- do:
|
||||
xpack.ml.get_calendar_events:
|
||||
calendar_id: "events"
|
||||
after: "2017-12-02T00:00:00Z"
|
||||
before: "2017-12-12T00:00:00Z"
|
||||
start: "2017-12-02T00:00:00Z"
|
||||
end: "2017-12-12T00:00:00Z"
|
||||
- length: { events: 1 }
|
||||
- match: { events.0.description: "event 2" }
|
||||
|
||||
|
@ -497,7 +497,7 @@
|
|||
- do:
|
||||
xpack.ml.get_calendar_events:
|
||||
calendar_id: _all
|
||||
after: "2018-01-01T00:00:00Z"
|
||||
start: "2018-01-01T00:00:00Z"
|
||||
job_id: cal-crud-job-with-events
|
||||
- match: { count: 2 }
|
||||
- length: { events: 2 }
|
||||
|
|
Loading…
Reference in New Issue