Skip to content

Commit

Permalink
Fix build with latest OpenSearch (for real this time)
Browse files Browse the repository at this point in the history
This is a follow-up to #971, where commit
2839bc2 only fixed _some_ but not _all_
of the CI errors (it allowed `./gradlew run` to pass but `./gradlew
build` was failing).

Fix the build errors when we run `./gradlew build`.

Signed-off-by: Romain Tartière <[email protected]>
  • Loading branch information
smortex committed Aug 9, 2023
1 parent 2839bc2 commit b209a2c
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.RestClient;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.XContentFactory;
Expand Down Expand Up @@ -327,7 +326,7 @@ public void updateClusterSettings(String settingKey, Object value) throws Except
.endObject()
.endObject();
Request request = new Request("PUT", "_cluster/settings");
request.setJsonEntity(Strings.toString(builder));
request.setJsonEntity(builder.toString());
Response response = client().performRequest(request);
assertEquals(RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
Thread.sleep(2000); // sleep some time to resolve flaky test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void disableResourceNotFoundFaultTolerence() throws IOException {
settingCommand.endObject();
settingCommand.endObject();
Request request = new Request("PUT", "/_cluster/settings");
request.setJsonEntity(org.opensearch.common.Strings.toString(settingCommand));
request.setJsonEntity(settingCommand.toString());

adminClient().performRequest(request);
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/org/opensearch/ad/model/EntityProfileTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.opensearch.ad.common.exception.JsonPathNotFoundException;
import org.opensearch.ad.constant.ADCommonName;
import org.opensearch.common.Strings;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.timeseries.AbstractTimeSeriesTest;
Expand All @@ -38,15 +37,15 @@ public void testToXContent() throws IOException, JsonPathNotFoundException {

XContentBuilder builder = jsonBuilder();
profile1.toXContent(builder, ToXContent.EMPTY_PARAMS);
String json = Strings.toString(builder);
String json = builder.toString();

assertEquals("INIT", JsonDeserializer.getTextValue(json, ADCommonName.STATE));

EntityProfile profile2 = new EntityProfile(null, -1, -1, null, null, EntityState.UNKNOWN);

builder = jsonBuilder();
profile2.toXContent(builder, ToXContent.EMPTY_PARAMS);
json = Strings.toString(builder);
json = builder.toString();

assertTrue(false == JsonDeserializer.hasChildNode(json, ADCommonName.STATE));
}
Expand All @@ -56,15 +55,15 @@ public void testToXContentTimeStampAboveZero() throws IOException, JsonPathNotFo

XContentBuilder builder = jsonBuilder();
profile1.toXContent(builder, ToXContent.EMPTY_PARAMS);
String json = Strings.toString(builder);
String json = builder.toString();

assertEquals("INIT", JsonDeserializer.getTextValue(json, ADCommonName.STATE));

EntityProfile profile2 = new EntityProfile(null, 1, 1, null, null, EntityState.UNKNOWN);

builder = jsonBuilder();
profile2.toXContent(builder, ToXContent.EMPTY_PARAMS);
json = Strings.toString(builder);
json = builder.toString();

assertTrue(false == JsonDeserializer.hasChildNode(json, ADCommonName.STATE));
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/opensearch/ad/model/ModelProfileTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.io.IOException;

import org.opensearch.common.Strings;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.timeseries.AbstractTimeSeriesTest;
Expand All @@ -33,14 +32,14 @@ public void testToXContent() throws IOException {
0
);
XContentBuilder builder = getBuilder(profile1);
String json = Strings.toString(builder);
String json = builder.toString();
assertTrue(JsonDeserializer.hasChildNode(json, CommonName.ENTITY_KEY));
assertFalse(JsonDeserializer.hasChildNode(json, CommonName.MODEL_SIZE_IN_BYTES));

ModelProfile profile2 = new ModelProfile(randomAlphaOfLength(5), null, 1);

builder = getBuilder(profile2);
json = Strings.toString(builder);
json = builder.toString();

assertFalse(JsonDeserializer.hasChildNode(json, CommonName.ENTITY_KEY));
assertTrue(JsonDeserializer.hasChildNode(json, CommonName.MODEL_SIZE_IN_BYTES));
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/org/opensearch/ad/transport/ADStatsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.ad.ml.ModelState;
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.transport.TransportAddress;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void testSimpleADStatsNodeResponse() throws IOException, JsonPathNotFound
// Test toXContent
XContentBuilder builder = jsonBuilder();
adStatsNodeResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
String json = Strings.toString(builder);
String json = builder.toString();

for (Map.Entry<String, Object> stat : stats.entrySet()) {
assertEquals("toXContent does not work", JsonDeserializer.getTextValue(json, stat.getKey()), stat.getValue());
Expand Down Expand Up @@ -164,7 +163,7 @@ public void testADStatsNodeResponseWithEntity() throws IOException, JsonPathNotF
// Test toXContent
XContentBuilder builder = jsonBuilder();
adStatsNodeResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
String json = Strings.toString(builder);
String json = builder.toString();

for (Map.Entry<String, Object> stat : stats.entrySet()) {
if (stat.getKey().equals(ModelState.LAST_CHECKPOINT_TIME_KEY) || stat.getKey().equals(ModelState.LAST_USED_TIME_KEY)) {
Expand Down Expand Up @@ -236,7 +235,7 @@ public void testADStatsNodesResponse() throws IOException, JsonPathNotFoundExcep
// Test toXContent
XContentBuilder builder = jsonBuilder();
adStatsNodesResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
String json = Strings.toString(builder);
String json = builder.toString();

logger.info("JSON: " + json);

Expand All @@ -260,7 +259,7 @@ public void testADStatsNodesResponse() throws IOException, JsonPathNotFoundExcep
ADStatsNodesResponse readRequest = new ADStatsNodesResponse(streamInput);

builder = jsonBuilder();
String readJson = Strings.toString(readRequest.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject());
String readJson = readRequest.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject().toString();
assertEquals("Serialization fails", readJson, json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
Expand Down Expand Up @@ -1016,7 +1015,7 @@ public void testJsonResponse() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
Function<JsonElement, FeatureData> function = (s) -> {
try {
String featureId = JsonDeserializer.getTextValue(s, FeatureData.FEATURE_ID_FIELD);
Expand Down Expand Up @@ -1065,7 +1064,7 @@ public void testJsonRequest() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getTextValue(json, ADCommonName.ID_JSON_KEY), request.getAdID());
assertEquals(JsonDeserializer.getLongValue(json, CommonName.START_JSON_KEY), request.getStart());
assertEquals(JsonDeserializer.getLongValue(json, CommonName.END_JSON_KEY), request.getEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -113,7 +112,7 @@ public void testNormal() throws IOException, JsonPathNotFoundException {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();

String json = Strings.toString(builder);
String json = builder.toString();
Function<JsonElement, String> function = (s) -> {
try {
return JsonDeserializer.getTextValue(s, CronNodeResponse.NODE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void testNormal() throws IOException, JsonPathNotFoundException {
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();

String json = Strings.toString(builder);
String json = builder.toString();
Function<JsonElement, String> function = (s) -> {
try {
return JsonDeserializer.getTextValue(s, CronNodeResponse.NODE_ID);
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/opensearch/ad/transport/DeleteTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
Expand Down Expand Up @@ -185,7 +184,7 @@ public <R extends ToXContent> void testJsonRequestTemplate(R request, Supplier<S
XContentBuilder builder = jsonBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getTextValue(json, ADCommonName.ID_JSON_KEY), requestSupplier.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.opensearch.ad.stats.ADStats;
import org.opensearch.ad.stats.suppliers.CounterSupplier;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
Expand Down Expand Up @@ -357,7 +356,7 @@ public void testJsonResponse() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getTextValue(json, ADCommonName.ID_JSON_KEY), detectorId);
assertEquals(JsonDeserializer.getLongValue(json, CommonName.START_JSON_KEY), start);
assertEquals(JsonDeserializer.getLongValue(json, CommonName.END_JSON_KEY), end);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/opensearch/ad/transport/ProfileTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.opensearch.ad.model.ModelProfileOnNode;
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.transport.TransportAddress;
Expand Down Expand Up @@ -153,7 +152,7 @@ public void testProfileNodeResponse() throws IOException, JsonPathNotFoundExcept
// Test toXContent
XContentBuilder builder = jsonBuilder();
profileNodeResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
String json = Strings.toString(builder);
String json = builder.toString();

for (Map.Entry<String, Long> profile : modelSizeMap1.entrySet()) {
assertEquals(
Expand Down Expand Up @@ -229,7 +228,7 @@ public void testProfileResponse() throws IOException, JsonPathNotFoundException
// Test toXContent
XContentBuilder builder = jsonBuilder();
profileResponse.toXContent(builder.startObject(), ToXContent.EMPTY_PARAMS).endObject();
String json = Strings.toString(builder);
String json = builder.toString();

logger.info("JSON: " + json);

Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/opensearch/ad/transport/RCFResultTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.opensearch.ad.stats.ADStats;
import org.opensearch.ad.stats.suppliers.CounterSupplier;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -233,7 +232,7 @@ public void testJsonResponse() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getDoubleValue(json, RCFResultResponse.RCF_SCORE_JSON_KEY), response.getRCFScore(), 0.001);
assertEquals(JsonDeserializer.getDoubleValue(json, RCFResultResponse.FOREST_SIZE_JSON_KEY), response.getForestSize(), 0.001);
assertTrue(
Expand Down Expand Up @@ -267,7 +266,7 @@ public void testJsonRequest() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getTextValue(json, ADCommonName.ID_JSON_KEY), request.getAdID());
assertArrayEquals(JsonDeserializer.getDoubleArrayValue(json, ADCommonName.FEATURE_JSON_KEY), request.getFeatures(), 0.001);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.ActionResponse;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -94,7 +93,7 @@ public void toXContentTest() throws IOException {
XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
stopDetectorResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
String jsonStr = Strings.toString(builder);
String jsonStr = builder.toString();
assertEquals("{\"success\":true}", jsonStr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.opensearch.ad.constant.ADCommonName;
import org.opensearch.ad.ml.ModelManager;
import org.opensearch.ad.ml.ThresholdingResult;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -117,7 +116,7 @@ public void testJsonResponse() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getDoubleValue(json, ADCommonName.ANOMALY_GRADE_JSON_KEY), response.getAnomalyGrade(), 0.001);
assertEquals(JsonDeserializer.getDoubleValue(json, ADCommonName.CONFIDENCE_JSON_KEY), response.getConfidence(), 0.001);
}
Expand Down Expand Up @@ -148,7 +147,7 @@ public void testJsonRequest() throws IOException, JsonPathNotFoundException {
XContentBuilder builder = jsonBuilder();
request.toXContent(builder, ToXContent.EMPTY_PARAMS);

String json = Strings.toString(builder);
String json = builder.toString();
assertEquals(JsonDeserializer.getTextValue(json, ADCommonName.ID_JSON_KEY), request.getAdID());
assertEquals(JsonDeserializer.getDoubleValue(json, ADCommonName.RCF_SCORE_JSON_KEY), request.getRCFScore(), 0.001);
}
Expand Down

0 comments on commit b209a2c

Please sign in to comment.