[ML] Also serialize the job id in a update job request.

Relates to elastic/x-pack-elasticsearch#787 and elastic/x-pack-elasticsearch#799

Original commit: elastic/x-pack-elasticsearch@fc64d25bcb
This commit is contained in:
Martijn van Groningen 2017-03-22 18:09:10 +01:00
parent 6ddc626c17
commit d779bf66a5
2 changed files with 36 additions and 3 deletions

View File

@ -30,11 +30,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.MlMetadata;
import org.elasticsearch.xpack.ml.job.JobManager; import org.elasticsearch.xpack.ml.job.JobManager;
import org.elasticsearch.xpack.ml.job.config.Job; import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.config.JobState; import org.elasticsearch.xpack.ml.job.config.JobState;
import org.elasticsearch.xpack.ml.job.config.JobUpdate; import org.elasticsearch.xpack.ml.job.config.JobUpdate;
import org.elasticsearch.xpack.ml.MlMetadata;
import org.elasticsearch.xpack.persistent.PersistentTasks; import org.elasticsearch.xpack.persistent.PersistentTasks;
import java.io.IOException; import java.io.IOException;
@ -94,17 +94,20 @@ public class UpdateJobAction extends Action<UpdateJobAction.Request, PutJobActio
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
jobId = in.readString();
update = new JobUpdate(in); update = new JobUpdate(in);
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeString(jobId);
update.writeTo(out); update.writeTo(out);
} }
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
// only serialize the update, as the job id is specified as part of the url
update.toXContent(builder, params); update.toXContent(builder, params);
return builder; return builder;
} }
@ -114,12 +117,13 @@ public class UpdateJobAction extends Action<UpdateJobAction.Request, PutJobActio
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
UpdateJobAction.Request request = (UpdateJobAction.Request) o; UpdateJobAction.Request request = (UpdateJobAction.Request) o;
return Objects.equals(update, request.update); return Objects.equals(jobId, request.jobId) &&
Objects.equals(update, request.update);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(update); return Objects.hash(jobId, update);
} }
@Override @Override

View File

@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ml.action;
import org.elasticsearch.xpack.ml.job.config.AnalysisLimits;
import org.elasticsearch.xpack.ml.job.config.JobUpdate;
import org.elasticsearch.xpack.ml.support.AbstractStreamableTestCase;
public class UpdateJobActionRequestTests
extends AbstractStreamableTestCase<UpdateJobAction.Request> {
@Override
protected UpdateJobAction.Request createTestInstance() {
String jobId = randomAsciiOfLength(10);
// no need to randomize JobUpdate this is already tested in: JobUpdateTests
JobUpdate.Builder jobUpdate = new JobUpdate.Builder();
jobUpdate.setAnalysisLimits(new AnalysisLimits(100L, 100L));
return new UpdateJobAction.Request(jobId, jobUpdate.build());
}
@Override
protected UpdateJobAction.Request createBlankInstance() {
return new UpdateJobAction.Request();
}
}