From 2d44f03d630609f9112bf3bd72875bb58638b004 Mon Sep 17 00:00:00 2001 From: Heemin Kim Date: Thu, 17 Aug 2023 11:05:35 -0700 Subject: [PATCH] [Backport 2.x] Fix compile error due to changes in OpenSearch core (#387) * Switch from XContentType to MediaType to fix compilation errors (#366) Signed-off-by: Heemin Kim * Refactor XContentFactory to MediaTypeRegistry (#374) Signed-off-by: Heemin Kim * Refactor LifecycleComponent package path (#377) Signed-off-by: Heemin Kim * [Refactor] Strings utility methods to core library (#379) Signed-off-by: Heemin Kim * Fixed compilation errors after refactoring in core foundation classes (#380) Signed-off-by: Heemin Kim --------- Signed-off-by: Heemin Kim --- CHANGELOG.md | 3 +++ .../action/upload/geojson/IndexManager.java | 2 +- .../upload/geojson/PipelineManager.java | 2 +- .../upload/geojson/UploadGeoJSONResponse.java | 2 +- .../geojson/UploadGeoJSONTransportAction.java | 2 +- .../action/upload/geojson/Uploader.java | 2 +- .../DeleteDatasourceTransportAction.java | 2 +- .../ip2geo/action/GetDatasourceResponse.java | 2 +- .../action/GetDatasourceTransportAction.java | 2 +- .../action/PutDatasourceTransportAction.java | 2 +- .../action/RestGetDatasourceHandler.java | 2 +- .../UpdateDatasourceTransportAction.java | 2 +- .../ip2geo/common/Ip2GeoLockService.java | 2 +- .../ip2geo/common/ParameterValidator.java | 2 +- .../geospatial/ip2geo/dao/DatasourceDao.java | 2 +- .../ip2geo/listener/Ip2GeoListener.java | 4 +-- .../geospatial/plugin/GeospatialPlugin.java | 4 +-- .../geojson/RestUploadGeoJSONAction.java | 4 +-- .../geospatial/GeospatialRestTestCase.java | 12 ++++----- .../OpenSearchSecureRestTestCase.java | 6 ++--- .../upload/geojson/IndexManagerTests.java | 2 +- .../upload/geojson/PipelineManagerTests.java | 2 +- .../geojson/UploadGeoJSONResponseTests.java | 2 +- .../action/upload/geojson/UploaderTests.java | 2 +- .../xyshape/XYShapeQueryBuilderTests.java | 13 ++++----- .../geospatial/ip2geo/Ip2GeoTestCase.java | 4 +-- .../DeleteDatasourceTransportActionTests.java | 2 +- .../action/GetDatasourceResponseTests.java | 3 +-- .../GetDatasourceTransportActionTests.java | 2 +- .../PutDatasourceTransportActionTests.java | 2 +- .../UpdateDatasourceTransportActionTests.java | 2 +- .../common/InputFormatValidatorTests.java | 2 +- .../ip2geo/common/Ip2GeoLockServiceTests.java | 2 +- .../ip2geo/dao/DatasourceDaoTests.java | 2 +- .../ip2geo/dao/GeoIpDataDaoTests.java | 3 +-- .../ip2geo/listener/Ip2GeoListenerTests.java | 2 +- .../plugin/GeospatialPluginTests.java | 4 +-- .../stats/upload/TotalUploadStatsTests.java | 27 +++++++++---------- .../stats/upload/UploadMetricTests.java | 2 +- .../upload/UploadStatsResponseTests.java | 9 +++---- .../stats/upload/UploadStatsServiceTests.java | 13 +++++---- .../stats/upload/UploadStatsTests.java | 3 +-- 42 files changed, 80 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb45685..d403b166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Documentation ### Maintenance * Change package for Strings.hasText ([#314](https://github.com/opensearch-project/geospatial/pull/314)) +* Refactor LifecycleComponent package path ([#377](https://github.com/opensearch-project/geospatial/pull/377)) +* [Refactor] Strings utility methods to core library ([#379](https://github.com/opensearch-project/geospatial/pull/379)) +* Fixed compilation errors after refactoring in core foundation classes ([#380](https://github.com/opensearch-project/geospatial/pull/380)) ### Refactoring diff --git a/src/main/java/org/opensearch/geospatial/action/upload/geojson/IndexManager.java b/src/main/java/org/opensearch/geospatial/action/upload/geojson/IndexManager.java index 2ea24878..9fc02bac 100644 --- a/src/main/java/org/opensearch/geospatial/action/upload/geojson/IndexManager.java +++ b/src/main/java/org/opensearch/geospatial/action/upload/geojson/IndexManager.java @@ -13,11 +13,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.admin.indices.create.CreateIndexRequest; import org.opensearch.client.IndicesAdminClient; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.XContentBuilder; /** diff --git a/src/main/java/org/opensearch/geospatial/action/upload/geojson/PipelineManager.java b/src/main/java/org/opensearch/geospatial/action/upload/geojson/PipelineManager.java index 4a485983..dc98823c 100644 --- a/src/main/java/org/opensearch/geospatial/action/upload/geojson/PipelineManager.java +++ b/src/main/java/org/opensearch/geospatial/action/upload/geojson/PipelineManager.java @@ -12,7 +12,6 @@ import lombok.NonNull; import lombok.extern.log4j.Log4j2; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.ingest.DeletePipelineRequest; import org.opensearch.action.ingest.PutPipelineRequest; @@ -20,6 +19,7 @@ import org.opensearch.common.UUIDs; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.action.ActionListener; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.geospatial.processor.FeatureProcessor; diff --git a/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponse.java b/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponse.java index f1cd8616..1ddf0359 100644 --- a/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponse.java +++ b/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponse.java @@ -10,9 +10,9 @@ import java.util.List; import java.util.stream.Collectors; -import org.opensearch.action.ActionResponse; import org.opensearch.action.bulk.BulkItemResponse; import org.opensearch.action.bulk.BulkResponse; +import org.opensearch.core.action.ActionResponse; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.ToXContentObject; diff --git a/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONTransportAction.java b/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONTransportAction.java index 5d190870..4e0f0e1d 100644 --- a/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONTransportAction.java @@ -14,12 +14,12 @@ import java.util.Map; import org.opensearch.ResourceAlreadyExistsException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.GeospatialParser; import org.opensearch.geospatial.stats.upload.UploadStats; import org.opensearch.rest.RestRequest; diff --git a/src/main/java/org/opensearch/geospatial/action/upload/geojson/Uploader.java b/src/main/java/org/opensearch/geospatial/action/upload/geojson/Uploader.java index 1fcbfb41..f6cf02cf 100644 --- a/src/main/java/org/opensearch/geospatial/action/upload/geojson/Uploader.java +++ b/src/main/java/org/opensearch/geospatial/action/upload/geojson/Uploader.java @@ -11,12 +11,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.bulk.BulkItemResponse; import org.opensearch.action.bulk.BulkRequestBuilder; import org.opensearch.action.bulk.BulkResponse; import org.opensearch.common.collect.MapBuilder; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.stats.upload.UploadMetric; import org.opensearch.geospatial.stats.upload.UploadStats; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java index 8046f6ff..0522e228 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java @@ -10,11 +10,11 @@ import lombok.extern.log4j.Log4j2; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.inject.Inject; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.exceptions.ResourceInUseException; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponse.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponse.java index c6afac0b..03e6ec48 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponse.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponse.java @@ -13,8 +13,8 @@ import lombok.Getter; import lombok.Setter; -import org.opensearch.action.ActionResponse; import org.opensearch.core.ParseField; +import org.opensearch.core.action.ActionResponse; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.ToXContentObject; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportAction.java index d8e1aba7..522e1c39 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportAction.java @@ -9,10 +9,10 @@ import java.util.List; import org.opensearch.OpenSearchException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.common.inject.Inject; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java index ed4d1ee7..21440086 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java @@ -13,13 +13,13 @@ import lombok.extern.log4j.Log4j2; import org.opensearch.ResourceAlreadyExistsException; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.index.IndexResponse; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.inject.Inject; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.ip2geo.common.DatasourceState; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/RestGetDatasourceHandler.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/RestGetDatasourceHandler.java index 2c9379b5..0a51660d 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/RestGetDatasourceHandler.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/RestGetDatasourceHandler.java @@ -12,7 +12,7 @@ import java.util.List; import org.opensearch.client.node.NodeClient; -import org.opensearch.common.Strings; +import org.opensearch.core.common.Strings; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.RestRequest; import org.opensearch.rest.action.RestToXContentListener; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java index 31d77d08..e848a840 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java @@ -16,11 +16,11 @@ import lombok.extern.log4j.Log4j2; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.inject.Inject; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.exceptions.IncompatibleDatasourceException; import org.opensearch.geospatial.ip2geo.common.DatasourceManifest; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockService.java b/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockService.java index 7bd03316..f422caf8 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockService.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockService.java @@ -16,9 +16,9 @@ import lombok.extern.log4j.Log4j2; import org.opensearch.OpenSearchException; -import org.opensearch.action.ActionListener; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.core.action.ActionListener; import org.opensearch.jobscheduler.spi.LockModel; import org.opensearch.jobscheduler.spi.utils.LockService; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/common/ParameterValidator.java b/src/main/java/org/opensearch/geospatial/ip2geo/common/ParameterValidator.java index 56a2ea1d..deccbf21 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/common/ParameterValidator.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/common/ParameterValidator.java @@ -11,7 +11,7 @@ import java.util.Locale; import org.apache.commons.lang3.StringUtils; -import org.opensearch.common.Strings; +import org.opensearch.core.common.Strings; /** * Parameter validator for IP2Geo APIs diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java b/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java index 144add66..c0081c72 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java @@ -21,7 +21,6 @@ import org.opensearch.OpenSearchException; import org.opensearch.ResourceAlreadyExistsException; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.StepListener; import org.opensearch.action.admin.indices.create.CreateIndexRequest; @@ -44,6 +43,7 @@ import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.core.action.ActionListener; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.NamedXContentRegistry; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java b/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java index e6fe98f9..19e1968a 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java @@ -16,15 +16,15 @@ import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j2; -import org.opensearch.action.ActionListener; import org.opensearch.action.bulk.BulkResponse; import org.opensearch.cluster.ClusterChangedEvent; import org.opensearch.cluster.ClusterStateListener; import org.opensearch.cluster.RestoreInProgress; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.inject.Inject; +import org.opensearch.common.lifecycle.AbstractLifecycleComponent; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; diff --git a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java index de69daa6..e38e846d 100644 --- a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java +++ b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java @@ -16,18 +16,18 @@ import lombok.extern.log4j.Log4j2; import org.opensearch.action.ActionRequest; -import org.opensearch.action.ActionResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.collect.MapBuilder; -import org.opensearch.common.component.LifecycleComponent; +import org.opensearch.common.lifecycle.LifecycleComponent; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.SettingsFilter; +import org.opensearch.core.action.ActionResponse; import org.opensearch.core.common.io.stream.NamedWriteableRegistry; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.Environment; diff --git a/src/main/java/org/opensearch/geospatial/rest/action/upload/geojson/RestUploadGeoJSONAction.java b/src/main/java/org/opensearch/geospatial/rest/action/upload/geojson/RestUploadGeoJSONAction.java index 4e4034d0..51b3bbca 100644 --- a/src/main/java/org/opensearch/geospatial/rest/action/upload/geojson/RestUploadGeoJSONAction.java +++ b/src/main/java/org/opensearch/geospatial/rest/action/upload/geojson/RestUploadGeoJSONAction.java @@ -14,8 +14,8 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.geospatial.action.upload.geojson.UploadGeoJSONAction; import org.opensearch.geospatial.action.upload.geojson.UploadGeoJSONRequest; import org.opensearch.rest.BaseRestHandler; @@ -84,7 +84,7 @@ public List routes() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - Tuple sourceTuple = restRequest.contentOrSourceParam(); + Tuple sourceTuple = restRequest.contentOrSourceParam(); RestRequest.Method method = restRequest.getHttpRequest().method(); UploadGeoJSONRequest request = new UploadGeoJSONRequest(method, sourceTuple.v2()); return channel -> client.execute(UploadGeoJSONAction.INSTANCE, request, new RestToXContentListener<>(channel)); diff --git a/src/test/java/org/opensearch/geospatial/GeospatialRestTestCase.java b/src/test/java/org/opensearch/geospatial/GeospatialRestTestCase.java index 2be139a8..53ae7717 100644 --- a/src/test/java/org/opensearch/geospatial/GeospatialRestTestCase.java +++ b/src/test/java/org/opensearch/geospatial/GeospatialRestTestCase.java @@ -101,7 +101,7 @@ protected static Response createPipeline(String name, Optional descripti builder.endObject(); Request request = new Request("PUT", buildPipelinePath(name)); - request.setJsonEntity(org.opensearch.common.Strings.toString(builder)); + request.setJsonEntity(builder.toString()); return client().performRequest(request); } @@ -118,7 +118,7 @@ protected Response createDatasource(final String name, Map prope builder.endObject(); Request request = new Request(PUT, buildDatasourcePath(name)); - request.setJsonEntity(org.opensearch.common.Strings.toString(builder)); + request.setJsonEntity(builder.toString()); return client().performRequest(request); } @@ -178,7 +178,7 @@ protected Response updateDatasource(final String name, Map prope builder.endObject(); Request request = new Request(PUT, String.join(URL_DELIMITER, buildDatasourcePath(name), SETTINGS)); - request.setJsonEntity(org.opensearch.common.Strings.toString(builder)); + request.setJsonEntity(builder.toString()); return client().performRequest(request); } @@ -188,7 +188,7 @@ protected Map simulatePipeline(final String name, List d builder.endObject(); Request request = new Request(GET, String.join(URL_DELIMITER, buildPipelinePath(name), SIMULATE)); - request.setJsonEntity(org.opensearch.common.Strings.toString(builder)); + request.setJsonEntity(builder.toString()); Response response = client().performRequest(request); return createParser(XContentType.JSON.xContent(), EntityUtils.toString(response.getEntity())).map(); } @@ -199,7 +199,7 @@ protected static void createIndex(String name, Settings settings, Map XContentBuilder builder = JsonXContent.contentBuilder().startObject(); build.accept(builder); builder.endObject(); - return org.opensearch.common.Strings.toString(builder); + return builder.toString(); } public String buildSearchAggregationsBodyAsString(CheckedConsumer aggregationsBuilder) diff --git a/src/test/java/org/opensearch/geospatial/OpenSearchSecureRestTestCase.java b/src/test/java/org/opensearch/geospatial/OpenSearchSecureRestTestCase.java index 48c52ce0..cb26b7be 100644 --- a/src/test/java/org/opensearch/geospatial/OpenSearchSecureRestTestCase.java +++ b/src/test/java/org/opensearch/geospatial/OpenSearchSecureRestTestCase.java @@ -29,8 +29,8 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.ThreadContext; -import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.DeprecationHandler; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.test.rest.OpenSearchRestTestCase; @@ -129,9 +129,9 @@ protected boolean preserveIndicesUponCompletion() { @After public void deleteExternalIndices() throws IOException { Response response = client().performRequest(new Request("GET", "/_cat/indices?format=json&expand_wildcards=all")); - XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue()); + MediaType mediaType = MediaType.fromMediaType(response.getEntity().getContentType().getValue()); try ( - XContentParser parser = xContentType.xContent() + XContentParser parser = mediaType.xContent() .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, diff --git a/src/test/java/org/opensearch/geospatial/action/upload/geojson/IndexManagerTests.java b/src/test/java/org/opensearch/geospatial/action/upload/geojson/IndexManagerTests.java index 6fe205ad..be30eaca 100644 --- a/src/test/java/org/opensearch/geospatial/action/upload/geojson/IndexManagerTests.java +++ b/src/test/java/org/opensearch/geospatial/action/upload/geojson/IndexManagerTests.java @@ -16,11 +16,11 @@ import java.util.stream.IntStream; import org.opensearch.ResourceAlreadyExistsException; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.admin.indices.create.CreateIndexRequest; import org.opensearch.action.admin.indices.create.CreateIndexResponse; import org.opensearch.client.IndicesAdminClient; +import org.opensearch.core.action.ActionListener; import org.opensearch.test.OpenSearchTestCase; public class IndexManagerTests extends OpenSearchTestCase { diff --git a/src/test/java/org/opensearch/geospatial/action/upload/geojson/PipelineManagerTests.java b/src/test/java/org/opensearch/geospatial/action/upload/geojson/PipelineManagerTests.java index ff301fe8..de2677f3 100644 --- a/src/test/java/org/opensearch/geospatial/action/upload/geojson/PipelineManagerTests.java +++ b/src/test/java/org/opensearch/geospatial/action/upload/geojson/PipelineManagerTests.java @@ -11,12 +11,12 @@ import static org.mockito.Mockito.verify; import static org.opensearch.geospatial.GeospatialTestHelper.randomLowerCaseString; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.ingest.DeletePipelineRequest; import org.opensearch.action.ingest.PutPipelineRequest; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.client.ClusterAdminClient; +import org.opensearch.core.action.ActionListener; import org.opensearch.test.OpenSearchTestCase; public class PipelineManagerTests extends OpenSearchTestCase { diff --git a/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponseTests.java b/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponseTests.java index 30d63ce0..0f7feb4d 100644 --- a/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponseTests.java +++ b/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploadGeoJSONResponseTests.java @@ -6,8 +6,8 @@ package org.opensearch.geospatial.action.upload.geojson; import org.opensearch.action.bulk.BulkResponse; -import org.opensearch.common.Strings; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.common.Strings; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.test.OpenSearchTestCase; diff --git a/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploaderTests.java b/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploaderTests.java index 2e699947..e52834d8 100644 --- a/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploaderTests.java +++ b/src/test/java/org/opensearch/geospatial/action/upload/geojson/UploaderTests.java @@ -22,11 +22,11 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.bulk.BulkItemResponse; import org.opensearch.action.bulk.BulkRequestBuilder; import org.opensearch.action.bulk.BulkResponse; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.stats.upload.UploadMetric; import org.opensearch.geospatial.stats.upload.UploadStats; diff --git a/src/test/java/org/opensearch/geospatial/index/query/xyshape/XYShapeQueryBuilderTests.java b/src/test/java/org/opensearch/geospatial/index/query/xyshape/XYShapeQueryBuilderTests.java index 60103866..4da130fc 100644 --- a/src/test/java/org/opensearch/geospatial/index/query/xyshape/XYShapeQueryBuilderTests.java +++ b/src/test/java/org/opensearch/geospatial/index/query/xyshape/XYShapeQueryBuilderTests.java @@ -27,7 +27,6 @@ import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; import org.opensearch.action.get.GetRequest; import org.opensearch.action.get.GetResponse; -import org.opensearch.common.Strings; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.geo.GeoJson; import org.opensearch.common.geo.ShapeRelation; @@ -92,12 +91,10 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws mapperService.merge( DOC_TYPE, new CompressedXContent( - Strings.toString( - PutMappingRequest.simpleMapping( - XY_SHAPE_FIELD_NAME, - String.format(Locale.ROOT, "%s=%s", MAPPING_FIELD_TYPE_KEY, XYShapeQueryBuilder.NAME) - ) - ) + PutMappingRequest.simpleMapping( + XY_SHAPE_FIELD_NAME, + String.format(Locale.ROOT, "%s=%s", MAPPING_FIELD_TYPE_KEY, XYShapeQueryBuilder.NAME) + ).toString() ), MapperService.MergeReason.MAPPING_UPDATE ); @@ -120,7 +117,7 @@ protected GetResponse executeGet(GetRequest getRequest) { builder.field(expectedShapePath, (contentBuilder, params) -> GeoJson.toXContent(indexedShapeToReturn, contentBuilder, params)); builder.field(randomAlphaOfLengthBetween(10, 20), randomLowerCaseString()); builder.endObject(); - json = Strings.toString(builder); + json = builder.toString(); } catch (IOException ex) { throw new OpenSearchException(ex); } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java b/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java index 7bf2961f..b70b3f03 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java @@ -28,9 +28,7 @@ import org.junit.Before; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opensearch.action.ActionListener; import org.opensearch.action.ActionRequest; -import org.opensearch.action.ActionResponse; import org.opensearch.action.ActionType; import org.opensearch.action.support.ActionFilters; import org.opensearch.cluster.ClusterState; @@ -42,6 +40,8 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.OpenSearchExecutors; +import org.opensearch.core.action.ActionListener; +import org.opensearch.core.action.ActionResponse; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.common.DatasourceState; import org.opensearch.geospatial.ip2geo.common.Ip2GeoExecutor; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java index 3abf3c9d..3db3583a 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java @@ -27,8 +27,8 @@ import org.mockito.Mockito; import org.opensearch.OpenSearchException; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.master.AcknowledgedResponse; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; import org.opensearch.geospatial.ip2geo.common.DatasourceState; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponseTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponseTests.java index f1efad93..00b6f801 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponseTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceResponseTests.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Locale; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.common.io.stream.BytesStreamInput; @@ -35,7 +34,7 @@ public void testStreamInOut_whenValidInput_thenSucceed() throws Exception { public void testToXContent_whenValidInput_thenSucceed() throws Exception { List datasourceList = Arrays.asList(randomDatasource(), randomDatasource()); GetDatasourceResponse response = new GetDatasourceResponse(datasourceList); - String json = Strings.toString(response.toXContent(JsonXContent.contentBuilder(), null)); + String json = response.toXContent(JsonXContent.contentBuilder(), null).toString(); for (Datasource datasource : datasourceList) { assertTrue(json.contains(String.format(Locale.ROOT, "\"name\":\"%s\"", datasource.getName()))); assertTrue(json.contains(String.format(Locale.ROOT, "\"state\":\"%s\"", datasource.getState()))); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java index 581fd3b8..08eb6e22 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java @@ -16,7 +16,7 @@ import org.junit.Before; import org.opensearch.OpenSearchException; -import org.opensearch.action.ActionListener; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.index.IndexNotFoundException; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java index ef426cc5..63292dd8 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java @@ -20,10 +20,10 @@ import org.junit.Before; import org.mockito.ArgumentCaptor; import org.opensearch.ResourceAlreadyExistsException; -import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.unit.TimeValue; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java index aeb90c35..53ee2b1c 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java @@ -25,9 +25,9 @@ import org.mockito.ArgumentCaptor; import org.opensearch.OpenSearchException; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.common.unit.TimeValue; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.exceptions.IncompatibleDatasourceException; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; import org.opensearch.geospatial.ip2geo.common.DatasourceState; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/common/InputFormatValidatorTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/common/InputFormatValidatorTests.java index b9139a84..247585d2 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/common/InputFormatValidatorTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/common/InputFormatValidatorTests.java @@ -10,7 +10,7 @@ import java.util.Map; import org.opensearch.common.Randomness; -import org.opensearch.common.Strings; +import org.opensearch.core.common.Strings; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockServiceTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockServiceTests.java index 971bec0d..74206f68 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockServiceTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoLockServiceTests.java @@ -13,10 +13,10 @@ import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; -import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.update.UpdateRequest; import org.opensearch.action.update.UpdateResponse; +import org.opensearch.core.action.ActionListener; import org.opensearch.core.index.shard.ShardId; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java index 88329bb3..b2a59429 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java @@ -23,7 +23,6 @@ import org.mockito.ArgumentCaptor; import org.opensearch.ResourceAlreadyExistsException; import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.ActionListener; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.StepListener; import org.opensearch.action.admin.indices.create.CreateIndexRequest; @@ -42,6 +41,7 @@ import org.opensearch.cluster.routing.Preference; import org.opensearch.common.Randomness; import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.core.action.ActionListener; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.rest.RestStatus; import org.opensearch.geospatial.GeospatialTestHelper; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java index 0e7a1a26..3a985db1 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java @@ -42,7 +42,6 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.cluster.routing.Preference; -import org.opensearch.common.Strings; import org.opensearch.common.SuppressForbidden; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.geospatial.GeospatialTestHelper; @@ -101,7 +100,7 @@ public void testCreateDocument_whenBlankValue_thenDoNotAdd() { String[] values = { "1.0.0.0/25", "USA", " ", "Seattle" }; assertEquals( "{\"_cidr\":\"1.0.0.0/25\",\"_data\":{\"country\":\"USA\",\"city\":\"Seattle\"}}", - Strings.toString(noOpsGeoIpDataDao.createDocument(names, values)) + noOpsGeoIpDataDao.createDocument(names, values).toString() ); } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java index d31f38bc..ccf3fbfb 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java @@ -18,11 +18,11 @@ import org.junit.Before; import org.mockito.ArgumentCaptor; -import org.opensearch.action.ActionListener; import org.opensearch.cluster.ClusterChangedEvent; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.RestoreInProgress; import org.opensearch.common.settings.Settings; +import org.opensearch.core.action.ActionListener; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; diff --git a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java index bbe51267..09d5a4a8 100644 --- a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java +++ b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java @@ -21,13 +21,13 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.opensearch.action.ActionRequest; -import org.opensearch.action.ActionResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.component.LifecycleComponent; +import org.opensearch.common.lifecycle.LifecycleComponent; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; +import org.opensearch.core.action.ActionResponse; import org.opensearch.core.common.io.stream.NamedWriteableRegistry; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.Environment; diff --git a/src/test/java/org/opensearch/geospatial/stats/upload/TotalUploadStatsTests.java b/src/test/java/org/opensearch/geospatial/stats/upload/TotalUploadStatsTests.java index 021ff88b..2c26df9b 100644 --- a/src/test/java/org/opensearch/geospatial/stats/upload/TotalUploadStatsTests.java +++ b/src/test/java/org/opensearch/geospatial/stats/upload/TotalUploadStatsTests.java @@ -12,9 +12,8 @@ import java.util.Collections; import java.util.List; -import org.opensearch.common.Strings; -import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaTypeRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; @@ -43,11 +42,11 @@ public void testEmptyUploadStats() { public void testToXContentWithEmptyUploadStats() throws IOException { TotalUploadStats totalUploadStats = new TotalUploadStats(Collections.emptyList()); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); String expectedEmptyContent = "{\"total\":{}}"; assertEquals(expectedEmptyContent, summary); @@ -58,11 +57,11 @@ public void testToXContentWithRequestAPICount() throws IOException { long expectedSum = INIT; expectedSum += randomUploadStats.stream().mapToLong(UploadStats::getTotalAPICount).sum(); TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); assertTrue(summary.contains(buildFieldNameValuePair(TotalUploadStats.FIELDS.REQUEST_COUNT.toString(), expectedSum))); } @@ -74,11 +73,11 @@ public void testToXContentWithUploadCount() throws IOException { expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getUploadCount).sum(); } TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); assertTrue(summary.contains(buildFieldNameValuePair(TotalUploadStats.FIELDS.UPLOAD.toString(), expectedSum))); } @@ -90,11 +89,11 @@ public void testToXContentWithSuccessCount() throws IOException { expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getSuccessCount).sum(); } TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); assertTrue(summary.contains(buildFieldNameValuePair(TotalUploadStats.FIELDS.SUCCESS.toString(), expectedSum))); } @@ -106,11 +105,11 @@ public void testToXContentWithFailedCount() throws IOException { expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getFailedCount).sum(); } TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); assertTrue(summary.contains(buildFieldNameValuePair(TotalUploadStats.FIELDS.FAILED.toString(), expectedSum))); } @@ -122,11 +121,11 @@ public void testToXContentWithDuration() throws IOException { expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getDuration).sum(); } TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats); - XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON); + XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON); contentBuilder.startObject(); totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); - String summary = Strings.toString(contentBuilder); + String summary = contentBuilder.toString(); assertNotNull(summary); assertTrue(summary.contains(buildFieldNameValuePair(TotalUploadStats.FIELDS.DURATION.toString(), expectedSum))); } diff --git a/src/test/java/org/opensearch/geospatial/stats/upload/UploadMetricTests.java b/src/test/java/org/opensearch/geospatial/stats/upload/UploadMetricTests.java index c69ca8e3..f9b0df14 100644 --- a/src/test/java/org/opensearch/geospatial/stats/upload/UploadMetricTests.java +++ b/src/test/java/org/opensearch/geospatial/stats/upload/UploadMetricTests.java @@ -11,9 +11,9 @@ import java.io.IOException; -import org.opensearch.common.Strings; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.common.Strings; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.test.OpenSearchTestCase; diff --git a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsResponseTests.java b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsResponseTests.java index e6fec0aa..3b43f7f2 100644 --- a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsResponseTests.java +++ b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsResponseTests.java @@ -18,7 +18,6 @@ import java.util.stream.Collectors; import org.opensearch.cluster.ClusterName; -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; @@ -38,7 +37,7 @@ public void testXContentWithMetrics() throws IOException { ); final XContentBuilder serviceContentBuilder = jsonBuilder(); uploadStatsResponse.toXContent(serviceContentBuilder, ToXContent.EMPTY_PARAMS); - String nodesResponseAsString = Strings.toString(serviceContentBuilder); + String nodesResponseAsString = serviceContentBuilder.toString(); assertNotNull(nodesResponseAsString); final List uploadMetrics = getUploadMetrics(nodeResponse); @@ -46,7 +45,7 @@ public void testXContentWithMetrics() throws IOException { XContentBuilder metricContent = XContentFactory.jsonBuilder().startObject(); metric.toXContent(metricContent, ToXContent.EMPTY_PARAMS); metricContent.endObject(); - final String metricAsString = Strings.toString(metricContent); + final String metricAsString = metricContent.toString(); assertNotNull(metricAsString); assertTrue(nodesResponseAsString.contains(removeStartAndEndObject(metricAsString))); } @@ -62,14 +61,14 @@ public void testXContentWithTotalUploads() throws IOException { ); final XContentBuilder serviceContentBuilder = jsonBuilder(); uploadStatsResponse.toXContent(serviceContentBuilder, ToXContent.EMPTY_PARAMS); - String nodesResponseAsString = Strings.toString(serviceContentBuilder); + String nodesResponseAsString = serviceContentBuilder.toString(); assertNotNull(nodesResponseAsString); TotalUploadStats totalUploadStats = new TotalUploadStats(getUploadStats(nodeResponse)); XContentBuilder totalUploadStatsContent = XContentFactory.jsonBuilder().startObject(); totalUploadStats.toXContent(totalUploadStatsContent, ToXContent.EMPTY_PARAMS); totalUploadStatsContent.endObject(); - final String totalUploadStatsAsString = Strings.toString(totalUploadStatsContent); + final String totalUploadStatsAsString = totalUploadStatsContent.toString(); assertNotNull(totalUploadStatsAsString); assertTrue(nodesResponseAsString.contains(removeStartAndEndObject(totalUploadStatsAsString))); } diff --git a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsServiceTests.java b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsServiceTests.java index e0583a70..8098ea35 100644 --- a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsServiceTests.java +++ b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsServiceTests.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Map; -import org.opensearch.common.Strings; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.geospatial.GeospatialTestHelper; @@ -43,7 +42,7 @@ public void testXContentWithNodeID() throws IOException { UploadStatsService service = new UploadStatsService(randomMap); final XContentBuilder serviceContentBuilder = jsonBuilder(); service.toXContent(serviceContentBuilder, ToXContent.EMPTY_PARAMS); - String content = Strings.toString(serviceContentBuilder); + String content = serviceContentBuilder.toString(); assertNotNull(content); for (String nodeID : randomMap.keySet()) { assertTrue(nodeID + " is missing", content.contains(buildFieldNameValuePair(UploadStatsService.NODE_ID, nodeID))); @@ -55,7 +54,7 @@ public void testXContentWithEmptyStats() throws IOException { final XContentBuilder contentBuilder = jsonBuilder(); service.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); String emptyContent = "{\"total\":{},\"metrics\":[]}"; - assertEquals(emptyContent, Strings.toString(contentBuilder)); + assertEquals(emptyContent, contentBuilder.toString()); } public void testXContentWithTotalUploadStats() throws IOException { @@ -68,14 +67,14 @@ public void testXContentWithTotalUploadStats() throws IOException { UploadStatsService service = new UploadStatsService(randomMap); final XContentBuilder serviceContentBuilder = jsonBuilder(); service.toXContent(serviceContentBuilder, ToXContent.EMPTY_PARAMS); - String content = Strings.toString(serviceContentBuilder); + String content = serviceContentBuilder.toString(); assertNotNull(content); final XContentBuilder summary = jsonBuilder().startObject(); TotalUploadStats expectedSummary = new TotalUploadStats(uploadStats); expectedSummary.toXContent(summary, ToXContent.EMPTY_PARAMS); summary.endObject(); - final String totalUploadStatsSummary = Strings.toString(summary); + final String totalUploadStatsSummary = summary.toString(); assertNotNull(totalUploadStatsSummary); assertTrue(content.contains(removeStartAndEndObject(totalUploadStatsSummary))); } @@ -91,14 +90,14 @@ public void testXContentWithMetrics() throws IOException { UploadStatsService service = new UploadStatsService(randomMap); final XContentBuilder serviceContentBuilder = jsonBuilder(); service.toXContent(serviceContentBuilder, ToXContent.EMPTY_PARAMS); - String content = Strings.toString(serviceContentBuilder); + String content = serviceContentBuilder.toString(); assertNotNull(content); for (UploadMetric metric : randomMetrics) { XContentBuilder metricsAsContent = jsonBuilder().startObject(); metric.toXContent(metricsAsContent, ToXContent.EMPTY_PARAMS); metricsAsContent.endObject(); - final String metricsAsString = Strings.toString(metricsAsContent); + final String metricsAsString = metricsAsContent.toString(); assertNotNull(metricsAsString); assertTrue(content.contains(removeStartAndEndObject(metricsAsString))); } diff --git a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsTests.java b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsTests.java index 4177d5e4..4f982cbe 100644 --- a/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsTests.java +++ b/src/test/java/org/opensearch/geospatial/stats/upload/UploadStatsTests.java @@ -13,7 +13,6 @@ import java.util.Set; import java.util.stream.IntStream; -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; @@ -91,7 +90,7 @@ public void testStreams() throws IOException { public void testToXContent() throws IOException { UploadStats stats = UploadStatsBuilder.randomUploadStats(); XContentBuilder statsContent = XContentFactory.jsonBuilder().startObject(); - String statsAsString = Strings.toString(stats.toXContent(statsContent, ToXContent.EMPTY_PARAMS).endObject()); + String statsAsString = stats.toXContent(statsContent, ToXContent.EMPTY_PARAMS).endObject().toString(); assertNotNull(statsAsString); assertTrue(statsAsString.contains(buildFieldNameValuePair(UploadStats.FIELDS.REQUEST_COUNT.toString(), stats.getTotalAPICount()))); stats.getMetrics().forEach(uploadMetric -> {