Skip to content

Commit d3d4122

Browse files
authored
Fix breaking change caused by opensearch core (#1187)
* Fix breaking change caused by opensearch core Signed-off-by: zane-neo <[email protected]> * Use builder.toString() to get a builder string value and format code Signed-off-by: zane-neo <[email protected]> --------- Signed-off-by: zane-neo <[email protected]>
1 parent 7bdc5e4 commit d3d4122

File tree

66 files changed

+129
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+129
-196
lines changed

common/src/main/java/org/opensearch/ml/common/MLModelGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import lombok.Builder;
1515
import lombok.Getter;
1616
import lombok.Setter;
17-
import org.opensearch.common.util.CollectionUtils;
1817
import org.opensearch.commons.authuser.User;
1918
import org.opensearch.core.common.io.stream.StreamInput;
2019
import org.opensearch.core.common.io.stream.StreamOutput;
20+
import org.opensearch.core.common.util.CollectionUtils;
2121
import org.opensearch.core.xcontent.ToXContentObject;
2222
import org.opensearch.core.xcontent.XContentBuilder;
2323
import org.opensearch.core.xcontent.XContentParser;

common/src/main/java/org/opensearch/ml/common/connector/Connector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.regex.Matcher;
2020
import java.util.regex.Pattern;
2121
import org.apache.commons.text.StringSubstitutor;
22-
import org.opensearch.common.Strings;
2322
import org.opensearch.core.common.io.stream.StreamInput;
2423
import org.opensearch.core.common.io.stream.StreamOutput;
2524
import org.opensearch.core.common.io.stream.Writeable;
@@ -93,7 +92,7 @@ static Connector fromStream(StreamInput in) throws IOException {
9392
}
9493

9594
static Connector createConnector(XContentBuilder builder, String connectorProtocol) throws IOException {
96-
String jsonStr = Strings.toString(builder);
95+
String jsonStr = builder.toString();
9796
return createConnector(jsonStr, connectorProtocol);
9897
}
9998

common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.opensearch.core.common.io.stream.StreamInput;
1111
import org.opensearch.core.common.io.stream.StreamOutput;
1212
import org.opensearch.core.common.io.stream.Writeable;
13-
import org.opensearch.common.util.CollectionUtils;
13+
import org.opensearch.core.common.util.CollectionUtils;
1414
import org.opensearch.core.xcontent.ToXContentObject;
1515
import org.opensearch.core.xcontent.XContentBuilder;
1616
import org.opensearch.core.xcontent.XContentParser;

common/src/test/java/org/opensearch/ml/common/TestHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.opensearch.ml.common;
77

8-
import org.opensearch.common.Strings;
98
import org.opensearch.core.common.bytes.BytesReference;
109
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
1110
import org.opensearch.common.xcontent.XContentFactory;
@@ -26,15 +25,15 @@ public static <T> void testParse(ToXContentObject obj, Function<XContentParser,
2625
}
2726

2827
public static <T> void testParse(ToXContentObject obj, Function<XContentParser, T> function, boolean wrapWithObject) throws IOException {
29-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
28+
XContentBuilder builder = XContentFactory.jsonBuilder();
3029
if (wrapWithObject) {
3130
builder.startObject();
3231
}
3332
obj.toXContent(builder, ToXContent.EMPTY_PARAMS);
3433
if (wrapWithObject) {
3534
builder.endObject();
3635
}
37-
String jsonStr = Strings.toString(builder);
36+
String jsonStr = builder.toString();
3837
testParseFromString(obj, jsonStr, function);
3938
}
4039

@@ -46,7 +45,7 @@ public static <T> void testParseFromString(ToXContentObject obj, String jsonStr,
4645
}
4746

4847
public static String contentObjectToString(ToXContentObject obj) throws IOException {
49-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
48+
XContentBuilder builder = XContentFactory.jsonBuilder();
5049
obj.toXContent(builder, ToXContent.EMPTY_PARAMS);
5150
return xContentBuilderToString(builder);
5251
}

common/src/test/java/org/opensearch/ml/common/dataframe/BooleanValueTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package org.opensearch.ml.common.dataframe;
77

88
import org.junit.Test;
9-
import org.opensearch.common.Strings;
109
import org.opensearch.common.xcontent.XContentFactory;
11-
import org.opensearch.common.xcontent.XContentType;
1210
import org.opensearch.core.xcontent.XContentBuilder;
1311

1412
import java.io.IOException;
@@ -29,11 +27,11 @@ public void booleanValue() {
2927
@Test
3028
public void testToXContent() throws IOException {
3129
BooleanValue value = new BooleanValue(true);
32-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
30+
XContentBuilder builder = XContentFactory.jsonBuilder();
3331
value.toXContent(builder);
3432

3533
assertNotNull(builder);
36-
String jsonStr = Strings.toString(builder);
34+
String jsonStr = builder.toString();
3735
assertEquals("{\"column_type\":\"BOOLEAN\",\"value\":true}", jsonStr);
3836
}
39-
}
37+
}

