From 56c63fa98d2c5b38d9da6b01395d69509446e272 Mon Sep 17 00:00:00 2001 From: zane-neo Date: Tue, 8 Aug 2023 10:29:38 +0800 Subject: [PATCH] Use builder.toString() to get a builder string value and format code Signed-off-by: zane-neo --- .../java/org/opensearch/ml/common/connector/Connector.java | 3 +-- .../java/org/opensearch/ml/common/utils/StringUtils.java | 6 ------ .../src/test/java/org/opensearch/ml/common/TestHelper.java | 3 +-- .../opensearch/ml/common/dataframe/BooleanValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/ColumnMetaTest.java | 3 +-- .../ml/common/dataframe/DefaultDataFrameTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/DoubleValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/FloatValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/IntValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/LongValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/NullValueTest.java | 3 +-- .../java/org/opensearch/ml/common/dataframe/RowTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/ShortValueTest.java | 3 +-- .../org/opensearch/ml/common/dataframe/StringValueTest.java | 3 +-- .../java/org/opensearch/ml/common/input/MLInputTest.java | 3 +-- .../anomalylocalization/AnomalyLocalizationInputTests.java | 5 ++--- .../opensearch/ml/common/input/nlp/TextDocsMLInputTest.java | 3 +-- .../opensearch/ml/common/output/MLPredictionOutputTest.java | 5 ++--- .../opensearch/ml/common/output/MLTrainingOutputTest.java | 3 +-- .../anomalylocalization/AnomalyLocalizationOutputTests.java | 3 +-- .../samplecalculator/LocalSampleCalculatorOutputTest.java | 5 ++--- .../ml/common/output/sample/SampleAlgoOutputTest.java | 5 ++--- .../transport/connector/MLConnectorGetResponseTests.java | 3 +-- .../transport/connector/MLCreateConnectorInputTests.java | 5 ++--- .../transport/deploy/MLDeployModelNodesResponseTest.java | 3 +-- .../common/transport/deploy/MLDeployModelResponseTest.java | 3 +-- .../common/transport/execute/MLExecuteTaskResponseTest.java | 3 +-- .../ml/common/transport/forward/MLForwardResponseTest.java | 3 +-- .../ml/common/transport/model/MLModelGetResponseTest.java | 3 +-- .../transport/prediction/MLPredictionTaskResponseTest.java | 3 +-- .../common/transport/register/MLRegisterModelInputTest.java | 5 ++--- .../transport/register/MLRegisterModelResponseTest.java | 3 +-- .../ml/common/transport/sync/MLSyncUpResponseTest.java | 3 +-- .../ml/common/transport/task/MLTaskGetResponseTest.java | 3 +-- .../common/transport/undeploy/MLUndeployModelInputTest.java | 3 +-- .../undeploy/MLUndeployModelNodesResponseTest.java | 3 +-- .../transport/upload_chunk/MLUploadModelChunkInputTest.java | 3 +-- .../ml/action/connector/TransportCreateConnectorAction.java | 2 +- .../org/opensearch/ml/action/handler/MLSearchHandler.java | 3 +-- .../action/model_group/TransportUpdateModelGroupAction.java | 2 +- .../org/opensearch/ml/helper/ModelAccessControlHelper.java | 2 +- .../java/org/opensearch/ml/model/MLModelGroupManager.java | 2 +- .../main/java/org/opensearch/ml/utils/MLExceptionUtils.java | 3 +-- .../deploy/TransportDeployModelOnNodeActionTests.java | 2 +- .../action/undeploy/TransportUndeployModelActionTests.java | 2 +- .../ml/autoredeploy/MLModelAutoReDeployerTests.java | 2 +- .../java/org/opensearch/ml/cluster/MLSyncUpCronTests.java | 2 +- .../org/opensearch/ml/rest/RestMLProfileActionTests.java | 2 +- .../java/org/opensearch/ml/rest/RestMLStatsActionTests.java | 2 +- .../test/java/org/opensearch/ml/utils/IntegTestUtils.java | 3 +-- .../src/test/java/org/opensearch/ml/utils/TestHelper.java | 2 +- 51 files changed, 56 insertions(+), 101 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/connector/Connector.java b/common/src/main/java/org/opensearch/ml/common/connector/Connector.java index 32d8ad78f4..19ed549db2 100644 --- a/common/src/main/java/org/opensearch/ml/common/connector/Connector.java +++ b/common/src/main/java/org/opensearch/ml/common/connector/Connector.java @@ -32,7 +32,6 @@ import org.opensearch.ml.common.AccessMode; import org.opensearch.ml.common.MLCommonsClassLoader; import org.opensearch.ml.common.output.model.ModelTensor; -import org.opensearch.ml.common.utils.StringUtils; /** * Connector defines how to connect to a remote service. @@ -93,7 +92,7 @@ static Connector fromStream(StreamInput in) throws IOException { } static Connector createConnector(XContentBuilder builder, String connectorProtocol) throws IOException { - String jsonStr = StringUtils.xContentBuilderToString(builder); + String jsonStr = builder.toString(); return createConnector(jsonStr, connectorProtocol); } diff --git a/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java b/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java index 34631b95b4..968cda1575 100644 --- a/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java +++ b/common/src/main/java/org/opensearch/ml/common/utils/StringUtils.java @@ -11,8 +11,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.opensearch.core.common.bytes.BytesReference; -import org.opensearch.core.xcontent.XContentBuilder; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -84,8 +82,4 @@ public static Map getParameterMap(Map parameterObjs) } return parameters; } - - public static String xContentBuilderToString(XContentBuilder builder) { - return BytesReference.bytes(builder).utf8ToString(); - } } diff --git a/common/src/test/java/org/opensearch/ml/common/TestHelper.java b/common/src/test/java/org/opensearch/ml/common/TestHelper.java index 0b72e790d6..81810aef92 100644 --- a/common/src/test/java/org/opensearch/ml/common/TestHelper.java +++ b/common/src/test/java/org/opensearch/ml/common/TestHelper.java @@ -14,7 +14,6 @@ import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.ml.common.utils.StringUtils; import java.io.IOException; import java.util.function.Function; @@ -34,7 +33,7 @@ public static void testParse(ToXContentObject obj, Function nodeErrors) throws IOExcep builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); - return StringUtils.xContentBuilderToString(builder); + return builder.toString(); } public static void logException(String errorMessage, Exception e, Logger log) { diff --git a/plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelOnNodeActionTests.java b/plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelOnNodeActionTests.java index d4038ad8be..2f283cf703 100644 --- a/plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelOnNodeActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/action/deploy/TransportDeployModelOnNodeActionTests.java @@ -47,8 +47,8 @@ import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.breaker.MLCircuitBreakerService; import org.opensearch.ml.common.FunctionName; diff --git a/plugin/src/test/java/org/opensearch/ml/action/undeploy/TransportUndeployModelActionTests.java b/plugin/src/test/java/org/opensearch/ml/action/undeploy/TransportUndeployModelActionTests.java index 125057fbf7..8de5cf5ec8 100644 --- a/plugin/src/test/java/org/opensearch/ml/action/undeploy/TransportUndeployModelActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/action/undeploy/TransportUndeployModelActionTests.java @@ -39,8 +39,8 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.cluster.DiscoveryNodeHelper; import org.opensearch.ml.common.MLModel; diff --git a/plugin/src/test/java/org/opensearch/ml/autoredeploy/MLModelAutoReDeployerTests.java b/plugin/src/test/java/org/opensearch/ml/autoredeploy/MLModelAutoReDeployerTests.java index 669fcc1a67..ee9d1df5db 100644 --- a/plugin/src/test/java/org/opensearch/ml/autoredeploy/MLModelAutoReDeployerTests.java +++ b/plugin/src/test/java/org/opensearch/ml/autoredeploy/MLModelAutoReDeployerTests.java @@ -38,9 +38,9 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.ml.common.MLModel; diff --git a/plugin/src/test/java/org/opensearch/ml/cluster/MLSyncUpCronTests.java b/plugin/src/test/java/org/opensearch/ml/cluster/MLSyncUpCronTests.java index 3f408f3a4d..00b917b94d 100644 --- a/plugin/src/test/java/org/opensearch/ml/cluster/MLSyncUpCronTests.java +++ b/plugin/src/test/java/org/opensearch/ml/cluster/MLSyncUpCronTests.java @@ -57,10 +57,10 @@ import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.commons.ConfigConstants; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.ml.common.MLModel; import org.opensearch.ml.common.model.MLModelState; diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMLProfileActionTests.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMLProfileActionTests.java index ef73fe7df9..2a6ce1f9f2 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMLProfileActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMLProfileActionTests.java @@ -40,10 +40,10 @@ import org.opensearch.cluster.node.DiscoveryNodeRole; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.commons.authuser.User; import org.opensearch.core.common.Strings; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.action.profile.MLProfileAction; import org.opensearch.ml.action.profile.MLProfileNodeResponse; diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMLStatsActionTests.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMLStatsActionTests.java index 50d3c5bbfb..099b09d60d 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMLStatsActionTests.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMLStatsActionTests.java @@ -45,9 +45,9 @@ import org.opensearch.cluster.node.DiscoveryNodeRole; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.action.stats.MLStatsNodeResponse; import org.opensearch.ml.action.stats.MLStatsNodesAction; diff --git a/plugin/src/test/java/org/opensearch/ml/utils/IntegTestUtils.java b/plugin/src/test/java/org/opensearch/ml/utils/IntegTestUtils.java index 76ef30380e..16036dd438 100644 --- a/plugin/src/test/java/org/opensearch/ml/utils/IntegTestUtils.java +++ b/plugin/src/test/java/org/opensearch/ml/utils/IntegTestUtils.java @@ -22,7 +22,6 @@ import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; import org.opensearch.action.support.WriteRequest; -import org.opensearch.ml.common.utils.StringUtils; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; @@ -194,7 +193,7 @@ public static void predictAndVerifyResult(String taskId, MLInputDataset inputDat MLPredictionOutput mlPredictionOutput = (MLPredictionOutput) predictionResponse.getOutput(); mlPredictionOutput.getPredictionResult().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); - String jsonStr = StringUtils.xContentBuilderToString(builder); + String jsonStr = builder.toString(); String expectedStr1 = "{\"column_metas\":[{\"name\":\"ClusterID\",\"column_type\":\"INTEGER\"}]," + "\"rows\":[{\"values\":[{\"column_type\":\"INTEGER\",\"value\":0}]}]}"; String expectedStr2 = "{\"column_metas\":[{\"name\":\"ClusterID\",\"column_type\":\"INTEGER\"}]," diff --git a/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java b/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java index 7f7ac4d7f7..23db025a04 100644 --- a/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java +++ b/plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java @@ -53,12 +53,12 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.common.bytes.BytesArray; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent;