[ML] Rename id to forecast_id in forecast API response (elastic/x-pack-elasticsearch#3074)

Original commit: elastic/x-pack-elasticsearch@c05d9fc602
This commit is contained in:
Dimitris Athanasiou 2017-11-21 13:57:41 +00:00 committed by GitHub
parent 83ca6e8064
commit e71b5639de
3 changed files with 33 additions and 23 deletions

View File

@ -29,6 +29,7 @@ import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager; import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager;
import org.elasticsearch.xpack.ml.job.process.autodetect.params.ForecastParams; import org.elasticsearch.xpack.ml.job.process.autodetect.params.ForecastParams;
import org.elasticsearch.xpack.ml.job.results.Forecast;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
@ -157,56 +158,64 @@ public class ForecastJobAction extends Action<ForecastJobAction.Request, Forecas
public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject { public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject {
private boolean acknowledged; private boolean acknowledged;
private long id; private long forecastId;
Response() { Response() {
super(null, null); super(null, null);
} }
Response(boolean acknowledged, long id) { Response(boolean acknowledged, long forecastId) {
super(null, null); super(null, null);
this.acknowledged = acknowledged; this.acknowledged = acknowledged;
this.id = id; this.forecastId = forecastId;
} }
public boolean isacknowledged() { public boolean isAcknowledged() {
return acknowledged; return acknowledged;
} }
public long getForecastId() {
return forecastId;
}
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
acknowledged = in.readBoolean(); acknowledged = in.readBoolean();
forecastId = in.readLong();
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeBoolean(acknowledged); out.writeBoolean(acknowledged);
out.writeLong(forecastId);
} }
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();
builder.field("acknowledged", acknowledged); builder.field("acknowledged", acknowledged);
builder.field("id", id); builder.field(Forecast.FORECAST_ID.getPreferredName(), forecastId);
builder.endObject(); builder.endObject();
return builder; return builder;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object obj) {
if (this == o) if (obj == null) {
return true;
if (o == null || getClass() != o.getClass())
return false; return false;
Response response = (Response) o; }
return acknowledged == response.acknowledged; if (getClass() != obj.getClass()) {
return false;
}
Response other = (Response) obj;
return this.acknowledged == other.acknowledged && this.forecastId == other.forecastId;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(acknowledged); return Objects.hash(acknowledged, forecastId);
} }
} }
@ -219,8 +228,7 @@ public class ForecastJobAction extends Action<ForecastJobAction.Request, Forecas
super(settings, ForecastJobAction.NAME, threadPool, clusterService, transportService, actionFilters, super(settings, ForecastJobAction.NAME, threadPool, clusterService, transportService, actionFilters,
indexNameExpressionResolver, ForecastJobAction.Request::new, ForecastJobAction.Response::new, ThreadPool.Names.SAME, indexNameExpressionResolver, ForecastJobAction.Request::new, ForecastJobAction.Response::new, ThreadPool.Names.SAME,
processManager); processManager);
// ThreadPool.Names.SAME, because operations is executed by // ThreadPool.Names.SAME, because operations is executed by autodetect worker thread
// autodetect worker thread
} }
@Override @Override
@ -243,7 +251,7 @@ public class ForecastJobAction extends Action<ForecastJobAction.Request, Forecas
ForecastParams params = paramsBuilder.build(); ForecastParams params = paramsBuilder.build();
processManager.forecastJob(task, params, e -> { processManager.forecastJob(task, params, e -> {
if (e == null) { if (e == null) {
listener.onResponse(new Response(true, params.getId())); listener.onResponse(new Response(true, params.getForecastId()));
} else { } else {
listener.onFailure(e); listener.onFailure(e);
} }

View File

@ -18,10 +18,10 @@ public class ForecastParams {
private final long endTime; private final long endTime;
private final long duration; private final long duration;
private final long id; private final long forecastId;
private ForecastParams(long id, long endTime, long duration) { private ForecastParams(long forecastId, long endTime, long duration) {
this.id = id; this.forecastId = forecastId;
this.endTime = endTime; this.endTime = endTime;
this.duration = duration; this.duration = duration;
} }
@ -47,13 +47,13 @@ public class ForecastParams {
* *
* @return The forecast Id * @return The forecast Id
*/ */
public long getId() { public long getForecastId() {
return id; return forecastId;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, endTime, duration); return Objects.hash(forecastId, endTime, duration);
} }
@Override @Override
@ -65,7 +65,9 @@ public class ForecastParams {
return false; return false;
} }
ForecastParams other = (ForecastParams) obj; ForecastParams other = (ForecastParams) obj;
return Objects.equals(id, other.id) && Objects.equals(endTime, other.endTime) && Objects.equals(duration, other.duration); return Objects.equals(forecastId, other.forecastId)
&& Objects.equals(endTime, other.endTime)
&& Objects.equals(duration, other.duration);
} }
public static Builder builder() { public static Builder builder() {

View File

@ -153,7 +153,7 @@ public class ControlMsgToProcessWriter {
public void writeForecastMessage(ForecastParams params) throws IOException { public void writeForecastMessage(ForecastParams params) throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder() XContentBuilder builder = XContentFactory.jsonBuilder()
.startObject() .startObject()
.field("forecast_id", params.getId()); .field("forecast_id", params.getForecastId());
if (params.getEndTime() != 0) { if (params.getEndTime() != 0) {
builder.field("end_time", params.getEndTime()); builder.field("end_time", params.getEndTime());