Skip to content

Commit

Permalink
update bwc
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize committed Jul 11, 2023
1 parent 1df5fc9 commit 2b50552
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.action.admin.cluster.storedscripts;

import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.master.AcknowledgedRequest;
import org.opensearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -67,7 +68,11 @@ public PutStoredScriptRequest(StreamInput in) throws IOException {
super(in);
id = in.readOptionalString();
content = in.readBytesReference();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
context = in.readOptionalString();
source = new StoredScriptSource(in);
}
Expand Down Expand Up @@ -147,7 +152,11 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(id);
out.writeBytesReference(content);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
out.writeOptionalString(context);
source.writeTo(out);
}
Expand Down
13 changes: 11 additions & 2 deletions server/src/main/java/org/opensearch/action/index/IndexRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.Strings;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -158,7 +159,11 @@ public IndexRequest(@Nullable ShardId shardId, StreamInput in) throws IOExceptio
isRetry = in.readBoolean();
autoGeneratedTimestamp = in.readLong();
if (in.readBoolean()) {
contentType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
contentType = in.readMediaType();
} else {
contentType = in.readEnum(XContentType.class);
}
} else {
contentType = null;
}
Expand Down Expand Up @@ -665,7 +670,11 @@ private void writeBody(StreamOutput out) throws IOException {
out.writeLong(autoGeneratedTimestamp);
if (contentType != null) {
out.writeBoolean(true);
contentType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
contentType.writeTo(out);
} else {
out.writeEnum((XContentType) contentType);
}
} else {
out.writeBoolean(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@

package org.opensearch.action.ingest;

import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.master.AcknowledgedRequest;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -68,7 +70,11 @@ public PutPipelineRequest(StreamInput in) throws IOException {
super(in);
id = in.readString();
source = in.readBytesReference();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
}

PutPipelineRequest() {}
Expand All @@ -95,7 +101,11 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeBytesReference(source);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@

package org.opensearch.action.ingest;

import org.opensearch.Version;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -83,7 +85,11 @@ public SimulatePipelineRequest(BytesReference source, MediaType mediaType) {
id = in.readOptionalString();
verbose = in.readBoolean();
source = in.readBytesReference();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
}

@Override
Expand Down Expand Up @@ -121,7 +127,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalString(id);
out.writeBoolean(verbose);
out.writeBytesReference(source);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.action.search;

import org.opensearch.Version;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.support.master.AcknowledgedRequest;
import org.opensearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -46,7 +47,11 @@ public PutSearchPipelineRequest(StreamInput in) throws IOException {
super(in);
id = in.readString();
source = in.readBytesReference();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
}

@Override
Expand All @@ -71,7 +76,11 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeBytesReference(source);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.action.get.MultiGetRequest;
import org.opensearch.action.support.single.shard.SingleShardRequest;
import org.opensearch.common.Nullable;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.ParseField;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -185,7 +186,11 @@ public TermVectorsRequest() {}

if (in.readBoolean()) {
doc = in.readBytesReference();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
}
routing = in.readOptionalString();
preference = in.readOptionalString();
Expand Down Expand Up @@ -533,7 +538,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(doc != null);
if (doc != null) {
out.writeBytesReference(doc);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}
out.writeOptionalString(routing);
out.writeOptionalString(preference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
package org.opensearch.extensions.rest;

import org.opensearch.OpenSearchParseException;
import org.opensearch.Version;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaType;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentParser;
Expand Down Expand Up @@ -102,7 +104,11 @@ public ExtensionRestRequest(StreamInput in) throws IOException {
params = in.readMap(StreamInput::readString, StreamInput::readString);
headers = in.readMap(StreamInput::readString, StreamInput::readStringList);
if (in.readBoolean()) {
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
}
content = in.readBytesReference();
principalIdentifierToken = in.readString();
Expand All @@ -119,7 +125,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeMap(headers, StreamOutput::writeString, StreamOutput::writeStringCollection);
out.writeBoolean(mediaType != null);
if (mediaType != null) {
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}
out.writeBytesReference(content);
out.writeString(principalIdentifierToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ public Item(@Nullable String index, XContentBuilder doc) {
}
if (in.readBoolean()) {
doc = (BytesReference) in.readGenericValue();
mediaType = in.readMediaType();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType = in.readMediaType();
} else {
mediaType = in.readEnum(XContentType.class);
}
} else {
id = in.readString();
}
Expand All @@ -256,7 +260,11 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(doc != null);
if (doc != null) {
out.writeGenericValue(doc);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
} else {
out.writeString(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.ingest;

import org.opensearch.Version;
import org.opensearch.cluster.AbstractDiffable;
import org.opensearch.cluster.Diff;
import org.opensearch.core.ParseField;
Expand Down Expand Up @@ -137,7 +138,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

public static PipelineConfiguration readFrom(StreamInput in) throws IOException {
return new PipelineConfiguration(in.readString(), in.readBytesReference(), in.readMediaType());
return new PipelineConfiguration(
in.readString(),
in.readBytesReference(),
in.getVersion().onOrAfter(Version.V_3_0_0) ? in.readMediaType() : in.readEnum(XContentType.class)
);
}

public static Diff<PipelineConfiguration> readDiffFrom(StreamInput in) throws IOException {
Expand All @@ -153,7 +158,11 @@ public String toString() {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeBytesReference(config);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.search.pipeline;

import org.opensearch.Version;
import org.opensearch.cluster.AbstractDiffable;
import org.opensearch.cluster.Diff;
import org.opensearch.common.Strings;
Expand Down Expand Up @@ -116,7 +117,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

public static PipelineConfiguration readFrom(StreamInput in) throws IOException {
return new PipelineConfiguration(in.readString(), in.readBytesReference(), in.readMediaType());
return new PipelineConfiguration(
in.readString(),
in.readBytesReference(),
in.getVersion().onOrAfter(Version.V_3_0_0) ? in.readMediaType() : in.readEnum(XContentType.class)
);
}

public static Diff<PipelineConfiguration> readDiffFrom(StreamInput in) throws IOException {
Expand All @@ -132,7 +137,11 @@ public String toString() {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(id);
out.writeBytesReference(config);
mediaType.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
mediaType.writeTo(out);
} else {
out.writeEnum((XContentType) mediaType);
}
}

@Override
Expand Down

0 comments on commit 2b50552

Please sign in to comment.