Skip to content

Commit e6e41c0

Browse files
authored
[ML] removing old 7.x bwc serialization code (#80029)
This commit removes all the old serialization code to that was added when serializing to nodes with a version before 7.16 It also removes specific tests for those versions and some code only used by older versions.
1 parent d967c16 commit e6e41c0

32 files changed

+62
-506
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlMetadata.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,15 @@ public MlMetadata(StreamInput in) throws IOException {
162162
this.datafeeds = datafeeds;
163163
this.groupOrJobLookup = new GroupOrJobLookup(jobs.values());
164164
this.upgradeMode = in.readBoolean();
165-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
166-
this.resetMode = in.readBoolean();
167-
} else {
168-
this.resetMode = false;
169-
}
165+
this.resetMode = in.readBoolean();
170166
}
171167

172168
@Override
173169
public void writeTo(StreamOutput out) throws IOException {
174170
writeMap(jobs, out);
175171
writeMap(datafeeds, out);
176172
out.writeBoolean(upgradeMode);
177-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
178-
out.writeBoolean(resetMode);
179-
}
173+
out.writeBoolean(resetMode);
180174
}
181175

182176
private static <T extends Writeable> void writeMap(Map<String, T> map, StreamOutput out) throws IOException {
@@ -240,11 +234,7 @@ public MlMetadataDiff(StreamInput in) throws IOException {
240234
MlMetadataDiff::readDatafeedDiffFrom
241235
);
242236
upgradeMode = in.readBoolean();
243-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
244-
resetMode = in.readBoolean();
245-
} else {
246-
resetMode = false;
247-
}
237+
resetMode = in.readBoolean();
248238
}
249239

