From ad9d65cfa504bca36e819556e28d014250248e60 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 3 Jan 2017 10:13:39 +0000 Subject: [PATCH] Fix compilation after upstream Elasticsearch changes (elastic/elasticsearch#621) The Elasticsearch change that caused the breakage was https://github.com/elastic/elasticsearch/commit/73625f62911d04f3c81f598430e41191d62fcc27 Original commit: elastic/x-pack-elasticsearch@01b82a79d452ce9fdbe32b5380d20cddb828398b --- .../xpack/prelert/PrelertPlugin.java | 4 --- .../elasticsearch/xpack/prelert/job/Job.java | 6 ---- .../prelert/job/metadata/Allocation.java | 5 ---- .../prelert/job/metadata/PrelertMetadata.java | 29 ++++--------------- .../xpack/prelert/scheduler/Scheduler.java | 5 ---- .../job/metadata/PrelertMetadataTests.java | 2 +- 6 files changed, 7 insertions(+), 44 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/PrelertPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/PrelertPlugin.java index f96eb319a5d..165f78b586d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/PrelertPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/PrelertPlugin.java @@ -137,10 +137,6 @@ public class PrelertPlugin extends Plugin implements ActionPlugin { private final ParseFieldMatcherSupplier parseFieldMatcherSupplier; - static { - MetaData.registerPrototype(PrelertMetadata.TYPE, PrelertMetadata.PROTO); - } - public PrelertPlugin(Settings settings) { this.settings = settings; this.env = new Environment(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java index 2b12806fd7b..678589b9ae9 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java @@ -23,7 +23,6 @@ import org.elasticsearch.xpack.prelert.job.messages.Messages; import org.elasticsearch.xpack.prelert.job.transform.TransformConfig; import org.elasticsearch.xpack.prelert.job.transform.TransformConfigs; import org.elasticsearch.xpack.prelert.job.transform.verification.TransformConfigsVerifier; -import org.elasticsearch.xpack.prelert.utils.ExceptionsHelper; import org.elasticsearch.xpack.prelert.utils.PrelertStrings; import org.elasticsearch.xpack.prelert.utils.time.TimeUtils; @@ -196,11 +195,6 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent indexName = in.readString(); } - @Override - public Job readFrom(StreamInput in) throws IOException { - return new Job(in); - } - /** * Return the Job Id. * diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/Allocation.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/Allocation.java index dfa851e16ea..b92c8a360cd 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/Allocation.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/Allocation.java @@ -87,11 +87,6 @@ public class Allocation extends AbstractDiffable implements ToXConte return statusReason; } - @Override - public Allocation readFrom(StreamInput in) throws IOException { - return new Allocation(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(nodeId); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java index bec09ef5d60..07190ad818e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadata.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.DiffableUtils; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -20,7 +19,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.xpack.prelert.job.Job; import org.elasticsearch.xpack.prelert.job.JobStatus; @@ -89,15 +87,10 @@ public class PrelertMetadata implements MetaData.Custom { } @Override - public String type() { + public String getWriteableName() { return TYPE; } - @Override - public MetaData.Custom fromXContent(XContentParser parser) throws IOException { - return PRELERT_METADATA_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT).build(); - } - @Override public EnumSet context() { // NORELEASE: Also include SNAPSHOT, but then we need to split the allocations from here and add them @@ -110,29 +103,25 @@ public class PrelertMetadata implements MetaData.Custom { return new PrelertMetadataDiff((PrelertMetadata) previousState, this); } - @Override - public Diff readDiffFrom(StreamInput in) throws IOException { - return new PrelertMetadataDiff(in); - } - - @Override - public MetaData.Custom readFrom(StreamInput in) throws IOException { + public PrelertMetadata(StreamInput in) throws IOException { int size = in.readVInt(); TreeMap jobs = new TreeMap<>(); for (int i = 0; i < size; i++) { jobs.put(in.readString(), new Job(in)); } + this.jobs = jobs; size = in.readVInt(); TreeMap allocations = new TreeMap<>(); for (int i = 0; i < size; i++) { - allocations.put(in.readString(), Allocation.PROTO.readFrom(in)); + allocations.put(in.readString(), new Allocation(in)); } + this.allocations = allocations; size = in.readVInt(); TreeMap schedulers = new TreeMap<>(); for (int i = 0; i < size; i++) { schedulers.put(in.readString(), new Scheduler(in)); } - return new PrelertMetadata(jobs, allocations, schedulers); + this.schedulers = schedulers; } @Override @@ -179,12 +168,6 @@ public class PrelertMetadata implements MetaData.Custom { this.schedulers = DiffableUtils.diff(before.schedulers, after.schedulers, DiffableUtils.getStringKeySerializer()); } - PrelertMetadataDiff(StreamInput in) throws IOException { - jobs = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), Job.PROTO); - allocations = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), Allocation.PROTO); - schedulers = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), Scheduler.PROTO); - } - @Override public MetaData.Custom apply(MetaData.Custom part) { TreeMap newJobs = new TreeMap<>(jobs.apply(((PrelertMetadata) part).jobs)); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/scheduler/Scheduler.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/scheduler/Scheduler.java index 1121417ba79..d4e3e1d130d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/scheduler/Scheduler.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/scheduler/Scheduler.java @@ -66,11 +66,6 @@ public class Scheduler extends AbstractDiffable implements ToXContent return status; } - @Override - public Scheduler readFrom(StreamInput in) throws IOException { - return new Scheduler(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { config.writeTo(out); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadataTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadataTests.java index 322a01bdf2b..fb230d6984f 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadataTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/metadata/PrelertMetadataTests.java @@ -68,7 +68,7 @@ public class PrelertMetadataTests extends AbstractSerializingTestCase instanceReader() { - return in -> (PrelertMetadata) PrelertMetadata.PROTO.readFrom(in); + return in -> new PrelertMetadata(in); } @Override