make optional flush parameter really optional

Original commit: elastic/x-pack-elasticsearch@6129023c49
This commit is contained in:
Martijn van Groningen 2016-12-09 10:24:16 +01:00
parent 372cb7c964
commit e067008a21
3 changed files with 19 additions and 10 deletions

View File

@ -240,13 +240,20 @@ public class FlushJobAction extends Action<FlushJobAction.Request, FlushJobActio
protected final void doExecute(FlushJobAction.Request request, ActionListener<FlushJobAction.Response> listener) {
threadPool.executor(PrelertPlugin.THREAD_POOL_NAME).execute(() -> {
try {
TimeRange timeRange = TimeRange.builder().startTime(request.getStart()).endTime(request.getEnd()).build();
InterimResultsParams params = InterimResultsParams.builder()
.calcInterim(request.getCalcInterim())
.forTimeRange(timeRange)
.advanceTime(request.getAdvanceTime())
.build();
processManager.flushJob(request.getJobId(), params);
InterimResultsParams.Builder paramsBuilder = InterimResultsParams.builder();
paramsBuilder.calcInterim(request.getCalcInterim());
if (request.getAdvanceTime() != null) {
paramsBuilder.advanceTime(request.getAdvanceTime());
}
TimeRange.Builder timeRangeBuilder = TimeRange.builder();
if (request.getStart() != null) {
timeRangeBuilder.startTime(request.getStart());
}
if (request.getEnd() != null) {
timeRangeBuilder.endTime(request.getEnd());
}
paramsBuilder.forTimeRange(timeRangeBuilder.build());
processManager.flushJob(request.getJobId(), paramsBuilder.build());
listener.onResponse(new Response(true));
} catch (Exception e) {
listener.onFailure(e);

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.prelert.job.process.autodetect.params;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.xpack.prelert.job.messages.Messages;
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
import org.elasticsearch.xpack.prelert.utils.time.TimeUtils;
import java.util.Objects;
@ -86,7 +87,7 @@ public class InterimResultsParams {
}
public Builder advanceTime(String timestamp) {
advanceTime = timestamp;
advanceTime = ExceptionsHelper.requireNonNull(timestamp, "advance");
return this;
}

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.prelert.job.process.autodetect.params;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.xpack.prelert.job.messages.Messages;
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
import org.elasticsearch.xpack.prelert.utils.time.TimeUtils;
import java.util.Objects;
@ -62,12 +63,12 @@ public class TimeRange {
}
public Builder startTime(String start) {
this.start = start;
this.start = ExceptionsHelper.requireNonNull(start, "start");
return this;
}
public Builder endTime(String end) {
this.end = end;
this.end = ExceptionsHelper.requireNonNull(end, "end");
return this;
}