Skip to content

Commit

Permalink
remove v_7
Browse files Browse the repository at this point in the history
  • Loading branch information
JVerwolf committed Dec 5, 2024
1 parent b716a53 commit eea5e77
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public enum RestApiVersion {

V_9(9),

V_8(8),

@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) // remove all references to V_7 then delete this annotation
V_7(7);
V_8(8);

public final byte major;

Expand Down Expand Up @@ -54,23 +51,18 @@ public static Predicate<RestApiVersion> equalTo(RestApiVersion restApiVersion) {
return switch (restApiVersion) {
case V_9 -> r -> r.major == V_9.major;
case V_8 -> r -> r.major == V_8.major;
case V_7 -> r -> r.major == V_7.major;
};
}

public static Predicate<RestApiVersion> onOrAfter(RestApiVersion restApiVersion) {
return switch (restApiVersion) {
case V_9 -> r -> r.major >= V_9.major;
case V_8 -> r -> r.major >= V_8.major;
case V_7 -> r -> r.major >= V_7.major;
};
}

public static RestApiVersion forMajor(int major) {
switch (major) {
case 7 -> {
return V_7;
}
case 8 -> {
return V_8;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.ingest.ConfigurationUtils;
import org.elasticsearch.ingest.IngestDocument;
Expand Down Expand Up @@ -160,7 +160,8 @@ static Parsed parse(Map<String, Object> config, boolean verbose, IngestService i
return new Parsed(pipeline, ingestDocumentList, verbose);
}

@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT) // Unconditionally deprecate the _type field once V8 BWC support is removed
@UpdateForV9(owner = UpdateForV9.Owner.DATA_MANAGEMENT)
// Unconditionally deprecate the _type field once V7 BWC support is removed
private static List<IngestDocument> parseDocs(Map<String, Object> config, RestApiVersion restApiVersion) {
List<Map<String, Object>> docs = ConfigurationUtils.readList(null, null, config, Fields.DOCS);
if (docs.isEmpty()) {
Expand All @@ -177,12 +178,6 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config, RestAp
String index = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.INDEX.getFieldName(), "_index");
String id = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.ID.getFieldName(), "_id");
String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null, dataMap, Metadata.ROUTING.getFieldName());
if (restApiVersion != RestApiVersion.V_8 && dataMap.containsKey(Metadata.TYPE.getFieldName())) {
deprecationLogger.compatibleCritical(
"simulate_pipeline_with_types",
"[types removal] specifying _type in pipeline simulation requests is deprecated"
);
}
long version = Versions.MATCH_ANY;
if (dataMap.containsKey(Metadata.VERSION.getFieldName())) {
String versionValue = ConfigurationUtils.readOptionalStringOrLongProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ static ChunkedToXContentBuilder builder(ToXContent.Params params) {
*/
default Iterator<? extends ToXContent> toXContentChunked(RestApiVersion restApiVersion, ToXContent.Params params) {
return switch (restApiVersion) {
case V_7 -> throw new AssertionError("v7 API not supported");
case V_8 -> toXContentChunkedV8(params);
case V_9 -> toXContentChunked(params);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import static org.elasticsearch.ingest.IngestDocument.Metadata.IF_SEQ_NO;
import static org.elasticsearch.ingest.IngestDocument.Metadata.INDEX;
import static org.elasticsearch.ingest.IngestDocument.Metadata.ROUTING;
import static org.elasticsearch.ingest.IngestDocument.Metadata.TYPE;
import static org.elasticsearch.ingest.IngestDocument.Metadata.VERSION;
import static org.elasticsearch.ingest.IngestDocument.Metadata.VERSION_TYPE;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -269,99 +268,4 @@ public void testNotValidDocs() {
);
assertThat(e3.getMessage(), containsString("required property is missing"));
}

public void testIngestPipelineWithDocumentsWithType() throws Exception {
int numDocs = randomIntBetween(1, 10);

Map<String, Object> requestContent = new HashMap<>();
List<Map<String, Object>> docs = new ArrayList<>();
List<Map<String, Object>> expectedDocs = new ArrayList<>();
requestContent.put(Fields.DOCS, docs);
for (int i = 0; i < numDocs; i++) {
Map<String, Object> doc = new HashMap<>();
Map<String, Object> expectedDoc = new HashMap<>();
List<Metadata> fields = Arrays.asList(INDEX, TYPE, ID, ROUTING, VERSION, VERSION_TYPE);
for (Metadata field : fields) {
if (field == VERSION) {
Long value = randomLong();
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == VERSION_TYPE) {
String value = VersionType.toString(randomFrom(VersionType.INTERNAL, VersionType.EXTERNAL, VersionType.EXTERNAL_GTE));
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == TYPE) {
String value = randomAlphaOfLengthBetween(1, 10);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else {
if (randomBoolean()) {
String value = randomAlphaOfLengthBetween(1, 10);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else {
Integer value = randomIntBetween(1, 1000000);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), String.valueOf(value));
}
}
}
String fieldName = randomAlphaOfLengthBetween(1, 10);
String fieldValue = randomAlphaOfLengthBetween(1, 10);
doc.put(Fields.SOURCE, Collections.singletonMap(fieldName, fieldValue));
docs.add(doc);
expectedDoc.put(Fields.SOURCE, Collections.singletonMap(fieldName, fieldValue));
expectedDocs.add(expectedDoc);
}
Map<String, Object> pipelineConfig = new HashMap<>();
List<Map<String, Object>> processors = new ArrayList<>();
int numProcessors = randomIntBetween(1, 10);
for (int i = 0; i < numProcessors; i++) {
Map<String, Object> processorConfig = new HashMap<>();
List<Map<String, Object>> onFailureProcessors = new ArrayList<>();
int numOnFailureProcessors = randomIntBetween(0, 1);
for (int j = 0; j < numOnFailureProcessors; j++) {
onFailureProcessors.add(Collections.singletonMap("mock_processor", Collections.emptyMap()));
}
if (numOnFailureProcessors > 0) {
processorConfig.put("on_failure", onFailureProcessors);
}
processors.add(Collections.singletonMap("mock_processor", processorConfig));
}
pipelineConfig.put("processors", processors);
List<Map<String, Object>> onFailureProcessors = new ArrayList<>();
int numOnFailureProcessors = randomIntBetween(0, 1);
for (int i = 0; i < numOnFailureProcessors; i++) {
onFailureProcessors.add(Collections.singletonMap("mock_processor", Collections.emptyMap()));
}
if (numOnFailureProcessors > 0) {
pipelineConfig.put("on_failure", onFailureProcessors);
}
requestContent.put(Fields.PIPELINE, pipelineConfig);
SimulatePipelineRequest.Parsed actualRequest = SimulatePipelineRequest.parse(
requestContent,
false,
ingestService,
RestApiVersion.V_7
);
assertThat(actualRequest.verbose(), equalTo(false));
assertThat(actualRequest.documents().size(), equalTo(numDocs));
Iterator<Map<String, Object>> expectedDocsIterator = expectedDocs.iterator();
for (IngestDocument ingestDocument : actualRequest.documents()) {
Map<String, Object> expectedDocument = expectedDocsIterator.next();
org.elasticsearch.script.Metadata metadata = ingestDocument.getMetadata();
assertThat(metadata.get(INDEX.getFieldName()), equalTo(expectedDocument.get(INDEX.getFieldName())));
assertThat(metadata.get(ID.getFieldName()), equalTo(expectedDocument.get(ID.getFieldName())));
assertThat(metadata.get(ROUTING.getFieldName()), equalTo(expectedDocument.get(ROUTING.getFieldName())));
assertThat(metadata.get(VERSION.getFieldName()), equalTo(expectedDocument.get(VERSION.getFieldName())));
assertThat(metadata.get(VERSION_TYPE.getFieldName()), equalTo(expectedDocument.get(VERSION_TYPE.getFieldName())));
assertThat(ingestDocument.getSource(), equalTo(expectedDocument.get(Fields.SOURCE)));
}
assertThat(actualRequest.pipeline().getId(), equalTo(SIMULATED_PIPELINE_ID));
assertThat(actualRequest.pipeline().getDescription(), nullValue());
assertThat(actualRequest.pipeline().getProcessors().size(), equalTo(numProcessors));

assertCriticalWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.xcontent.ToXContentObject;
Expand Down Expand Up @@ -142,7 +141,7 @@ static boolean isEnterprise(String typeName) {
*/
public static final String LICENSE_VERSION_MODE = "license_version";
/**
* Set for {@link RestApiVersion#V_7} requests only
* Set for RestApiVersion#V_7 requests only
* XContent param name to map the "enterprise" license type to "platinum"
* for backwards compatibility with older clients
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

public final class MachineLearningField {

public static final String DEPRECATED_ALLOW_NO_JOBS_PARAM = "allow_no_jobs";
public static final String DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM = "allow_no_datafeeds";

public static final Setting<Boolean> AUTODETECT_PROCESS = Setting.boolSetting(
"xpack.ml.autodetect_process",
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
Expand All @@ -27,10 +25,6 @@
import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.core.RestApiVersion.equalTo;
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_JOBS_PARAM;

public class CloseJobAction extends ActionType<CloseJobAction.Response> {

public static final CloseJobAction INSTANCE = new CloseJobAction();
Expand All @@ -45,11 +39,7 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
public static final ParseField TIMEOUT = new ParseField("timeout");
public static final ParseField FORCE = new ParseField("force");

@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate forRestApiVersion
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate ref to RestApiVersion.V_7
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_JOBS_PARAM)
.forRestApiVersion(equalTo(RestApiVersion.V_7));
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);

static {
Expand All @@ -60,7 +50,6 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
);
PARSER.declareBoolean(Request::setForce, FORCE);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
}

public static Request parseRequest(String jobId, XContentParser parser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -62,6 +63,7 @@ private GetDatafeedsStatsAction() {
// serialized to older nodes where the transport action was a MasterNodeReadAction.
// TODO: Make this a simple request in a future version where there is no possibility
// of this request being serialized to another node.
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
public static class Request extends MasterNodeReadRequest<Request> {

public static final String ALLOW_NO_MATCH = "allow_no_match";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.time.DateMathParser;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
Expand All @@ -33,10 +31,6 @@
import java.util.Objects;
import java.util.function.LongSupplier;

import static org.elasticsearch.core.RestApiVersion.equalTo;
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_JOBS_PARAM;

/**
* <p>
* This action returns summarized bucket results over multiple jobs.
Expand Down Expand Up @@ -68,11 +62,7 @@ public static class Request extends ActionRequest implements ToXContentObject {
public static final ParseField EXCLUDE_INTERIM = new ParseField("exclude_interim");
public static final ParseField START = new ParseField("start");
public static final ParseField END = new ParseField("end");
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate forRestApiVersion
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate ref to RestApiVersion.V_7
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_JOBS_PARAM)
.forRestApiVersion(equalTo(RestApiVersion.V_7));
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");

private static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);

Expand All @@ -88,7 +78,6 @@ public static class Request extends ActionRequest implements ToXContentObject {
);
PARSER.declareString((request, endTime) -> request.setEnd(parseDateOrThrow(endTime, END, System::currentTimeMillis)), END);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
}

static long parseDateOrThrow(String date, ParseField paramName, LongSupplier now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ParseField;
Expand All @@ -29,10 +27,6 @@
import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.core.RestApiVersion.equalTo;
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM;

public class StopDatafeedAction extends ActionType<StopDatafeedAction.Response> {

public static final StopDatafeedAction INSTANCE = new StopDatafeedAction();
Expand All @@ -47,11 +41,7 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont

public static final ParseField TIMEOUT = new ParseField("timeout");
public static final ParseField FORCE = new ParseField("force");
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate forRestApiVersion
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // v7 REST API no longer exists: eliminate ref to RestApiVersion.V_7
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM)
.forRestApiVersion(equalTo(RestApiVersion.V_7));
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");

public static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
static {
Expand All @@ -62,7 +52,6 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
);
PARSER.declareBoolean(Request::setForce, FORCE);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
}

public static Request parseRequest(String datafeedId, XContentParser parser) {
Expand Down
Loading

0 comments on commit eea5e77

Please sign in to comment.