From b209a2c3c0ca7b69df53f3dd40ec288ea8f294e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 8 Aug 2023 14:23:18 -1000 Subject: [PATCH] Fix build with latest OpenSearch (for real this time) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow-up to #971, where commit 2839bc2c6f470639b68901086c80cb2152d96558 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 --- .../org/opensearch/ad/AnomalyDetectorRestTestCase.java | 3 +-- .../org/opensearch/ad/e2e/AbstractSyntheticDataTest.java | 2 +- .../java/org/opensearch/ad/model/EntityProfileTests.java | 9 ++++----- .../java/org/opensearch/ad/model/ModelProfileTests.java | 5 ++--- .../java/org/opensearch/ad/transport/ADStatsTests.java | 9 ++++----- .../org/opensearch/ad/transport/AnomalyResultTests.java | 5 ++--- .../ad/transport/CronTransportActionTests.java | 3 +-- .../ad/transport/DeleteModelTransportActionTests.java | 3 +-- .../java/org/opensearch/ad/transport/DeleteTests.java | 3 +-- .../ad/transport/EntityResultTransportActionTests.java | 3 +-- .../java/org/opensearch/ad/transport/ProfileTests.java | 5 ++--- .../java/org/opensearch/ad/transport/RCFResultTests.java | 5 ++--- .../opensearch/ad/transport/StopDetectorActionTests.java | 3 +-- .../opensearch/ad/transport/ThresholdResultTests.java | 5 ++--- 14 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java b/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java index 288c0e3dc..020281ac6 100644 --- a/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java +++ b/src/test/java/org/opensearch/ad/AnomalyDetectorRestTestCase.java @@ -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; @@ -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 diff --git a/src/test/java/org/opensearch/ad/e2e/AbstractSyntheticDataTest.java b/src/test/java/org/opensearch/ad/e2e/AbstractSyntheticDataTest.java index 39344a0b6..4330118b6 100644 --- a/src/test/java/org/opensearch/ad/e2e/AbstractSyntheticDataTest.java +++ b/src/test/java/org/opensearch/ad/e2e/AbstractSyntheticDataTest.java @@ -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); } diff --git a/src/test/java/org/opensearch/ad/model/EntityProfileTests.java b/src/test/java/org/opensearch/ad/model/EntityProfileTests.java index caa45a2d8..18e179145 100644 --- a/src/test/java/org/opensearch/ad/model/EntityProfileTests.java +++ b/src/test/java/org/opensearch/ad/model/EntityProfileTests.java @@ -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; @@ -38,7 +37,7 @@ 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)); @@ -46,7 +45,7 @@ public void testToXContent() throws IOException, JsonPathNotFoundException { builder = jsonBuilder(); profile2.toXContent(builder, ToXContent.EMPTY_PARAMS); - json = Strings.toString(builder); + json = builder.toString(); assertTrue(false == JsonDeserializer.hasChildNode(json, ADCommonName.STATE)); } @@ -56,7 +55,7 @@ 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)); @@ -64,7 +63,7 @@ public void testToXContentTimeStampAboveZero() throws IOException, JsonPathNotFo builder = jsonBuilder(); profile2.toXContent(builder, ToXContent.EMPTY_PARAMS); - json = Strings.toString(builder); + json = builder.toString(); assertTrue(false == JsonDeserializer.hasChildNode(json, ADCommonName.STATE)); } diff --git a/src/test/java/org/opensearch/ad/model/ModelProfileTests.java b/src/test/java/org/opensearch/ad/model/ModelProfileTests.java index d00f0f5c5..c99ff6222 100644 --- a/src/test/java/org/opensearch/ad/model/ModelProfileTests.java +++ b/src/test/java/org/opensearch/ad/model/ModelProfileTests.java @@ -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; @@ -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)); diff --git a/src/test/java/org/opensearch/ad/transport/ADStatsTests.java b/src/test/java/org/opensearch/ad/transport/ADStatsTests.java index c23f26575..e2edac7ea 100644 --- a/src/test/java/org/opensearch/ad/transport/ADStatsTests.java +++ b/src/test/java/org/opensearch/ad/transport/ADStatsTests.java @@ -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; @@ -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 stat : stats.entrySet()) { assertEquals("toXContent does not work", JsonDeserializer.getTextValue(json, stat.getKey()), stat.getValue()); @@ -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 stat : stats.entrySet()) { if (stat.getKey().equals(ModelState.LAST_CHECKPOINT_TIME_KEY) || stat.getKey().equals(ModelState.LAST_USED_TIME_KEY)) { @@ -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); @@ -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); } } diff --git a/src/test/java/org/opensearch/ad/transport/AnomalyResultTests.java b/src/test/java/org/opensearch/ad/transport/AnomalyResultTests.java index a92704b33..598c56dab 100644 --- a/src/test/java/org/opensearch/ad/transport/AnomalyResultTests.java +++ b/src/test/java/org/opensearch/ad/transport/AnomalyResultTests.java @@ -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; @@ -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 function = (s) -> { try { String featureId = JsonDeserializer.getTextValue(s, FeatureData.FEATURE_ID_FIELD); @@ -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()); diff --git a/src/test/java/org/opensearch/ad/transport/CronTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/CronTransportActionTests.java index 9adf7b387..06f375053 100644 --- a/src/test/java/org/opensearch/ad/transport/CronTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/CronTransportActionTests.java @@ -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; @@ -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 function = (s) -> { try { return JsonDeserializer.getTextValue(s, CronNodeResponse.NODE_ID); diff --git a/src/test/java/org/opensearch/ad/transport/DeleteModelTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/DeleteModelTransportActionTests.java index b0fc233f6..62429f962 100644 --- a/src/test/java/org/opensearch/ad/transport/DeleteModelTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/DeleteModelTransportActionTests.java @@ -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; @@ -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 function = (s) -> { try { return JsonDeserializer.getTextValue(s, CronNodeResponse.NODE_ID); diff --git a/src/test/java/org/opensearch/ad/transport/DeleteTests.java b/src/test/java/org/opensearch/ad/transport/DeleteTests.java index de531c9b0..35444445e 100644 --- a/src/test/java/org/opensearch/ad/transport/DeleteTests.java +++ b/src/test/java/org/opensearch/ad/transport/DeleteTests.java @@ -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; @@ -185,7 +184,7 @@ public void testJsonRequestTemplate(R request, Supplier profile : modelSizeMap1.entrySet()) { assertEquals( @@ -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); diff --git a/src/test/java/org/opensearch/ad/transport/RCFResultTests.java b/src/test/java/org/opensearch/ad/transport/RCFResultTests.java index 8f26af293..f61ecc0d7 100644 --- a/src/test/java/org/opensearch/ad/transport/RCFResultTests.java +++ b/src/test/java/org/opensearch/ad/transport/RCFResultTests.java @@ -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; @@ -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( @@ -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); } diff --git a/src/test/java/org/opensearch/ad/transport/StopDetectorActionTests.java b/src/test/java/org/opensearch/ad/transport/StopDetectorActionTests.java index 2f854f5fd..9a151c2e3 100644 --- a/src/test/java/org/opensearch/ad/transport/StopDetectorActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/StopDetectorActionTests.java @@ -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; @@ -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); } } diff --git a/src/test/java/org/opensearch/ad/transport/ThresholdResultTests.java b/src/test/java/org/opensearch/ad/transport/ThresholdResultTests.java index 9f2869c8c..e683c09b7 100644 --- a/src/test/java/org/opensearch/ad/transport/ThresholdResultTests.java +++ b/src/test/java/org/opensearch/ad/transport/ThresholdResultTests.java @@ -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; @@ -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); } @@ -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); }