[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.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.ml.MlMetadata;
import org.elasticsearch.xpack.ml.job.JobManager;
import org.elasticsearch.xpack.ml.job.config.Job;
import org.elasticsearch.xpack.ml.job.config.JobState;
import org.elasticsearch.xpack.ml.job.config.JobUpdate;
import org.elasticsearch.xpack.ml.MlMetadata;
import org.elasticsearch.xpack.persistent.PersistentTasks;
import java.io.IOException;
@ -94,17 +94,20 @@ public class UpdateJobAction extends Action<UpdateJobAction.Request, PutJobActio
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
jobId = in.readString();
update = new JobUpdate(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(jobId);
update.writeTo(out);
}
@Override
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);
return builder;
}
@ -114,12 +117,13 @@ public class UpdateJobAction extends Action<UpdateJobAction.Request, PutJobActio
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UpdateJobAction.Request request = (UpdateJobAction.Request) o;
return Objects.equals(update, request.update);
return Objects.equals(jobId, request.jobId) &&
Objects.equals(update, request.update);
}
@Override
public int hashCode() {
return Objects.hash(update);
return Objects.hash(jobId, update);
}
@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();
}
}