250240
/**
@@ -264,9 +254,7 @@ public void writeTo(StreamOutput out) throws IOException {
264254
jobs.writeTo(out);
265255
datafeeds.writeTo(out);
266256
out.writeBoolean(upgradeMode);
267-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
268-
out.writeBoolean(resetMode);
269-
}
257+
out.writeBoolean(resetMode);
270258
}
271259

272260
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDataFrameAnalyticsStatsAction.java

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.core.ml.action;
88

99
import org.elasticsearch.ElasticsearchException;
10-
import org.elasticsearch.Version;
1110
import org.elasticsearch.action.ActionRequestValidationException;
1211
import org.elasticsearch.action.ActionType;
1312
import org.elasticsearch.action.TaskOperationFailure;
@@ -200,26 +199,10 @@ public Stats(StreamInput in) throws IOException {
200199
id = in.readString();
201200
state = DataFrameAnalyticsState.fromStream(in);
202201
failureReason = in.readOptionalString();
203-
if (in.getVersion().before(Version.V_7_4_0)) {
204-
progress = readProgressFromLegacy(state, in);
205-
} else {
206-
progress = in.readList(PhaseProgress::new);
207-
}
208-
if (in.getVersion().onOrAfter(Version.V_7_7_0)) {
209-
dataCounts = new DataCounts(in);
210-
} else {
211-
dataCounts = null;
212-
}
213-
if (in.getVersion().onOrAfter(Version.V_7_7_0)) {
214-
memoryUsage = new MemoryUsage(in);
215-
} else {
216-
memoryUsage = null;
217-
}
218-
if (in.getVersion().onOrAfter(Version.V_7_7_0)) {
219-
analysisStats = in.readOptionalNamedWriteable(AnalysisStats.class);
220-
} else {
221-
analysisStats = null;
222-
}
202+
progress = in.readList(PhaseProgress::new);
203+
dataCounts = new DataCounts(in);
204+
memoryUsage = new MemoryUsage(in);
205+
analysisStats = in.readOptionalNamedWriteable(AnalysisStats.class);
223206
node = in.readOptionalWriteable(DiscoveryNode::new);
224207
assignmentExplanation = in.readOptionalString();
225208
}
@@ -355,50 +338,14 @@ public void writeTo(StreamOutput out) throws IOException {
355338
out.writeString(id);
356339
state.writeTo(out);
357340
out.writeOptionalString(failureReason);
358-
if (out.getVersion().before(Version.V_7_4_0)) {
359-
writeProgressToLegacy(out);
360-
} else {
361-
out.writeList(progress);
362-
}
363-
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
364-
dataCounts.writeTo(out);
365-
}
366-
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
367-
memoryUsage.writeTo(out);
368-
}
369-
if (out.getVersion().onOrAfter(Version.V_7_7_0)) {
370-
out.writeOptionalNamedWriteable(analysisStats);
371-
}
341+
out.writeList(progress);
342+
dataCounts.writeTo(out);
343+
memoryUsage.writeTo(out);
344+
out.writeOptionalNamedWriteable(analysisStats);
372345
out.writeOptionalWriteable(node);
373346
out.writeOptionalString(assignmentExplanation);
374347
}
375348

376-
private void writeProgressToLegacy(StreamOutput out) throws IOException {
377-
String targetPhase = null;
378-
switch (state) {
379-
case ANALYZING:
380-
targetPhase = "analyzing";
381-
break;
382-
case REINDEXING:
383-
targetPhase = "reindexing";
384-
break;
385-
case STARTING:
386-
case STARTED:
387-
case STOPPED:
388-
case STOPPING:
389-
default:
390-
break;
391-
}
392-
393-
Integer legacyProgressPercent = null;
394-
for (PhaseProgress phaseProgress : progress) {
395-
if (phaseProgress.getPhase().equals(targetPhase)) {
396-
legacyProgressPercent = phaseProgress.getProgressPercent();
397-
}
398-
}
399-
out.writeOptionalInt(legacyProgressPercent);
400-
}
401-
402349
@Override
403350
public int hashCode() {
404351
return Objects.hash(

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetTrainedModelsAction.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.core.ml.action;
88

9-
import org.elasticsearch.Version;
109
import org.elasticsearch.action.ActionType;
1110
import org.elasticsearch.common.io.stream.StreamInput;
1211
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -36,7 +35,7 @@ private GetTrainedModelsAction() {
3635
}
3736

3837
public static class Includes implements Writeable {
39-
static final String DEFINITION = "definition";
38+
public static final String DEFINITION = "definition";
4039
static final String TOTAL_FEATURE_IMPORTANCE = "total_feature_importance";
4140
static final String FEATURE_IMPORTANCE_BASELINE = "feature_importance_baseline";
4241
static final String HYPERPARAMETERS = "hyperparameters";
@@ -126,18 +125,6 @@ public static class Request extends AbstractGetResourcesRequest {
126125
private final Includes includes;
127126
private final List<String> tags;
128127

129-
@Deprecated
130-
public Request(String id, boolean includeModelDefinition, List<String> tags) {
131-
setResourceId(id);
132-
setAllowNoResources(true);
133-
this.tags = tags == null ? Collections.emptyList() : tags;
134-
if (includeModelDefinition) {
135-
this.includes = Includes.forModelDefinition();
136-
} else {
137-
this.includes = Includes.empty();
138-
}
139-
}
140-
141128
public Request(String id) {
142129
this(id, null, null);
143130
}
@@ -151,11 +138,7 @@ public Request(String id, List<String> tags, Set<String> includes) {
151138

152139
public Request(StreamInput in) throws IOException {
153140
super(in);
154-
if (in.getVersion().onOrAfter(Version.V_7_10_0)) {
155-
this.includes = new Includes(in);
156-
} else {
157-
this.includes = in.readBoolean() ? Includes.forModelDefinition() : Includes.empty();
158-
}
141+
this.includes = new Includes(in);
159142
this.tags = in.readStringList();
160143
}
161144

@@ -175,11 +158,7 @@ public Includes getIncludes() {
175158
@Override
176159
public void writeTo(StreamOutput out) throws IOException {
177160
super.writeTo(out);
178-
if (out.getVersion().onOrAfter(Version.V_7_10_0)) {
179-
this.includes.writeTo(out);
180-
} else {
181-
out.writeBoolean(this.includes.isIncludeModelDefinition());
182-
}
161+
this.includes.writeTo(out);
183162
out.writeStringCollection(tags);
184163
}
185164

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/InternalInferModelAction.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.core.ml.action;
88

9-
import org.elasticsearch.Version;
109
import org.elasticsearch.action.ActionRequest;
1110
import org.elasticsearch.action.ActionRequestValidationException;
1211
import org.elasticsearch.action.ActionResponse;
@@ -15,11 +14,7 @@
1514
import org.elasticsearch.common.io.stream.StreamOutput;
1615
import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig;
1716
import org.elasticsearch.xpack.core.ml.inference.results.InferenceResults;
18-
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ClassificationConfig;
19-
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.ClassificationConfigUpdate;
20-
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfig;
2117
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfigUpdate;
22-
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.RegressionConfig;
2318
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.RegressionConfigUpdate;
2419
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
2520

@@ -74,18 +69,7 @@ public Request(StreamInput in) throws IOException {
7469
super(in);
7570
this.modelId = in.readString();
7671
this.objectsToInfer = Collections.unmodifiableList(in.readList(StreamInput::readMap));
77-
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
78-
this.update = in.readNamedWriteable(InferenceConfigUpdate.class);
79-
} else {
80-
InferenceConfig oldConfig = in.readNamedWriteable(InferenceConfig.class);
81-
if (oldConfig instanceof RegressionConfig) {
82-
this.update = RegressionConfigUpdate.fromConfig((RegressionConfig) oldConfig);
83-
} else if (oldConfig instanceof ClassificationConfig) {
84-
this.update = ClassificationConfigUpdate.fromConfig((ClassificationConfig) oldConfig);
85-
} else {
86-
throw new IOException("Unexpected configuration type [" + oldConfig.getName() + "]");
87-
}
88-
}
72+
this.update = in.readNamedWriteable(InferenceConfigUpdate.class);
8973
this.previouslyLicensed = in.readBoolean();
9074
}
9175

@@ -115,11 +99,7 @@ public void writeTo(StreamOutput out) throws IOException {
11599
super.writeTo(out);
116100
out.writeString(modelId);
117101
out.writeCollection(objectsToInfer, StreamOutput::writeMap);
118-
if (out.getVersion().onOrAfter(Version.V_7_8_0)) {
119-
out.writeNamedWriteable(update);
120-
} else {
121-
out.writeNamedWriteable(update.toConfig());
122-
}
102+
out.writeNamedWriteable(update);
123103
out.writeBoolean(previouslyLicensed);
124104
}
125105

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotAction.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.elasticsearch.xpack.core.ml.action;
88

9-
import org.elasticsearch.Version;
109
import org.elasticsearch.action.ActionRequestValidationException;
1110
import org.elasticsearch.action.ActionResponse;
1211
import org.elasticsearch.action.ActionType;
@@ -74,11 +73,7 @@ public Request(StreamInput in) throws IOException {
7473
jobId = in.readString();
7574
snapshotId = in.readString();
7675
deleteInterveningResults = in.readBoolean();
77-
if (in.getVersion().onOrAfter(Version.V_7_11_0)) {
78-
force = in.readBoolean();
79-
} else {
80-
force = false;
81-
}
76+
force = in.readBoolean();
8277
}
8378

8479
public Request(String jobId, String snapshotId) {
@@ -121,9 +116,7 @@ public void writeTo(StreamOutput out) throws IOException {
121116
out.writeString(jobId);
122117
out.writeString(snapshotId);
123118
out.writeBoolean(deleteInterveningResults);
124-
if (out.getVersion().onOrAfter(Version.V_7_11_0)) {
125-
out.writeBoolean(force);
126-
}
119+
out.writeBoolean(force);
127120
}
128121

129122
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/DataFrameAnalyticsConfig.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -173,30 +173,17 @@ private DataFrameAnalyticsConfig(
173173

174174
public DataFrameAnalyticsConfig(StreamInput in) throws IOException {
175175
this.id = in.readString();
176-
if (in.getVersion().onOrAfter(Version.V_7_4_0)) {
177-
description = in.readOptionalString();
178-
} else {
179-
description = null;
180-
}
176+
this.description = in.readOptionalString();
181177
this.source = new DataFrameAnalyticsSource(in);
182178
this.dest = new DataFrameAnalyticsDest(in);
183179
this.analysis = in.readNamedWriteable(DataFrameAnalysis.class);
184180
this.analyzedFields = in.readOptionalWriteable(FetchSourceContext::new);
185181
this.modelMemoryLimit = in.readOptionalWriteable(ByteSizeValue::new);
186182
this.headers = Collections.unmodifiableMap(in.readMap(StreamInput::readString, StreamInput::readString));
187-
if (in.getVersion().onOrAfter(Version.V_7_3_0)) {
188-
createTime = in.readOptionalInstant();
189-
version = in.readBoolean() ? Version.readVersion(in) : null;
190-
} else {
191-
createTime = null;
192-
version = null;
193-
}
194-
if (in.getVersion().onOrAfter(Version.V_7_5_0)) {
195-
allowLazyStart = in.readBoolean();
196-
} else {
197-
allowLazyStart = false;
198-
}
199-
maxNumThreads = in.readVInt();
183+
this.createTime = in.readOptionalInstant();
184+
this.version = in.readBoolean() ? Version.readVersion(in) : null;
185+
this.allowLazyStart = in.readBoolean();
186+
this.maxNumThreads = in.readVInt();
200187
}
201188

202189
public String getId() {
@@ -291,27 +278,21 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
291278
@Override
292279
public void writeTo(StreamOutput out) throws IOException {
293280
out.writeString(id);
294-
if (out.getVersion().onOrAfter(Version.V_7_4_0)) {
295-
out.writeOptionalString(description);
296-
}
281+
out.writeOptionalString(description);
297282
source.writeTo(out);
298283
dest.writeTo(out);
299284
out.writeNamedWriteable(analysis);
300285
out.writeOptionalWriteable(analyzedFields);
301286
out.writeOptionalWriteable(modelMemoryLimit);
302287
out.writeMap(headers, StreamOutput::writeString, StreamOutput::writeString);
303-
if (out.getVersion().onOrAfter(Version.V_7_3_0)) {
304-
out.writeOptionalInstant(createTime);
305-
if (version != null) {
306-
out.writeBoolean(true);
307-
Version.writeVersion(version, out);
308-
} else {
309-
out.writeBoolean(false);
310-
}
311-
}
312-
if (out.getVersion().onOrAfter(Version.V_7_5_0)) {
313-
out.writeBoolean(allowLazyStart);
288+
out.writeOptionalInstant(createTime);
289+
if (version != null) {
290+
out.writeBoolean(true);
291+
Version.writeVersion(version, out);
292+
} else {
293+
out.writeBoolean(false);
314294
}
295+
out.writeBoolean(allowLazyStart);
315296
out.writeVInt(maxNumThreads);
316297
}
317298

0 commit comments

Comments
 (0)