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) { protected final void doExecute(FlushJobAction.Request request, ActionListener<FlushJobAction.Response> listener) {
threadPool.executor(PrelertPlugin.THREAD_POOL_NAME).execute(() -> { threadPool.executor(PrelertPlugin.THREAD_POOL_NAME).execute(() -> {
try { try {
TimeRange timeRange = TimeRange.builder().startTime(request.getStart()).endTime(request.getEnd()).build(); InterimResultsParams.Builder paramsBuilder = InterimResultsParams.builder();
InterimResultsParams params = InterimResultsParams.builder() paramsBuilder.calcInterim(request.getCalcInterim());
.calcInterim(request.getCalcInterim()) if (request.getAdvanceTime() != null) {
.forTimeRange(timeRange) paramsBuilder.advanceTime(request.getAdvanceTime());
.advanceTime(request.getAdvanceTime()) }
.build(); TimeRange.Builder timeRangeBuilder = TimeRange.builder();
processManager.flushJob(request.getJobId(), params); 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)); listener.onResponse(new Response(true));
} catch (Exception e) { } catch (Exception e) {
listener.onFailure(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.ElasticsearchParseException;
import org.elasticsearch.xpack.prelert.job.messages.Messages; import org.elasticsearch.xpack.prelert.job.messages.Messages;
import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper;
import org.elasticsearch.xpack.prelert.utils.time.TimeUtils; import org.elasticsearch.xpack.prelert.utils.time.TimeUtils;
import java.util.Objects; import java.util.Objects;
@ -86,7 +87,7 @@ public class InterimResultsParams {
} }
public Builder advanceTime(String timestamp) { public Builder advanceTime(String timestamp) {
advanceTime = timestamp; advanceTime = ExceptionsHelper.requireNonNull(timestamp, "advance");
return this; return this;
} }

View File

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