common/src/test/java/org/opensearch/ml/common/dataframe/ColumnMetaTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
import org.junit.Before;
99
import org.junit.Test;
10-
import org.opensearch.common.Strings;
1110
import org.opensearch.common.io.stream.BytesStreamOutput;
1211
import org.opensearch.common.xcontent.XContentFactory;
13-
import org.opensearch.common.xcontent.XContentType;
1412
import org.opensearch.core.xcontent.XContentBuilder;
1513
import org.opensearch.core.xcontent.XContentParser;
1614
import org.opensearch.ml.common.TestHelper;
@@ -51,11 +49,11 @@ public void writeToAndReadStream() throws IOException {
5149

5250
@Test
5351
public void testToXContent() throws IOException {
54-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
52+
XContentBuilder builder = XContentFactory.jsonBuilder();
5553
columnMeta.toXContent(builder);
5654

5755
assertNotNull(builder);
58-
String jsonStr = Strings.toString(builder);
56+
String jsonStr = builder.toString();
5957
assertEquals("{\"name\":\"columnMetaName\",\"column_type\":\"STRING\"}", jsonStr);
6058
}
6159

common/src/test/java/org/opensearch/ml/common/dataframe/DefaultDataFrameTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
import org.junit.Rule;
1515
import org.junit.Test;
1616
import org.junit.rules.ExpectedException;
17-
import org.opensearch.common.Strings;
1817
import org.opensearch.common.io.stream.BytesStreamOutput;
1918
import org.opensearch.core.common.io.stream.StreamInput;
2019
import org.opensearch.common.xcontent.XContentFactory;
21-
import org.opensearch.common.xcontent.XContentType;
2220
import org.opensearch.core.xcontent.XContentBuilder;
2321
import org.opensearch.core.xcontent.XContentParser;
2422
import org.opensearch.ml.common.TestHelper;
@@ -227,13 +225,13 @@ public void select_Exception_InvalidColumn(){
227225

228226
@Test
229227
public void testToXContent() throws IOException {
230-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
228+
XContentBuilder builder = XContentFactory.jsonBuilder();
231229
builder.startObject();
232230
defaultDataFrame.toXContent(builder);
233231
builder.endObject();
234232

235233
assertNotNull(builder);
236-
String jsonStr = Strings.toString(builder);
234+
String jsonStr = builder.toString();
237235
assertEquals("{\"column_metas\":[" +
238236
"{\"name\":\"c1\",\"column_type\":\"STRING\"}," +
239237
"{\"name\":\"c2\",\"column_type\":\"INTEGER\"}," +
@@ -274,4 +272,4 @@ public void testParse_WrongExtraField() throws IOException {
274272
"[{\"column_type\":\"INTEGER\",\"value\":2}]}]}";
275273
TestHelper.testParseFromString(dataFrame, jsonStr, function);
276274
}
277-
}
275+
}

common/src/test/java/org/opensearch/ml/common/dataframe/DoubleValueTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import java.io.IOException;
99

1010
import org.junit.Test;
11-
import org.opensearch.common.Strings;
1211
import org.opensearch.common.io.stream.BytesStreamOutput;
1312
import org.opensearch.common.xcontent.XContentFactory;
14-
import org.opensearch.common.xcontent.XContentType;
1513
import org.opensearch.core.xcontent.XContentBuilder;
1614

1715
import static org.junit.Assert.assertEquals;
@@ -47,11 +45,11 @@ public void writeTo() throws IOException {
4745
@Test
4846
public void testToXContent() throws IOException {
4947
DoubleValue doubleValue = new DoubleValue(5.0D);
50-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
48+
XContentBuilder builder = XContentFactory.jsonBuilder();
5149
doubleValue.toXContent(builder);
5250

5351
assertNotNull(builder);
54-
String jsonStr = Strings.toString(builder);
52+
String jsonStr = builder.toString();
5553
assertEquals("{\"column_type\":\"DOUBLE\",\"value\":5.0}", jsonStr);
5654
}
57-
}
55+
}

common/src/test/java/org/opensearch/ml/common/dataframe/FloatValueTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package org.opensearch.ml.common.dataframe;
77

88
import org.junit.Test;
9-
import org.opensearch.common.Strings;
109
import org.opensearch.common.xcontent.XContentFactory;
11-
import org.opensearch.common.xcontent.XContentType;
1210
import org.opensearch.core.xcontent.XContentBuilder;
1311

1412
import java.io.IOException;
@@ -30,11 +28,11 @@ public void floatValue() {
3028
@Test
3129
public void testToXContent() throws IOException {
3230
FloatValue floatValue = new FloatValue(2.1f);
33-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
31+
XContentBuilder builder = XContentFactory.jsonBuilder();
3432
floatValue.toXContent(builder);
3533

3634
assertNotNull(builder);
37-
String jsonStr = Strings.toString(builder);
35+
String jsonStr = builder.toString();
3836
assertEquals("{\"column_type\":\"FLOAT\",\"value\":2.1}", jsonStr);
3937
}
40-
}
38+
}

common/src/test/java/org/opensearch/ml/common/dataframe/IntValueTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
package org.opensearch.ml.common.dataframe;
77

88
import org.junit.Test;
9-
import org.opensearch.common.Strings;
109
import org.opensearch.common.xcontent.XContentFactory;
11-
import org.opensearch.common.xcontent.XContentType;
1210
import org.opensearch.core.xcontent.XContentBuilder;
1311

1412
import java.io.IOException;
@@ -29,11 +27,11 @@ public void intValue() {
2927
@Test
3028
public void testToXContent() throws IOException {
3129
IntValue intValue = new IntValue(2);
32-
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
30+
XContentBuilder builder = XContentFactory.jsonBuilder();
3331
intValue.toXContent(builder);
3432

3533
assertNotNull(builder);
36-
String jsonStr = Strings.toString(builder);
34+
String jsonStr = builder.toString();
3735
assertEquals("{\"column_type\":\"INTEGER\",\"value\":2}", jsonStr);
3836
}
39-
}
37+
}

0 commit comments

Comments
 (0)