Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PluginInfo bwc for opensearch_version field #12537

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix PluginInfo bwc for opensearch_version field
Signed-off-by: Abhilasha Seth <[email protected]>
  • Loading branch information
abseth-amzn committed Mar 5, 2024
commit 225de7ba59873fa1ad4007c954811fa7920e9470
Original file line number Diff line number Diff line change
@@ -491,7 +491,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
{
builder.field("name", name);
builder.field("version", version);
builder.field("opensearch_version", opensearchVersionRanges);
builder.field("opensearch_version", getOpenSearchVersionRangesString());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the super quick fix. Should we do an additional pass at all places of usage to confirm they are bwc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All callers that require a serialized form of PluginInfo will use one of the following:

  1. writeTo method - already updated to be bwc
  2. toXContent method - updated with this PR
  3. toString method - already updated to be bwc

builder.field("java_version", javaVersion);
builder.field("description", description);
builder.field("classname", classname);
Original file line number Diff line number Diff line change
@@ -37,7 +37,10 @@
import org.opensearch.Version;
import org.opensearch.action.admin.cluster.node.info.PluginsAndModules;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.common.io.stream.ByteBufferStreamInput;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.semver.SemverRange;
import org.opensearch.test.OpenSearchTestCase;

@@ -367,6 +370,31 @@ public void testSerialize() throws Exception {
assertThat(info2.toString(), equalTo(info.toString()));
}

public void testToXContent() throws Exception {
PluginInfo info = new PluginInfo(
"fake",
"foo",
"dummy",
Version.CURRENT,
"1.8",
"dummyClass",
"folder",
Collections.emptyList(),
false
);
XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint();
String prettyPrint = info.toXContent(builder, ToXContent.EMPTY_PARAMS).prettyPrint().toString();
assertTrue(prettyPrint.contains("\"name\" : \"fake\""));
assertTrue(prettyPrint.contains("\"version\" : \"dummy\""));
assertTrue(prettyPrint.contains("\"opensearch_version\" : \"" + Version.CURRENT));
assertTrue(prettyPrint.contains("\"java_version\" : \"1.8\""));
assertTrue(prettyPrint.contains("\"description\" : \"foo\""));
assertTrue(prettyPrint.contains("\"classname\" : \"dummyClass\""));
assertTrue(prettyPrint.contains("\"custom_foldername\" : \"folder\""));
assertTrue(prettyPrint.contains("\"extended_plugins\" : [ ]"));
assertTrue(prettyPrint.contains("\"has_native_controller\" : false"));
}

public void testPluginListSorted() {
List<PluginInfo> plugins = new ArrayList<>();
plugins.add(new PluginInfo("c", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass", Collections.emptyList(), randomBoolean()));