Skip to content

Commit

Permalink
[ML] Remove unnecessary version constraints (#60314)
Browse files Browse the repository at this point in the history
[ML] Remove unnecessary version constraints

Remove checks on version numbers from the serialisation code that are no longer necessary in the 8.0.0 branch
  • Loading branch information
edsavage authored Jul 31, 2020
1 parent d6dd6bc commit 6bc1975
Show file tree
Hide file tree
Showing 38 changed files with 161 additions and 525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.xpack.core.XPackField;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -56,16 +55,8 @@ public MachineLearningFeatureSetUsage(StreamInput in) throws IOException {
super(in);
this.jobsUsage = in.readMap();
this.datafeedsUsage = in.readMap();
if (in.getVersion().onOrAfter(Version.V_7_4_0)) {
this.analyticsUsage = in.readMap();
} else {
this.analyticsUsage = Collections.emptyMap();
}
if (in.getVersion().onOrAfter(Version.V_7_6_0)) {
this.inferenceUsage = in.readMap();
} else {
this.inferenceUsage = Collections.emptyMap();
}
this.analyticsUsage = in.readMap();
this.inferenceUsage = in.readMap();
this.nodeCount = in.readInt();
}

Expand All @@ -79,12 +70,8 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(jobsUsage);
out.writeMap(datafeedsUsage);
if (out.getVersion().onOrAfter(Version.V_7_4_0)) {
out.writeMap(analyticsUsage);
}
if (out.getVersion().onOrAfter(Version.V_7_6_0)) {
out.writeMap(inferenceUsage);
}
out.writeMap(analyticsUsage);
out.writeMap(inferenceUsage);
out.writeInt(nodeCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
Expand Down Expand Up @@ -45,11 +44,7 @@ public static class Request extends AcknowledgedRequest<Request> {
public Request(StreamInput in) throws IOException {
super(in);
id = in.readString();
if (in.getVersion().onOrAfter(Version.V_7_6_0)) {
force = in.readBoolean();
} else {
force = false;
}
force = in.readBoolean();
}

public Request() {
Expand Down Expand Up @@ -97,9 +92,7 @@ public boolean equals(Object o) {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
if (out.getVersion().onOrAfter(Version.V_7_6_0)) {
out.writeBoolean(force);
}
out.writeBoolean(force);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -70,16 +69,9 @@ public Request(Float requestsPerSecond, TimeValue timeValue) {

public Request(StreamInput in) throws IOException {
super(in);
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
this.requestsPerSecond = in.readOptionalFloat();
this.timeout = in.readOptionalTimeValue();
} else {
this.requestsPerSecond = null;
this.timeout = null;
}
if (in.getVersion().onOrAfter(Version.V_7_9_0)) {
jobId = in.readOptionalString();
}
this.requestsPerSecond = in.readOptionalFloat();
this.timeout = in.readOptionalTimeValue();
this.jobId = in.readOptionalString();
}

public Float getRequestsPerSecond() {
Expand Down Expand Up @@ -137,13 +129,9 @@ public int hashCode() {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_7_8_0)) {
out.writeOptionalFloat(requestsPerSecond);
out.writeOptionalTimeValue(timeout);
}
if (out.getVersion().onOrAfter(Version.V_7_9_0)) {
out.writeOptionalString(jobId);
}
out.writeOptionalFloat(requestsPerSecond);
out.writeOptionalTimeValue(timeout);
out.writeOptionalString(jobId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -91,10 +90,8 @@ public Request() {}
public Request(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
if (in.getVersion().onOrAfter(Version.V_7_4_0)) {
if (in.readBoolean()) {
queryProvider = QueryProvider.fromStream(in);
}
if (in.readBoolean()) {
queryProvider = QueryProvider.fromStream(in);
}
evaluation = in.readNamedWriteable(Evaluation.class);
}
Expand Down Expand Up @@ -139,13 +136,11 @@ public ActionRequestValidationException validate() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
if (out.getVersion().onOrAfter(Version.V_7_4_0)) {
if (queryProvider != null) {
out.writeBoolean(true);
queryProvider.writeTo(out);
} else {
out.writeBoolean(false);
}
if (queryProvider != null) {
out.writeBoolean(true);
queryProvider.writeTo(out);
} else {
out.writeBoolean(false);
}
out.writeNamedWriteable(evaluation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -129,9 +128,7 @@ public Request() {
public Request(StreamInput in) throws IOException {
super(in);
linesToSample = in.readOptionalVInt();
if (in.getVersion().onOrAfter(Version.V_7_3_0)) {
lineMergeSizeLimit = in.readOptionalVInt();
}
lineMergeSizeLimit = in.readOptionalVInt();
timeout = in.readOptionalTimeValue();
charset = in.readOptionalString();
format = in.readBoolean() ? in.readEnum(FileStructure.Format.class) : null;
Expand Down Expand Up @@ -337,9 +334,7 @@ public ActionRequestValidationException validate() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalVInt(linesToSample);
if (out.getVersion().onOrAfter(Version.V_7_3_0)) {
out.writeOptionalVInt(lineMergeSizeLimit);
}
out.writeOptionalVInt(lineMergeSizeLimit);
out.writeOptionalTimeValue(timeout);
out.writeOptionalString(charset);
if (format == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.support.tasks.BaseTasksResponse;
import org.elasticsearch.common.ParseField;
Expand Down Expand Up @@ -83,19 +82,15 @@ public Request(StreamInput in) throws IOException {
super(in);
this.duration = in.readOptionalTimeValue();
this.expiresIn = in.readOptionalTimeValue();
if (in.getVersion().onOrAfter(Version.V_7_9_0)) {
this.maxModelMemory = in.readOptionalVLong();
}
this.maxModelMemory = in.readOptionalVLong();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalTimeValue(duration);
out.writeOptionalTimeValue(expiresIn);
if (out.getVersion().onOrAfter(Version.V_7_9_0)) {
out.writeOptionalVLong(maxModelMemory);
}
out.writeOptionalVLong(maxModelMemory);
}

public Request(String jobId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.Version.V_7_4_0;

public class GetDatafeedsStatsAction extends ActionType<GetDatafeedsStatsAction.Response> {

public static final GetDatafeedsStatsAction INSTANCE = new GetDatafeedsStatsAction();
Expand Down Expand Up @@ -132,11 +130,7 @@ public DatafeedStats(String datafeedId, DatafeedState datafeedState, @Nullable D
datafeedState = DatafeedState.fromStream(in);
node = in.readOptionalWriteable(DiscoveryNode::new);
assignmentExplanation = in.readOptionalString();
if (in.getVersion().onOrAfter(V_7_4_0)) {
timingStats = in.readOptionalWriteable(DatafeedTimingStats::new);
} else {
timingStats = null;
}
timingStats = in.readOptionalWriteable(DatafeedTimingStats::new);
}

public String getDatafeedId() {
Expand Down Expand Up @@ -199,9 +193,7 @@ public void writeTo(StreamOutput out) throws IOException {
datafeedState.writeTo(out);
out.writeOptionalWriteable(node);
out.writeOptionalString(assignmentExplanation);
if (out.getVersion().onOrAfter(V_7_4_0)) {
out.writeOptionalWriteable(timingStats);
}
out.writeOptionalWriteable(timingStats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.Version.V_7_3_0;

public class GetJobsStatsAction extends ActionType<GetJobsStatsAction.Response> {

public static final GetJobsStatsAction INSTANCE = new GetJobsStatsAction();
Expand Down Expand Up @@ -174,11 +172,7 @@ public JobStats(StreamInput in) throws IOException {
assignmentExplanation = in.readOptionalString();
openTime = in.readOptionalTimeValue();
forecastStats = in.readOptionalWriteable(ForecastStats::new);
if (in.getVersion().onOrAfter(V_7_3_0)) {
timingStats = in.readOptionalWriteable(TimingStats::new);
} else {
timingStats = null;
}
timingStats = in.readOptionalWriteable(TimingStats::new);
}

public String getJobId() {
Expand Down Expand Up @@ -277,9 +271,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(assignmentExplanation);
out.writeOptionalTimeValue(openTime);
out.writeOptionalWriteable(forecastStats);
if (out.getVersion().onOrAfter(V_7_3_0)) {
out.writeOptionalWriteable(timingStats);
}
out.writeOptionalWriteable(timingStats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -49,11 +48,7 @@ public Request(String id, boolean includeModelDefinition, List<String> tags) {
public Request(StreamInput in) throws IOException {
super(in);
this.includeModelDefinition = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_7_7_0)) {
this.tags = in.readStringList();
} else {
this.tags = Collections.emptyList();
}
this.tags = in.readStringList();
}

@Override
Expand All @@ -73,9 +68,7 @@ public List<String> getTags() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(includeModelDefinition);
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
out.writeStringCollection(tags);
}
out.writeStringCollection(tags);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.elasticsearch.xpack.core.ml.action;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -93,11 +92,7 @@ public TrainedModelStats(StreamInput in) throws IOException {
modelId = in.readString();
ingestStats = new IngestStats(in);
pipelineCount = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
this.inferenceStats = in.readOptionalWriteable(InferenceStats::new);
} else {
this.inferenceStats = null;
}
this.inferenceStats = in.readOptionalWriteable(InferenceStats::new);
}

public String getModelId() {
Expand Down Expand Up @@ -133,9 +128,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(modelId);
ingestStats.writeTo(out);
out.writeVInt(pipelineCount);
if (out.getVersion().onOrAfter(Version.V_7_8_0)) {
out.writeOptionalWriteable(this.inferenceStats);
}
out.writeOptionalWriteable(this.inferenceStats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,8 @@ private TaskParams(String id, String version, @Nullable List<PhaseProgress> prog
public TaskParams(StreamInput in) throws IOException {
this.id = in.readString();
this.version = Version.readVersion(in);
if (in.getVersion().onOrAfter(Version.V_7_5_0)) {
progressOnStart = in.readList(PhaseProgress::new);
} else {
progressOnStart = Collections.emptyList();
}
if (in.getVersion().onOrAfter(Version.V_7_5_0)) {
allowLazyStart = in.readBoolean();
} else {
allowLazyStart = false;
}
progressOnStart = in.readList(PhaseProgress::new);
allowLazyStart = in.readBoolean();
}

public String getId() {
Expand Down Expand Up @@ -222,12 +214,8 @@ public Version getMinimalSupportedVersion() {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
Version.writeVersion(version, out);
if (out.getVersion().onOrAfter(Version.V_7_5_0)) {
out.writeList(progressOnStart);
}
if (out.getVersion().onOrAfter(Version.V_7_5_0)) {
out.writeBoolean(allowLazyStart);
}
out.writeList(progressOnStart);
out.writeBoolean(allowLazyStart);
}

@Override
Expand Down
Loading

0 comments on commit 6bc1975

Please sign in to comment.